Skip to content

Commit 413bb83

Browse files
committed
feat: defer merging of common stanza imports
proof of concept retain imports for foreignLib section retain imports for executable section retain imports for test-suite retain imports for benchmark attempt to insert used imports and not all imports use newtype change import data type; fix issues with import propagation & decoration fix missing import names in testSuite fix missing import names in benchmark run fourmolu run hlint defer merging prototype Currently we have achieve the following: - Stop merging, the merging function "endo" is id - CondTree are completly retained in bigger types such as libarry and executable We will need to do the following: - Allow merging in the accessor We broke: - A bunch of Read and Ord instances Revert "defer merging prototype" This reverts commit 21636db. stop merging retain common stanza in GenericPackageDescription experiment: use WithImport in gpd add function to merge imports mergeLibrary fix transitive imports retaintion and merging run fourmolu deferred merging for sublibraries simplification; remove todos retain foreignlib imports retain executable imports retain TestSuiteStanza imports We isolated the type TestSuiteStanza and the logic to infer test type retain BenchmarkStanza imports We isolated the BenchmarkStanza type and the logic to infer benchmark type. clean up remove benchmark import field We now use the WithImports type to tag imports introduce type alias in GenericPackageDescription add GenericPackageDescription pattern to hide internal implementation backward compatible accessors fix compiler errors add todo fix compiler errors for integration test run fourmolu don't expose intemediary accessors remove early experiment "import" fields in TestSuite and Benchmark move TestSuiteStanza validation to its module clean up {TestSuite,Benchmark}Stanza exports from FieldGrammar restore old behaviour in code working with PackageDescription we fixed GenericPackageDescription's constructor patch {TestSuite,Benchmark}Stanza type when using accessor remove accessors tests fix accessor dropping common stanza map when non it is not required This guarantees that unmerged internal representation is correct run fourmolu remove FieldGrammar export {TestSuite,Benchmark}Stanza fix(GenericPackageDescription): "pattern" keyword deprecated after 914 test: remove new test files test: add tests for gpd accessors test: check equality on each field test: improve import list test: use @? operator test: use a tuple to store all gpd fields test: define ToExpr tuple instance manually test: update expected test: use Rec constructor to annotate field names test: update expected test: remove comment not in scope for this PR test: use field equality in hackage tests test: add new test files test: fix test build test: newtype to guide GPD ToExpr instance test: add internal accessors test test: update expected for internal accessors test test: update expected test: fix hackage tests ToExpr instance
1 parent 8365cec commit 413bb83

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+2184
-611
lines changed

Cabal-syntax/Cabal-syntax.cabal

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ library
121121
Distribution.Types.AbiDependency
122122
Distribution.Types.AbiHash
123123
Distribution.Types.Benchmark
124+
Distribution.Types.BenchmarkStanza
124125
Distribution.Types.Benchmark.Lens
125126
Distribution.Types.BenchmarkInterface
126127
Distribution.Types.BenchmarkType
@@ -160,6 +161,8 @@ library
160161
Distribution.Types.Library.Lens
161162
Distribution.Types.LibraryName
162163
Distribution.Types.LibraryVisibility
164+
Distribution.Types.Imports
165+
Distribution.Types.Imports.Lens
163166
Distribution.Types.MissingDependency
164167
Distribution.Types.MissingDependencyReason
165168
Distribution.Types.Mixin
@@ -183,6 +186,7 @@ library
183186
Distribution.Types.SourceRepo
184187
Distribution.Types.SourceRepo.Lens
185188
Distribution.Types.TestSuite
189+
Distribution.Types.TestSuiteStanza
186190
Distribution.Types.TestSuite.Lens
187191
Distribution.Types.TestSuiteInterface
188192
Distribution.Types.TestType

Cabal-syntax/src/Distribution/PackageDescription.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ module Distribution.PackageDescription
1515
module Distribution.Types.PackageDescription
1616
, module Distribution.Types.GenericPackageDescription
1717

