Skip to content

Commit a0fa0b2

Browse files
committed
Merge branch 'master' into featureset
2 parents e5c29e8 + 03e833b commit a0fa0b2

File tree

20 files changed

+639
-332
lines changed

20 files changed

+639
-332
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ test/testdata/**/hie.yaml
3030

3131
# shake build folder (used in benchmark suite)
3232
.shake/
33+
34+
# pre-commit-hook.nix
35+
.pre-commit-config.yaml

.stylish-haskell.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# See https://github.com/jaspervdj/stylish-haskell/blob/main/data/stylish-haskell.yaml
2+
# for reference.
3+
4+
steps:
5+
# - unicode_syntax:
6+
# add_language_pragma: true
7+
8+
# - module_header:
9+
# indent: 4
10+
# sort: true
11+
# separate_lists: true
12+
13+
# - records:
14+
# equals: "indent 2"
15+
# first_field: "indent 2"
16+
# field_comment: 2
17+
# deriving: 2
18+
# via: "indent 2"
19+
# sort_deriving: true
20+
# break_enums: false
21+
# break_single_constructors: true
22+
# curried_context: false
23+
24+
- simple_align:
25+
cases: always
26+
top_level_patterns: always
27+
records: always
28+
multi_way_if: always
29+
30+
- imports:
31+
align: global
32+
list_align: after_alias
33+
pad_module_names: true
34+
long_list_align: inline
35+
empty_list_align: inherit
36+
list_padding: 4
37+
separate_lists: true
38+
space_surround: false
39+
ghc_lib_parser: false
40+
41+
- language_pragmas:
42+
style: vertical
43+
align: true
44+
remove_redundant: true
45+
language_prefix: LANGUAGE
46+
47+
# - tabs:
48+
# spaces: 8
49+
50+
- trailing_whitespace: {}
51+
52+
# - squash: {}
53+
54+
columns: 80
55+
56+
newline: native
57+
58+
language_extensions:
59+
- DataKinds
60+
- OverloadedStrings
61+
- TypeOperators
62+
63+
cabal: true

CONTRIBUTING.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
11
# Contributors Guide
22

