Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC
Commits:
-
f191714a
by Vladislav Zavialov at 2026-09-29T10:42:22-04:00
-
5e12c24d
by Alan Zimmerman at 2026-09-29T10:42:23-04:00
28 changed files:
- compiler/GHC/Parser.y
- compiler/GHC/Parser/Annotation.hs
- compiler/GHC/Parser/PostProcess/Haddock.hs
- testsuite/tests/ghc-api/exactprint/T22919.stderr
- testsuite/tests/ghc-api/exactprint/Test20239.stderr
- testsuite/tests/ghc-api/exactprint/ZeroWidthSemi.stderr
- 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/T24221.stderr
- testsuite/tests/module/mod185.stderr
- testsuite/tests/parser/should_compile/DumpParsedAst.stderr
- testsuite/tests/parser/should_compile/DumpParsedAstComments.stderr
- testsuite/tests/parser/should_compile/DumpSemis.stderr
- testsuite/tests/parser/should_compile/KindSigs.stderr
- testsuite/tests/parser/should_compile/T15323.stderr
- testsuite/tests/parser/should_compile/T20452.stderr
- testsuite/tests/parser/should_compile/T20718.stderr
- testsuite/tests/parser/should_compile/T20718b.stderr
- testsuite/tests/parser/should_compile/T20846.stderr
- testsuite/tests/parser/should_compile/T23315/T23315.stderr
- testsuite/tests/printer/AnnotationNoListTuplePuns.stdout
- testsuite/tests/printer/T18791.stderr
- testsuite/tests/printer/Test20297.stdout
- testsuite/tests/printer/Test24533.stdout
- + testsuite/tests/simplCore/should_compile/T7803.hs
- + testsuite/tests/simplCore/should_compile/T7803.stderr
- + testsuite/tests/simplCore/should_compile/T7803a.hs
- testsuite/tests/simplCore/should_compile/all.T
Changes:
| ... | ... | @@ -945,13 +945,13 @@ body :: { ([TrailingAnn] |
| 945 | 945 | ,([LImportDecl GhcPs], [LHsDecl GhcPs])
|
| 946 | 946 | ,EpLayout) }
|
| 947 | 947 | : '{' top '}' { (fst $2, snd $2, epExplicitBraces $1 $3) }
|
| 948 | - | vocurly top close { (fst $2, snd $2, EpVirtualBraces (getVOCURLY $1)) }
|
|
| 948 | + | vocurly top close { (fst $2, snd $2, EpVirtualBraces (glR $1)) }
|
|
| 949 | 949 | |
| 950 | 950 | body2 :: { ([TrailingAnn]
|
| 951 | 951 | ,([LImportDecl GhcPs], [LHsDecl GhcPs])
|
| 952 | 952 | ,EpLayout) }
|
| 953 | 953 | : '{' top '}' { (fst $2, snd $2, epExplicitBraces $1 $3) }
|
| 954 | - | missing_module_keyword top close { ([], snd $2, EpVirtualBraces leftmostColumn) }
|
|
| 954 | + | missing_module_keyword top close { ([], snd $2, EpVirtualBraces (EpaDelta noSrcSpan (SameLine 0) [])) }
|
|
| 955 | 955 | |
| 956 | 956 | |
| 957 | 957 | top :: { ([TrailingAnn]
|
| ... | ... | @@ -1855,7 +1855,7 @@ decllist_cls |
| 1855 | 1855 | : '{' decls_cls '}' { sLL $1 $> ((epTok $1, fst $ unLoc $2, epTok $3)
|
| 1856 | 1856 | ,snd $ unLoc $2, epExplicitBraces $1 $3) }
|
| 1857 | 1857 | | vocurly decls_cls close { let { L l (anns, decls) = $2 }
|
| 1858 | - in L l ((noEpTok, anns, noEpTok), decls, EpVirtualBraces (getVOCURLY $1)) }
|
|
| 1858 | + in L l ((noEpTok, anns, noEpTok), decls, EpVirtualBraces (glR $1)) }
|
|
| 1859 | 1859 | |
| 1860 | 1860 | -- Class body
|
| 1861 | 1861 | --
|
| ... | ... | @@ -4305,7 +4305,6 @@ getINLINE (L _ (ITinline_prag _ inl conl)) = (inl,conl) |
| 4305 | 4305 | getSPEC_INLINE (L _ (ITspec_inline_prag src True)) = (Inline,FunLike)
|
| 4306 | 4306 | getSPEC_INLINE (L _ (ITspec_inline_prag src False)) = (NoInline,FunLike)
|
| 4307 | 4307 | getCOMPLETE_PRAGs (L _ (ITcomplete_prag x)) = x
|
| 4308 | -getVOCURLY (L (RealSrcSpan l _) ITvocurly) = srcSpanStartCol l
|
|
| 4309 | 4308 | |
| 4310 | 4309 | getINTEGERs (L _ (ITinteger (IL src _ _))) = src
|
| 4311 | 4310 | getCHARs (L _ (ITchar src _)) = src
|
| ... | ... | @@ -5,7 +5,7 @@ module GHC.Parser.Annotation ( |
| 5 | 5 | getEpTokenBufSpan,
|
| 6 | 6 | getEpTokenLoc, getEpUniTokenLoc,
|
| 7 | 7 | TokDcolon, TokDarrow, TokRarrow, TokForall, TokStar,
|
| 8 | - EpLayout(..),
|
|
| 8 | + EpLayout(..), getEpaLocationCol,
|
|
| 9 | 9 | EpaComment(..), EpaCommentTok(..),
|
| 10 | 10 | IsUnicodeSyntax(..),
|
| 11 | 11 | HasE(..),
|
| ... | ... | @@ -282,7 +282,9 @@ data EpLayout = |
| 282 | 282 | -- bar :: a
|
| 283 | 283 | -- @
|
| 284 | 284 | EpVirtualBraces
|
| 285 | - !Int -- ^ Layout column (indentation level, begins at 1)
|
|
| 285 | + !EpaLocation -- ^ Layout column (indentation level, begins at 1)
|
|
| 286 | + -- We keep this as an 'EpaLocation' so exact printing
|
|
| 287 | + -- can use it too.
|
|
| 286 | 288 | |
|
| 287 | 289 | -- | Empty or compiler-generated blocks do not have layout information
|
| 288 | 290 | -- associated with them.
|
| ... | ... | @@ -290,6 +292,14 @@ data EpLayout = |
| 290 | 292 | |
| 291 | 293 | deriving instance Data EpLayout
|
| 292 | 294 | |
| 295 | +-- | Used in 'GHC.Parser.Haddock' to get layout column. It assumes
|
|
| 296 | +-- | there is a RealSrcSpan in it, falling back to zero otherwise
|
|
| 297 | +getEpaLocationCol :: EpaLocation -> Int
|
|
| 298 | +getEpaLocationCol loc
|
|
| 299 | + = case loc of
|
|
| 300 | + EpaSpan (RealSrcSpan l _) -> srcSpanStartCol l
|
|
| 301 | + _ -> leftmostColumn -- should never happen in Parser output
|
|
| 302 | + |
|
| 293 | 303 | -- ---------------------------------------------------------------------
|
| 294 | 304 | |
| 295 | 305 | data EpaComment =
|
| ... | ... | @@ -392,8 +392,9 @@ addHaddockInterleaveItems layout get_doc_item = go |
| 392 | 392 | with_layout = case layout of
|
| 393 | 393 | EpNoLayout -> id
|
| 394 | 394 | EpExplicitBraces{} -> id
|
| 395 | - EpVirtualBraces n ->
|
|
| 396 | - let loc_range = mempty { loc_range_col = ColumnFrom (n+1) }
|
|
| 395 | + EpVirtualBraces n' ->
|
|
| 396 | + let n = getEpaLocationCol n'
|
|
| 397 | + loc_range = mempty { loc_range_col = ColumnFrom (n+1) }
|
|
| 397 | 398 | in hoistHdkA (inLocRange loc_range)
|
| 398 | 399 | |
| 399 | 400 | instance HasHaddock (LocatedA (HsDecl GhcPs)) where
|
| ... | ... | @@ -1304,7 +1305,7 @@ mkDocDecl layout (L l_comment hdk_comment) |
| 1304 | 1305 | indent_mismatch = case layout of
|
| 1305 | 1306 | EpNoLayout -> False
|
| 1306 | 1307 | EpExplicitBraces{} -> False
|
| 1307 | - EpVirtualBraces n -> n /= srcSpanStartCol (psRealSpan l_comment)
|
|
| 1308 | + EpVirtualBraces n -> getEpaLocationCol n /= srcSpanStartCol (psRealSpan l_comment)
|
|
| 1308 | 1309 | |
| 1309 | 1310 | mkDocIE :: PsLocated HdkComment -> Maybe (LIE GhcPs)
|
| 1310 | 1311 | mkDocIE (L l_comment hdk_comment) =
|
| ... | ... | @@ -34,7 +34,7 @@ |
| 34 | 34 | { T22919.hs:1:8-13 }))]
|
| 35 | 35 | []))
|
| 36 | 36 | (EpVirtualBraces
|
| 37 | - (1))
|
|
| 37 | + (EpaSpan { T22919.hs:2:1 }))
|
|
| 38 | 38 | (Nothing)
|
| 39 | 39 | (Nothing))
|
| 40 | 40 | (Just
|
| ... | ... | @@ -34,7 +34,7 @@ |
| 34 | 34 | "-- ^ Run any arbitrary IO code")
|
| 35 | 35 | { Test20239.hs:7:86 }))]))
|
| 36 | 36 | (EpVirtualBraces
|
| 37 | - (1))
|
|
| 37 | + (EpaSpan { Test20239.hs:5:1 }))
|
|
| 38 | 38 | (Nothing)
|
| 39 | 39 | (Nothing))
|
| 40 | 40 | (Just
|
| ... | ... | @@ -40,7 +40,7 @@ |
| 40 | 40 | "-- Trailing comment, should be in HsModule extension point")
|
| 41 | 41 | { ZeroWidthSemi.hs:6:5 }))]))
|
| 42 | 42 | (EpVirtualBraces
|
| 43 | - (1))
|
|
| 43 | + (EpaSpan { ZeroWidthSemi.hs:6:1 }))
|
|
| 44 | 44 | (Nothing)
|
| 45 | 45 | (Nothing))
|
| 46 | 46 | (Just
|
| ... | ... | @@ -28,7 +28,7 @@ |
| 28 | 28 | []
|
| 29 | 29 | []))
|
| 30 | 30 | (EpVirtualBraces
|
| 31 | - (1))
|
|
| 31 | + (EpaSpan { T17544.hs:5:1 }))
|
|
| 32 | 32 | (Nothing)
|
| 33 | 33 | (Nothing))
|
| 34 | 34 | (Just
|
| ... | ... | @@ -64,7 +64,7 @@ |
| 64 | 64 | (EpTok (EpaSpan { <no location info> }))
|
| 65 | 65 | [])
|
| 66 | 66 | (EpVirtualBraces
|
| 67 | - (3)))
|
|
| 67 | + (EpaSpan { T17544.hs:6:3 })))
|
|
| 68 | 68 | []
|
| 69 | 69 | (Nothing)
|
| 70 | 70 | (L
|
| ... | ... | @@ -243,7 +243,7 @@ |
| 243 | 243 | (EpTok (EpaSpan { <no location info> }))
|
| 244 | 244 | [])
|
| 245 | 245 | (EpVirtualBraces
|
| 246 | - (3)))
|
|
| 246 | + (EpaSpan { T17544.hs:10:3 })))
|
|
| 247 | 247 | []
|
| 248 | 248 | (Nothing)
|
| 249 | 249 | (L
|
| ... | ... | @@ -423,7 +423,7 @@ |
| 423 | 423 | (EpTok (EpaSpan { <no location info> }))
|
| 424 | 424 | [])
|
| 425 | 425 | (EpVirtualBraces
|
| 426 | - (3)))
|
|
| 426 | + (EpaSpan { T17544.hs:14:3 })))
|
|
| 427 | 427 | []
|
| 428 | 428 | (Nothing)
|
| 429 | 429 | (L
|
| ... | ... | @@ -603,7 +603,7 @@ |
| 603 | 603 | (EpTok (EpaSpan { <no location info> }))
|
| 604 | 604 | [])
|
| 605 | 605 | (EpVirtualBraces
|
| 606 | - (3)))
|
|
| 606 | + (EpaSpan { T17544.hs:18:3 })))
|
|
| 607 | 607 | []
|
| 608 | 608 | (Nothing)
|
| 609 | 609 | (L
|
| ... | ... | @@ -28,7 +28,7 @@ |
| 28 | 28 | []
|
| 29 | 29 | []))
|
| 30 | 30 | (EpVirtualBraces
|
| 31 | - (1))
|
|
| 31 | + (EpaSpan { T17544_kw.hs:13:1 }))
|
|
| 32 | 32 | (Nothing)
|
| 33 | 33 | (Nothing))
|
| 34 | 34 | (Just
|
| ... | ... | @@ -412,7 +412,7 @@ |
| 412 | 412 | (EpTok (EpaSpan { <no location info> }))
|
| 413 | 413 | [])
|
| 414 | 414 | (EpVirtualBraces
|
| 415 | - (5)))
|
|
| 415 | + (EpaSpan { T17544_kw.hs:22:5 })))
|
|
| 416 | 416 | []
|
| 417 | 417 | (Nothing)
|
| 418 | 418 | (L
|
| ... | ... | @@ -28,7 +28,7 @@ |
| 28 | 28 | []
|
| 29 | 29 | []))
|
| 30 | 30 | (EpVirtualBraces
|
| 31 | - (1))
|
|
| 31 | + (EpaSpan { T24221.hs:3:1 }))
|
|
| 32 | 32 | (Nothing)
|
| 33 | 33 | (Nothing))
|
| 34 | 34 | (Just
|
| ... | ... | @@ -28,7 +28,7 @@ |
| 28 | 28 | []
|
| 29 | 29 | []))
|
| 30 | 30 | (EpVirtualBraces
|
| 31 | - (1))
|
|
| 31 | + (EpaDelta { <no location info> } (SameLine 0) []))
|
|
| 32 | 32 | (Nothing)
|
| 33 | 33 | (Nothing))
|
| 34 | 34 | (Nothing)
|
| ... | ... | @@ -28,7 +28,7 @@ |
| 28 | 28 | []
|
| 29 | 29 | []))
|
| 30 | 30 | (EpVirtualBraces
|
| 31 | - (1))
|
|
| 31 | + (EpaSpan { DumpParsedAst.hs:5:1 }))
|
|
| 32 | 32 | (Nothing)
|
| 33 | 33 | (Nothing))
|
| 34 | 34 | (Just
|
| ... | ... | @@ -41,7 +41,7 @@ |
| 41 | 41 | { DumpParsedAstComments.hs:1:1-28 }))]
|
| 42 | 42 | []))
|
| 43 | 43 | (EpVirtualBraces
|
| 44 | - (1))
|
|
| 44 | + (EpaSpan { DumpParsedAstComments.hs:9:1 }))
|
|
| 45 | 45 | (Nothing)
|
| 46 | 46 | (Nothing))
|
| 47 | 47 | (Just
|
| ... | ... | @@ -45,7 +45,7 @@ |
| 45 | 45 | []
|
| 46 | 46 | []))
|
| 47 | 47 | (EpVirtualBraces
|
| 48 | - (1))
|
|
| 48 | + (EpaSpan { DumpSemis.hs:4:1 }))
|
|
| 49 | 49 | (Nothing)
|
| 50 | 50 | (Nothing))
|
| 51 | 51 | (Just
|
| ... | ... | @@ -1336,7 +1336,7 @@ |
| 1336 | 1336 | (EpTok (EpaSpan { <no location info> }))
|
| 1337 | 1337 | [])
|
| 1338 | 1338 | (EpVirtualBraces
|
| 1339 | - (3)))
|
|
| 1339 | + (EpaSpan { DumpSemis.hs:29:3 })))
|
|
| 1340 | 1340 | []
|
| 1341 | 1341 | (Nothing)
|
| 1342 | 1342 | (L
|
| ... | ... | @@ -28,7 +28,7 @@ |
| 28 | 28 | []
|
| 29 | 29 | []))
|
| 30 | 30 | (EpVirtualBraces
|
| 31 | - (1))
|
|
| 31 | + (EpaSpan { KindSigs.hs:8:1 }))
|
|
| 32 | 32 | (Nothing)
|
| 33 | 33 | (Nothing))
|
| 34 | 34 | (Just
|
| ... | ... | @@ -28,7 +28,7 @@ |
| 28 | 28 | []
|
| 29 | 29 | []))
|
| 30 | 30 | (EpVirtualBraces
|
| 31 | - (1))
|
|
| 31 | + (EpaSpan { T15323.hs:5:1 }))
|
|
| 32 | 32 | (Nothing)
|
| 33 | 33 | (Nothing))
|
| 34 | 34 | (Just
|
| ... | ... | @@ -28,7 +28,7 @@ |
| 28 | 28 | []
|
| 29 | 29 | []))
|
| 30 | 30 | (EpVirtualBraces
|
| 31 | - (1))
|
|
| 31 | + (EpaSpan { T20452.hs:5:1 }))
|
|
| 32 | 32 | (Nothing)
|
| 33 | 33 | (Nothing))
|
| 34 | 34 | (Just
|
| ... | ... | @@ -68,7 +68,7 @@ |
| 68 | 68 | "-- end 2")
|
| 69 | 69 | { T20718.hs:10:1-8 }))]))
|
| 70 | 70 | (EpVirtualBraces
|
| 71 | - (1))
|
|
| 71 | + (EpaSpan { T20718.hs:8:1 }))
|
|
| 72 | 72 | (Nothing)
|
| 73 | 73 | (Nothing))
|
| 74 | 74 | (Just
|
| ... | ... | @@ -55,7 +55,7 @@ |
| 55 | 55 | { T20718b.hs:6:1-21 }))]
|
| 56 | 56 | []))
|
| 57 | 57 | (EpVirtualBraces
|
| 58 | - (1))
|
|
| 58 | + (EpaSpan { T20718b.hs:8:1 }))
|
|
| 59 | 59 | (Nothing)
|
| 60 | 60 | (Nothing))
|
| 61 | 61 | (Just
|
| ... | ... | @@ -28,7 +28,7 @@ |
| 28 | 28 | []
|
| 29 | 29 | []))
|
| 30 | 30 | (EpVirtualBraces
|
| 31 | - (1))
|
|
| 31 | + (EpaSpan { T20846.hs:3:1 }))
|
|
| 32 | 32 | (Nothing)
|
| 33 | 33 | (Nothing))
|
| 34 | 34 | (Just
|
| ... | ... | @@ -24,7 +24,7 @@ |
| 24 | 24 | (EpaComments
|
| 25 | 25 | []))
|
| 26 | 26 | (EpVirtualBraces
|
| 27 | - (1))
|
|
| 27 | + (EpaSpan { T23315.hsig:3:1 }))
|
|
| 28 | 28 | (Nothing)
|
| 29 | 29 | (Nothing))
|
| 30 | 30 | (Just
|
| ... | ... | @@ -47,7 +47,7 @@ |
| 47 | 47 | "-- comment post B")
|
| 48 | 48 | { AnnotationNoListTuplePuns.hs:17:3 }))]))
|
| 49 | 49 | (EpVirtualBraces
|
| 50 | - (1))
|
|
| 50 | + (EpaSpan { AnnotationNoListTuplePuns.hs:5:1 }))
|
|
| 51 | 51 | (Nothing)
|
| 52 | 52 | (Nothing))
|
| 53 | 53 | (Just
|
| ... | ... | @@ -244,7 +244,7 @@ |
| 244 | 244 | { AnnotationNoListTuplePuns.ppr.hs:1:1-32 }))]
|
| 245 | 245 | []))
|
| 246 | 246 | (EpVirtualBraces
|
| 247 | - (1))
|
|
| 247 | + (EpaSpan { AnnotationNoListTuplePuns.ppr.hs:4:1 }))
|
|
| 248 | 248 | (Nothing)
|
| 249 | 249 | (Nothing))
|
| 250 | 250 | (Just
|
| ... | ... | @@ -28,7 +28,7 @@ |
| 28 | 28 | []
|
| 29 | 29 | []))
|
| 30 | 30 | (EpVirtualBraces
|
| 31 | - (1))
|
|
| 31 | + (EpaSpan { T18791.hs:4:1 }))
|
|
| 32 | 32 | (Nothing)
|
| 33 | 33 | (Nothing))
|
| 34 | 34 | (Just
|
| ... | ... | @@ -34,7 +34,7 @@ |
| 34 | 34 | { Test20297.hs:1:1 }))]
|
| 35 | 35 | []))
|
| 36 | 36 | (EpVirtualBraces
|
| 37 | - (1))
|
|
| 37 | + (EpaSpan { Test20297.hs:5:1 }))
|
|
| 38 | 38 | (Nothing)
|
| 39 | 39 | (Nothing))
|
| 40 | 40 | (Just
|
| ... | ... | @@ -476,7 +476,7 @@ |
| 476 | 476 | { Test20297.ppr.hs:1:1 }))]
|
| 477 | 477 | []))
|
| 478 | 478 | (EpVirtualBraces
|
| 479 | - (1))
|
|
| 479 | + (EpaSpan { Test20297.ppr.hs:3:1 }))
|
|
| 480 | 480 | (Nothing)
|
| 481 | 481 | (Nothing))
|
| 482 | 482 | (Just
|
| ... | ... | @@ -34,7 +34,7 @@ |
| 34 | 34 | { Test24533.hs:1:1 }))]
|
| 35 | 35 | []))
|
| 36 | 36 | (EpVirtualBraces
|
| 37 | - (1))
|
|
| 37 | + (EpaSpan { Test24533.hs:4:1 }))
|
|
| 38 | 38 | (Nothing)
|
| 39 | 39 | (Nothing))
|
| 40 | 40 | (Just
|
| ... | ... | @@ -694,7 +694,7 @@ |
| 694 | 694 | { Test24533.ppr.hs:1:1 }))]
|
| 695 | 695 | []))
|
| 696 | 696 | (EpVirtualBraces
|
| 697 | - (1))
|
|
| 697 | + (EpaSpan { Test24533.ppr.hs:3:1 }))
|
|
| 698 | 698 | (Nothing)
|
| 699 | 699 | (Nothing))
|
| 700 | 700 | (Just
|
| 1 | +{-# OPTIONS_GHC -ddump-simpl #-}
|
|
| 2 | + |
|
| 3 | +-- #7803: foo1 should be fully specialised at Double. In the bug report
|
|
| 4 | +-- it ended up calling the overloaded exp5Tail (with a dictionary argument),
|
|
| 5 | +-- because the specialiser ran before the overloaded call was floated to
|
|
| 6 | +-- the top level. So the dumped Core for this module must mention no
|
|
| 7 | +-- exp5Tail at all.
|
|
| 8 | +module T7803 (foo1) where
|
|
| 9 | + |
|
| 10 | +import T7803a
|
|
| 11 | + |
|
| 12 | +bar :: Floating a => a -> a -> a
|
|
| 13 | +bar z = subtract (evaluate integ z) . evaluate integ
|
|
| 14 | + where
|
|
| 15 | + integ = indefinite (Piecewise [Poly4 1])
|
|
| 16 | +{-# SPECIALIZE bar :: Double -> Double -> Double #-}
|
|
| 17 | + |
|
| 18 | +foo :: Floating a => a -> a -> a
|
|
| 19 | +foo x = bar x
|
|
| 20 | +{-# SPECIALIZE foo :: Double -> Double -> Double #-}
|
|
| 21 | + |
|
| 22 | +foo1 :: Double -> Double -> Double
|
|
| 23 | +foo1 x = foo x |
| 1 | +foo1 |
| 1 | +{-# LANGUAGE ConstraintKinds #-}
|
|
| 2 | +{-# LANGUAGE FlexibleContexts #-}
|
|
| 3 | +{-# LANGUAGE FlexibleInstances #-}
|
|
| 4 | +{-# LANGUAGE MultiParamTypeClasses #-}
|
|
| 5 | +{-# LANGUAGE TypeFamilies #-}
|
|
| 6 | +{-# LANGUAGE UndecidableInstances #-}
|
|
| 7 | +{-# LANGUAGE UndecidableSuperClasses #-}
|
|
| 8 | + |
|
| 9 | +module T7803a
|
|
| 10 | + ( Evaluate (..)
|
|
| 11 | + , HasIntegral (..)
|
|
| 12 | + , Poly4 (..)
|
|
| 13 | + , Domain
|
|
| 14 | + , IntOfLogPoly4 (..)
|
|
| 15 | + , Piecewise (..)
|
|
| 16 | + ) where
|
|
| 17 | + |
|
| 18 | +import Data.Kind (Constraint, Type)
|
|
| 19 | + |
|
| 20 | +class Evaluate poly where
|
|
| 21 | + evaluate :: (Domain' poly a) => poly a -> a -> a
|
|
| 22 | + |
|
| 23 | +class Evaluate (IntegralOf poly) => HasIntegral poly where
|
|
| 24 | + type IntegralOf poly :: Type -> Type
|
|
| 25 | + indefinite :: (Domain' poly a, Domain' (IntegralOf poly) a)
|
|
| 26 | + => poly a -> IntegralOf poly a
|
|
| 27 | + |
|
| 28 | +type family Domain (f :: Type -> Type) a :: Constraint
|
|
| 29 | + |
|
| 30 | +class Domain f a => Domain' f a
|
|
| 31 | +instance Domain f a => Domain' f a
|
|
| 32 | + |
|
| 33 | +newtype Poly4 a = Poly4 { poly4_a :: a }
|
|
| 34 | + |
|
| 35 | +type instance Domain Poly4 a = Fractional a
|
|
| 36 | + |
|
| 37 | +data IntOfLogPoly4 a = IntOfLogPoly4 { ilp4_k :: !a, ilp4_u :: !a }
|
|
| 38 | + |
|
| 39 | +type instance Domain IntOfLogPoly4 a = Floating a
|
|
| 40 | + |
|
| 41 | +instance Evaluate IntOfLogPoly4 where
|
|
| 42 | + evaluate (IntOfLogPoly4 k _) x = k + x * exp5Tail (- log x)
|
|
| 43 | + {-# INLINE evaluate #-}
|
|
| 44 | + |
|
| 45 | +{-# RULES "exp5Tail/Double" exp5Tail = exp5TailDouble #-}
|
|
| 46 | +{-# NOINLINE exp5Tail #-}
|
|
| 47 | + |
|
| 48 | +exp5Tail :: (Floating a) => a -> a
|
|
| 49 | +exp5Tail x = x / 120
|
|
| 50 | + |
|
| 51 | +exp5TailDouble :: Double -> Double
|
|
| 52 | +exp5TailDouble x = x / 120
|
|
| 53 | + |
|
| 54 | +instance HasIntegral Poly4 where
|
|
| 55 | + type IntegralOf Poly4 = IntOfLogPoly4
|
|
| 56 | + indefinite = \ (Poly4 a) -> IntOfLogPoly4 0 a
|
|
| 57 | + {-# INLINE indefinite #-}
|
|
| 58 | + |
|
| 59 | +newtype Piecewise poly a = Piecewise { unPiecewise :: [poly a] }
|
|
| 60 | + |
|
| 61 | +type instance Domain (Piecewise poly) a = (Domain poly a, Num a)
|
|
| 62 | + |
|
| 63 | +instance (Evaluate poly) => Evaluate (Piecewise poly) where
|
|
| 64 | + evaluate = \ (Piecewise pp) x ->
|
|
| 65 | + case pp of
|
|
| 66 | + p : _ -> evaluate p x
|
|
| 67 | + [] -> error "evaluate: empty Piecewise"
|
|
| 68 | + {-# INLINE evaluate #-}
|
|
| 69 | + |
|
| 70 | +instance (HasIntegral poly) => HasIntegral (Piecewise poly) where
|
|
| 71 | + type IntegralOf (Piecewise poly) = Piecewise (IntegralOf poly)
|
|
| 72 | + indefinite (Piecewise m) = Piecewise $ map indefinite m
|
|
| 73 | + {-# INLINE indefinite #-} |
| ... | ... | @@ -148,6 +148,13 @@ test('T7785', [ only_ways(['optasm']), |
| 148 | 148 | grep_errmsg(r'SPEC') ],
|
| 149 | 149 | compile, ['-ddump-cse'])
|
| 150 | 150 | |
| 151 | +# T7803: we expect NO calls to the overloaded 'exp5Tail' in T7803.hs
|
|
| 152 | +# In the bug report #7803, the unspecialised call was signalled by 'exp5Tail'
|
|
| 153 | +# in foo1's Core, so we grep for that; also for 'foo1', lest we dump nothing
|
|
| 154 | +# One module, T7803.hs, has OPTIONS_GHC -ddump-simpl
|
|
| 155 | +test('T7803', [ grep_errmsg(r'exp5Tail|foo1') ],
|
|
| 156 | + multimod_compile, ['T7803', '-O2 -v0 -dsuppress-all -dsuppress-uniques -dno-typeable-binds'])
|
|
| 157 | + |
|
| 151 | 158 | test('T7702',
|
| 152 | 159 | [extra_files(['T7702plugin']),
|
| 153 | 160 | pre_cmd('$MAKE -s --no-print-directory -C T7702plugin package.T7702 TOP={top}'),
|