18+
-- * Working with Imports
19+
, module Distribution.Types.Imports
20+
1821
-- * Components
1922
, module Distribution.Types.ComponentName
2023

@@ -29,11 +32,13 @@ module Distribution.PackageDescription
2932

3033
-- ** TestSuite
3134
, module Distribution.Types.TestSuite
35+
, module Distribution.Types.TestSuiteStanza
3236
, module Distribution.Types.TestType
3337
, module Distribution.Types.TestSuiteInterface
3438

3539
-- ** Benchmark
3640
, module Distribution.Types.Benchmark
41+
, module Distribution.Types.BenchmarkStanza
3742
, module Distribution.Types.BenchmarkType
3843
, module Distribution.Types.BenchmarkInterface
3944

@@ -88,6 +93,7 @@ import Prelude ()
8893

8994
import Distribution.Types.Benchmark
9095
import Distribution.Types.BenchmarkInterface
96+
import Distribution.Types.BenchmarkStanza
9197
import Distribution.Types.BenchmarkType
9298
import Distribution.Types.BuildInfo
9399
import Distribution.Types.BuildType
@@ -105,6 +111,7 @@ import Distribution.Types.ForeignLibOption
105111
import Distribution.Types.ForeignLibType
106112
import Distribution.Types.GenericPackageDescription
107113
import Distribution.Types.HookedBuildInfo
114+
import Distribution.Types.Imports
108115
import Distribution.Types.IncludeRenaming
109116
import Distribution.Types.LegacyExeDependency
110117
import Distribution.Types.Library
@@ -124,5 +131,6 @@ import Distribution.Types.SetupBuildInfo
124131
import Distribution.Types.SourceRepo
125132
import Distribution.Types.TestSuite
126133
import Distribution.Types.TestSuiteInterface
134+
import Distribution.Types.TestSuiteStanza
127135
import Distribution.Types.TestType
128136
import Distribution.Types.UnqualComponentName

Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs

Lines changed: 0 additions & 232 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,10 @@ module Distribution.PackageDescription.FieldGrammar
2222
, executableFieldGrammar
2323

2424
-- * Test suite
25-
, TestSuiteStanza (..)
2625
, testSuiteFieldGrammar
27-
, validateTestSuite
28-
, unvalidateTestSuite
29-
30-
-- ** Lenses
31-
, testStanzaTestType
32-
, testStanzaMainIs
33-
, testStanzaTestModule
34-
, testStanzaBuildInfo
3526

3627
-- * Benchmark
37-
, BenchmarkStanza (..)
3828
, benchmarkFieldGrammar
39-
, validateBenchmark
40-
, unvalidateBenchmark
4129

4230
-- * Field grammars
4331
, formatDependencyList
@@ -48,12 +36,6 @@ module Distribution.PackageDescription.FieldGrammar
4836
, formatOtherExtensions
4937
, formatOtherModules
5038

51-
-- ** Lenses
52-
, benchmarkStanzaBenchmarkType
53-
, benchmarkStanzaMainIs
54-
, benchmarkStanzaBenchmarkModule
55-
, benchmarkStanzaBuildInfo
56-
5739
-- * Flag
5840
, flagFieldGrammar
5941