3+
## Pre-commit hook
4+
We are using [pre-commit-hook.nix](https://github.com/cachix/pre-commit-hooks.nix) to configure git pre-commit hook for formatting. Although it is possible to run formatting manually, we recommend you to use it to set pre-commit hook as our CI checks pre-commit hook is applied or not.
5+
6+
You can configure the pre-commit-hook by running
7+
8+
``` bash
9+
nix-shell
10+
```
11+
12+
If you don't want to use [nix](https://nixos.org/guides/install-nix.html), you can instead use [pre-commit](https://pre-commit.com) with the following config.
13+
14+
```json
15+
{
16+
"repos": [
17+
{
18+
"hooks": [
19+
{
20+
"entry": "stylish-haskell -i ",
21+
"exclude": "(/test/testdata/*)",
22+
"files": "\\.l?hs$",
23+
"id": "stylish-haskell",
24+
"language": "system",
25+
"name": "stylish-haskell",
26+
"pass_filenames": true,
27+
"types": [
28+
"file"
29+
]
30+
}
31+
],
32+
"repo": "local"
33+
}
34+
]
35+
}
36+
```
37+
338
## Testing
439

540
The tests make use of the [Tasty](https://github.com/feuerbach/tasty) test framework.

ChangeLog.md

Lines changed: 286 additions & 286 deletions
Large diffs are not rendered by default.

GenChangelogs.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ main = do
3232

3333
forM_ prsAfterLastTag $ \SimplePullRequest{..} ->
3434
putStrLn $ T.unpack $ "- " <> simplePullRequestTitle <>
35-
"\n([#" <> T.pack (show $ unIssueNumber simplePullRequestNumber) <> ")](" <> getUrl simplePullRequestHtmlUrl <> ")" <>
35+
"\n([#" <> T.pack (show $ unIssueNumber simplePullRequestNumber) <> "](" <> getUrl simplePullRequestHtmlUrl <> "))" <>
3636
" by @" <> untagName (simpleUserLogin simplePullRequestUser)

ghcide/.stylish-haskell.yaml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# See https://github.com/jaspervdj/stylish-haskell/blob/main/data/stylish-haskell.yaml
2+
# for reference.
3+
4+
steps:
5+
# - unicode_syntax:
6+
# add_language_pragma: true
7+
8+
# - module_header:
9+
# indent: 4
10+
# sort: true
11+
# separate_lists: true
12+
13+
# - records:
14+
# equals: "indent 2"
15+
# first_field: "indent 2"
16+
# field_comment: 2
17+
# deriving: 2
18+
# via: "indent 2"
19+
# sort_deriving: true
20+
# break_enums: false
21+
# break_single_constructors: true
22+
# curried_context: false
23+
24+
- simple_align:
25+
cases: always
26+
top_level_patterns: always
27+
records: always
28+
multi_way_if: always
29+
30+
- imports:
31+
align: global
32+
list_align: after_alias
33+
pad_module_names: true
34+
long_list_align: inline
35+
empty_list_align: inherit
36+
list_padding: 4
37+
separate_lists: true
38+
space_surround: false
39+
ghc_lib_parser: false
40+
41+
- language_pragmas:
42+
style: vertical
43+
align: true
44+
remove_redundant: true
45+
language_prefix: LANGUAGE
46+
47+
# - tabs:
48+
# spaces: 8
49+
50+
- trailing_whitespace: {}
51+
52+
# - squash: {}
53+
54+
columns: 80
55+
56+
newline: native
57+
58+
language_extensions:
59+
- BangPatterns
60+
- DeriveFunctor
61+
- DeriveGeneric
62+
- FlexibleContexts
63+
- GeneralizedNewtypeDeriving
64+
- LambdaCase
65+
- NamedFieldPuns
66+
- OverloadedStrings
67+
- RecordWildCards
68+
- ScopedTypeVariables
69+
- StandaloneDeriving
70+
- TupleSections
71+
- TypeApplications
72+
- ViewPatterns
73+
74+
cabal: true

ghcide/ghcide.cabal

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ source-repository head
2727
type: git
2828
location: https://github.com/haskell/ghcide.git
2929

30+
flag ghc-patched-unboxed-bytecode
31+
description: The GHC version we link against supports unboxed sums and tuples in bytecode
32+
default: False
33+
manual: True
34+
3035
library
3136
default-language: Haskell2010
3237
build-depends:
@@ -190,6 +195,9 @@ library
190195
Development.IDE.Types.Action
191196
ghc-options: -Wall -Wno-name-shadowing -Wincomplete-uni-patterns -Wno-unticked-promoted-constructors
192197

198+
if flag(ghc-patched-unboxed-bytecode)
199+
cpp-options: -DGHC_PATCHED_UNBOXED_BYTECODE
200+
193201
executable ghcide-test-preprocessor
194202
default-language: Haskell2010
195203
hs-source-dirs: test/preprocessor

ghcide/src/Development/IDE/Core/Compile.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,12 @@ generateObjectCode session summary guts = do
325325
(warnings, dot_o_fp) <-
326326
withWarnings "object" $ \_tweak -> do
327327
let summary' = _tweak summary
328-
session' = session { hsc_dflags = (ms_hspp_opts summary') { outputFile = Just dot_o }}
328+
#if MIN_GHC_API_VERSION(8,10,0)
329+
target = defaultObjectTarget $ hsc_dflags session
330+
#else
331+
target = defaultObjectTarget $ targetPlatform $ hsc_dflags session
332+
#endif
333+
session' = session { hsc_dflags = updOptLevel 0 $ (ms_hspp_opts summary') { outputFile = Just dot_o , hscTarget = target}}
329334
(outputFilename, _mStub, _foreign_files) <- hscGenHardCode session' guts
330335
#if MIN_GHC_API_VERSION(8,10,0)
331336
(ms_location summary')

ghcide/src/Development/IDE/Core/RuleTypes.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ import Data.Int (Int64)
4545
import GHC.Serialized (Serialized)
4646

4747
data LinkableType = ObjectLinkable | BCOLinkable
48-
deriving (Eq,Ord,Show)
48+
deriving (Eq,Ord,Show, Generic)
49+
instance Hashable LinkableType
50+
instance NFData LinkableType
4951

5052
-- NOTATION
5153
-- Foo+ means Foo for the dependencies
@@ -337,7 +339,7 @@ instance NFData GetLocatedImports
337339
instance Binary GetLocatedImports
338340

339341
-- | Does this module need to be compiled?
340-
type instance RuleResult NeedsCompilation = Bool
342+
type instance RuleResult NeedsCompilation = Maybe LinkableType
341343

342344
data NeedsCompilation = NeedsCompilation
343345
deriving (Eq, Show, Typeable, Generic)

ghcide/src/Development/IDE/Core/Rules.hs

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,42 +1038,59 @@ getClientConfigAction defValue = do
10381038
Just (Success c) -> return c
10391039
_ -> return defValue
10401040

1041-
-- | For now we always use bytecode
1041+
-- | For now we always use bytecode unless something uses unboxed sums and tuples along with TH
10421042
getLinkableType :: NormalizedFilePath -> Action (Maybe LinkableType)
1043-
getLinkableType f = do
1044-
needsComp <- use_ NeedsCompilation f
1045-
pure $ if needsComp then Just BCOLinkable else Nothing
1043+
getLinkableType f = use_ NeedsCompilation f
10461044

10471045
needsCompilationRule :: Rules ()
10481046
needsCompilationRule = defineEarlyCutoff $ \NeedsCompilation file -> do
1049-
-- It's important to use stale data here to avoid wasted work.
1050-
-- if NeedsCompilation fails for a module M its result will be under-approximated
1051-
-- to False in its dependencies. However, if M actually used TH, this will
1052-
-- cause a re-evaluation of GetModIface for all dependencies
1053-
-- (since we don't need to generate object code anymore).
1054-
-- Once M is fixed we will discover that we actually needed all the object code
1055-
-- that we just threw away, and thus have to recompile all dependencies once
1056-
-- again, this time keeping the object code.
1057-
(ms,_) <- fst <$> useWithStale_ GetModSummaryWithoutTimestamps file
1058-
-- A file needs object code if it uses TemplateHaskell or any file that depends on it uses TemplateHaskell
1059-
res <-
1060-
if uses_th_qq ms
1061-
then pure True
1062-
else do
1063-
graph <- useNoFile GetModuleGraph
1064-
case graph of
1065-
-- Treat as False if some reverse dependency header fails to parse
1066-
Nothing -> pure False
1067-
Just depinfo -> case immediateReverseDependencies file depinfo of
1068-
-- If we fail to get immediate reverse dependencies, fail with an error message
1069-
Nothing -> fail $ "Failed to get the immediate reverse dependencies of " ++ show file
1070-
Just revdeps -> anyM (fmap (fromMaybe False) . use NeedsCompilation) revdeps
1047+
graph <- useNoFile GetModuleGraph
1048+
res <- case graph of
1049+
-- Treat as False if some reverse dependency header fails to parse
1050+
Nothing -> pure Nothing
1051+
Just depinfo -> case immediateReverseDependencies file depinfo of
1052+
-- If we fail to get immediate reverse dependencies, fail with an error message
1053+
Nothing -> fail $ "Failed to get the immediate reverse dependencies of " ++ show file
1054+
Just revdeps -> do
1055+
-- It's important to use stale data here to avoid wasted work.
1056+
-- if NeedsCompilation fails for a module M its result will be under-approximated
1057+
-- to False in its dependencies. However, if M actually used TH, this will
1058+
-- cause a re-evaluation of GetModIface for all dependencies
1059+
-- (since we don't need to generate object code anymore).
1060+
-- Once M is fixed we will discover that we actually needed all the object code
1061+
-- that we just threw away, and thus have to recompile all dependencies once
1062+
-- again, this time keeping the object code.
1063+
-- A file needs to be compiled if any file that depends on it uses TemplateHaskell or needs to be compiled
1064+
(ms,_) <- fst <$> useWithStale_ GetModSummaryWithoutTimestamps file
1065+
(modsums,needsComps) <- par (map (fmap (fst . fst)) <$> usesWithStale GetModSummaryWithoutTimestamps revdeps)
1066+
(uses NeedsCompilation revdeps)
1067+
pure $ computeLinkableType ms modsums (map join needsComps)
10711068

10721069
pure (Just $ BS.pack $ show $ hash res, ([], Just res))
10731070
where
10741071
uses_th_qq (ms_hspp_opts -> dflags) =
10751072
xopt LangExt.TemplateHaskell dflags || xopt LangExt.QuasiQuotes dflags
10761073

1074+
unboxed_tuples_or_sums (ms_hspp_opts -> d) =
1075+
xopt LangExt.UnboxedTuples d || xopt LangExt.UnboxedSums d
1076+
1077+
computeLinkableType :: ModSummary -> [Maybe ModSummary] -> [Maybe LinkableType] -> Maybe LinkableType
1078+
computeLinkableType this deps xs
1079+
| Just ObjectLinkable `elem` xs = Just ObjectLinkable -- If any dependent needs object code, so do we
1080+
| Just BCOLinkable `elem` xs = Just this_type -- If any dependent needs bytecode, then we need to be compiled
1081+
| any (maybe False uses_th_qq) deps = Just this_type -- If any dependent needs TH, then we need to be compiled
1082+
| otherwise = Nothing -- If none of these conditions are satisfied, we don't need to compile
1083+
where
1084+
-- How should we compile this module? (assuming we do in fact need to compile it)
1085+
-- Depends on whether it uses unboxed tuples or sums
1086+
this_type
1087+
#if defined(GHC_PATCHED_UNBOXED_BYTECODE)
1088+
= BCOLinkable
1089+
#else
1090+
| unboxed_tuples_or_sums this = ObjectLinkable
1091+
| otherwise = BCOLinkable
1092+
#endif
1093+
10771094
-- | Tracks which linkables are current, so we don't need to unload them
10781095
newtype CompiledLinkables = CompiledLinkables { getCompiledLinkables :: Var (ModuleEnv UTCTime) }
10791096
instance IsIdeGlobal CompiledLinkables

ghcide/test/data/THUnboxed/THA.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{-# LANGUAGE TemplateHaskell, UnboxedTuples #-}
2+
module THA where
3+
import Language.Haskell.TH
4+
5+
f :: Int -> (# Int, Int #)
6+
f x = (# x , x+1 #)
7+
8+
th_a :: DecsQ
9+
th_a = case f 1 of (# a , b #) -> [d| a = () |]

ghcide/test/data/THUnboxed/THB.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{-# LANGUAGE TemplateHaskell #-}
2+
module THB where
3+
import THA
4+
5+
$th_a

ghcide/test/data/THUnboxed/THC.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module THC where
2+
import THB
3+
4+
c ::()
5+
c = a

ghcide/test/data/THUnboxed/hie.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cradle: {direct: {arguments: ["-Wmissing-signatures", "-package template-haskell", "THA", "THB", "THC"]}}

0 commit comments

Comments
 (0)