@@ -290,43 +272,6 @@ executableFieldGrammar n =
290272
{-# SPECIALIZE executableFieldGrammar :: UnqualComponentName -> ParsecFieldGrammar' Executable #-}
291273
{-# SPECIALIZE executableFieldGrammar :: UnqualComponentName -> PrettyFieldGrammar' Executable #-}
292274

293-
-------------------------------------------------------------------------------
294-
-- TestSuite
295-
-------------------------------------------------------------------------------
296-
297-
-- | An intermediate type just used for parsing the test-suite stanza.
298-
-- After validation it is converted into the proper 'TestSuite' type.
299-
data TestSuiteStanza = TestSuiteStanza
300-
{ _testStanzaTestType :: Maybe TestType
301-
, _testStanzaMainIs :: Maybe (RelativePath Source File)
302-
, _testStanzaTestModule :: Maybe ModuleName
303-
, _testStanzaBuildInfo :: BuildInfo
304-
, _testStanzaCodeGenerators :: [String]
305-
}
306-
307-
instance L.HasBuildInfo TestSuiteStanza where
308-
buildInfo = testStanzaBuildInfo
309-
310-
testStanzaTestType :: Lens' TestSuiteStanza (Maybe TestType)
311-
testStanzaTestType f s = fmap (\x -> s{_testStanzaTestType = x}) (f (_testStanzaTestType s))
312-
{-# INLINE testStanzaTestType #-}
313-
314-
testStanzaMainIs :: Lens' TestSuiteStanza (Maybe (RelativePath Source File))
315-
testStanzaMainIs f s = fmap (\x -> s{_testStanzaMainIs = x}) (f (_testStanzaMainIs s))
316-
{-# INLINE testStanzaMainIs #-}
317-
318-
testStanzaTestModule :: Lens' TestSuiteStanza (Maybe ModuleName)
319-
testStanzaTestModule f s = fmap (\x -> s{_testStanzaTestModule = x}) (f (_testStanzaTestModule s))
320-
{-# INLINE testStanzaTestModule #-}
321-
322-
testStanzaBuildInfo :: Lens' TestSuiteStanza BuildInfo
323-
testStanzaBuildInfo f s = fmap (\x -> s{_testStanzaBuildInfo = x}) (f (_testStanzaBuildInfo s))
324-
{-# INLINE testStanzaBuildInfo #-}
325-
326-
testStanzaCodeGenerators :: Lens' TestSuiteStanza [String]
327-
testStanzaCodeGenerators f s = fmap (\x -> s{_testStanzaCodeGenerators = x}) (f (_testStanzaCodeGenerators s))
328-
{-# INLINE testStanzaCodeGenerators #-}
329-
330275
testSuiteFieldGrammar
331276
:: ( FieldGrammar c g
332277
, Applicative (g TestSuiteStanza)
@@ -361,117 +306,10 @@ testSuiteFieldGrammar =
361306
<*> monoidalFieldAla "code-generators" (alaList' CommaFSep Token) testStanzaCodeGenerators
362307
^^^ availableSince CabalSpecV3_8 []
363308

364-
validateTestSuite :: CabalSpecVersion -> Position -> TestSuiteStanza -> ParseResult src TestSuite
365-
validateTestSuite cabalSpecVersion pos stanza = case testSuiteType of
366-
Nothing -> pure basicTestSuite
367-
Just tt@(TestTypeUnknown _ _) ->
368-
pure
369-
basicTestSuite
370-
{ testInterface = TestSuiteUnsupported tt
371-
}
372-
Just tt
373-
| tt `notElem` knownTestTypes ->
374-
pure
375-
basicTestSuite
376-
{ testInterface = TestSuiteUnsupported tt
377-
}
378-
Just tt@(TestTypeExe ver) -> case _testStanzaMainIs stanza of
379-
Nothing -> do
380-
parseFailure pos (missingField "main-is" tt)
381-
pure emptyTestSuite
382-
Just file -> do
383-
when (isJust (_testStanzaTestModule stanza)) $
384-
parseWarning pos PWTExtraBenchmarkModule (extraField "test-module" tt)
385-
pure
386-
basicTestSuite
387-
{ testInterface = TestSuiteExeV10 ver file
388-
}
389-
Just tt@(TestTypeLib ver) -> case _testStanzaTestModule stanza of
390-
Nothing -> do
391-
parseFailure pos (missingField "test-module" tt)
392-
pure emptyTestSuite
393-
Just module_ -> do
394-
when (isJust (_testStanzaMainIs stanza)) $
395-
parseWarning pos PWTExtraMainIs (extraField "main-is" tt)
396-
pure
397-
basicTestSuite
398-
{ testInterface = TestSuiteLibV09 ver module_
399-
}
400-
where
401-
testSuiteType =
402-
_testStanzaTestType stanza
403-
<|> do
404-
guard (cabalSpecVersion >= CabalSpecV3_8)
405-
406-
testTypeExe <$ _testStanzaMainIs stanza
407-
<|> testTypeLib <$ _testStanzaTestModule stanza
408-
409-
missingField name tt =
410-
"The '"
411-
++ name
412-
++ "' field is required for the "
413-
++ prettyShow tt
414-
++ " test suite type."
415-
416-
extraField name tt =
417-
"The '"
418-
++ name
419-
++ "' field is not used for the '"
420-
++ prettyShow tt
421-
++ "' test suite type."
422-
basicTestSuite =
423-
emptyTestSuite
424-
{ testBuildInfo = _testStanzaBuildInfo stanza
425-
, testCodeGenerators = _testStanzaCodeGenerators stanza
426-
}
427-
428-
unvalidateTestSuite :: TestSuite -> TestSuiteStanza
429-
unvalidateTestSuite t =
430-
TestSuiteStanza
431-
{ _testStanzaTestType = ty
432-
, _testStanzaMainIs = ma
433-
, _testStanzaTestModule = mo
434-
, _testStanzaBuildInfo = testBuildInfo t
435-
, _testStanzaCodeGenerators = testCodeGenerators t
436-
}
437-
where
438-
(ty, ma, mo) = case testInterface t of
439-
TestSuiteExeV10 ver file -> (Just $ TestTypeExe ver, Just file, Nothing)
440-
TestSuiteLibV09 ver modu -> (Just $ TestTypeLib ver, Nothing, Just modu)
441-
_ -> (Nothing, Nothing, Nothing)
442-
443309
-------------------------------------------------------------------------------
444310
-- Benchmark
445311
-------------------------------------------------------------------------------
446312

447-
-- | An intermediate type just used for parsing the benchmark stanza.
448-
-- After validation it is converted into the proper 'Benchmark' type.
449-
data BenchmarkStanza = BenchmarkStanza
450-
{ _benchmarkStanzaBenchmarkType :: Maybe BenchmarkType
451-
, _benchmarkStanzaMainIs :: Maybe (RelativePath Source File)
452-
, _benchmarkStanzaBenchmarkModule :: Maybe ModuleName
453-
, _benchmarkStanzaBuildInfo :: BuildInfo
454-
}
455-
456-
instance L.HasBuildInfo BenchmarkStanza where
457-
buildInfo = benchmarkStanzaBuildInfo
458-
459-
benchmarkStanzaBenchmarkType :: Lens' BenchmarkStanza (Maybe BenchmarkType)
460-
benchmarkStanzaBenchmarkType f s = fmap (\x -> s{_benchmarkStanzaBenchmarkType = x}) (f (_benchmarkStanzaBenchmarkType s))
461-
{-# INLINE benchmarkStanzaBenchmarkType #-}
462-
463-
benchmarkStanzaMainIs :: Lens' BenchmarkStanza (Maybe (RelativePath Source File))
464-
benchmarkStanzaMainIs f s = fmap (\x -> s{_benchmarkStanzaMainIs = x}) (f (_benchmarkStanzaMainIs s))
465-
{-# INLINE benchmarkStanzaMainIs #-}
466-
467-
benchmarkStanzaBenchmarkModule :: Lens' BenchmarkStanza (Maybe ModuleName)
468-
benchmarkStanzaBenchmarkModule f s = fmap (\x -> s{_benchmarkStanzaBenchmarkModule = x}) (f (_benchmarkStanzaBenchmarkModule s))
469-
{-# INLINE benchmarkStanzaBenchmarkModule #-}
470-
471-
benchmarkStanzaBuildInfo :: Lens' BenchmarkStanza BuildInfo
472-
benchmarkStanzaBuildInfo f s = fmap (\x -> s{_benchmarkStanzaBuildInfo = x}) (f (_benchmarkStanzaBuildInfo s))
473-
{-# INLINE benchmarkStanzaBuildInfo #-}
474-
475313
benchmarkFieldGrammar
476314
:: ( FieldGrammar c g
477315
, Applicative (g BenchmarkStanza)
@@ -503,76 +341,6 @@ benchmarkFieldGrammar =
503341
<*> optionalField "benchmark-module" benchmarkStanzaBenchmarkModule
504342
<*> blurFieldGrammar benchmarkStanzaBuildInfo buildInfoFieldGrammar
505343

506-
validateBenchmark :: CabalSpecVersion -> Position -> BenchmarkStanza -> ParseResult src Benchmark
507-
validateBenchmark cabalSpecVersion pos stanza = case benchmarkStanzaType of
508-
Nothing ->
509-
pure
510-
emptyBenchmark
511-
{ benchmarkBuildInfo = _benchmarkStanzaBuildInfo stanza
512-
}
513-
Just tt@(BenchmarkTypeUnknown _ _) ->
514-
pure
515-
emptyBenchmark
516-
{ benchmarkInterface = BenchmarkUnsupported tt
517-
, benchmarkBuildInfo = _benchmarkStanzaBuildInfo stanza
518-
}
519-
Just tt
520-
| tt `notElem` knownBenchmarkTypes ->
521-
pure
522-
emptyBenchmark
523-
{ benchmarkInterface = BenchmarkUnsupported tt
524-
, benchmarkBuildInfo = _benchmarkStanzaBuildInfo stanza
525-
}
526-
Just tt@(BenchmarkTypeExe ver) -> case _benchmarkStanzaMainIs stanza of
527-
Nothing -> do
528-
parseFailure pos (missingField "main-is" tt)
529-
pure emptyBenchmark
530-
Just file -> do
531-
when (isJust (_benchmarkStanzaBenchmarkModule stanza)) $
532-
parseWarning pos PWTExtraBenchmarkModule (extraField "benchmark-module" tt)
533-
pure
534-
emptyBenchmark
535-
{ benchmarkInterface = BenchmarkExeV10 ver file
536-
, benchmarkBuildInfo = _benchmarkStanzaBuildInfo stanza
537-
}
538-
where
539-
benchmarkStanzaType =
540-
_benchmarkStanzaBenchmarkType stanza <|> do
541-
guard (cabalSpecVersion >= CabalSpecV3_8)
542-
543-
benchmarkTypeExe <$ _benchmarkStanzaMainIs stanza
544-
545-
missingField name tt =
546-
"The '"
547-
++ name
548-
++ "' field is required for the "
549-
++ prettyShow tt
550-
++ " benchmark type."
551-
552-
extraField name tt =
553-
"The '"
554-
++ name
555-
++ "' field is not used for the '"
556-
++ prettyShow tt
557-
++ "' benchmark type."
558-
559-
unvalidateBenchmark :: Benchmark -> BenchmarkStanza
560-
unvalidateBenchmark b =
561-
BenchmarkStanza
562-
{ _benchmarkStanzaBenchmarkType = ty
563-
, _benchmarkStanzaMainIs = ma
564-
, _benchmarkStanzaBenchmarkModule = mo
565-
, _benchmarkStanzaBuildInfo = benchmarkBuildInfo b
566-
}
567-
where
568-
(ty, ma, mo) = case benchmarkInterface b of
569-
BenchmarkExeV10 ver ma'
570-
| getSymbolicPath ma' == "" ->
571-
(Just $ BenchmarkTypeExe ver, Nothing, Nothing)
572-
| otherwise ->
573-
(Just $ BenchmarkTypeExe ver, Just ma', Nothing)
574-
_ -> (Nothing, Nothing, Nothing)
575-
576344
-------------------------------------------------------------------------------
577345
-- Build info
578346
-------------------------------------------------------------------------------

0 commit comments

Comments
 (0)