Skip to content

Commit 154134f

Browse files
committed
more cleanup & fixes - all tests passing
1 parent 43dc18a commit 154134f

14 files changed

Lines changed: 675 additions & 643 deletions

tests/ParallelTypeCheckingTests/Code/ASTVisit.fs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ type Reference =
1717
Kind : ReferenceKind
1818
}
1919

20-
type Abbreviation = Abbreviation of unit
20+
type Abbreviation =
21+
| ModuleAbbreviation
22+
| TypeAbbreviation
2123

2224
/// Reference to a module or type, found in the AST
2325
type ReferenceOrAbbreviation =
@@ -26,6 +28,12 @@ type ReferenceOrAbbreviation =
2628

2729
type private References = ReferenceOrAbbreviation seq
2830

31+
module Array =
32+
let split<'a, 'b, 'c> (splitter : 'a -> Choice<'b, 'c>) (items : 'a[]) =
33+
let items = items |> Array.map splitter
34+
items |> Array.choose (function Choice1Of2 x -> Some x | _ -> None),
35+
items |> Array.choose (function Choice2Of2 x -> Some x | _ -> None)
36+
2937
module ASTVisit =
3038
let rec visitSynModuleDecl (decl : SynModuleDecl) : References =
3139
// TODO
@@ -45,7 +53,7 @@ module ASTVisit =
4553
| SynModuleDecl.Types(synTypeDefns, range) ->
4654
visitSynTypeDefns synTypeDefns
4755
| SynModuleDecl.ModuleAbbrev(ident, longId, range) ->
48-
[ReferenceOrAbbreviation.Abbreviation (Abbreviation.Abbreviation())]
56+
[ReferenceOrAbbreviation.Abbreviation Abbreviation.ModuleAbbreviation]
4957
| SynModuleDecl.NamespaceFragment synModuleOrNamespace ->
5058
visitSynModuleOrNamespace synModuleOrNamespace
5159
| SynModuleDecl.NestedModule(synComponentInfo, isRecursive, synModuleDecls, isContinuing, range, synModuleDeclNestedModuleTrivia) ->
@@ -380,7 +388,7 @@ module ASTVisit =
380388
yield! visitParserDetail parserDetail
381389
yield! visitType rhsType
382390
// TODO This shouldn't be needed, but for some reason it fixes the 'graph' mode in lib.fs etc.
383-
yield (ReferenceOrAbbreviation.Abbreviation (Abbreviation.Abbreviation()))
391+
yield (ReferenceOrAbbreviation.Abbreviation Abbreviation.TypeAbbreviation)
384392
}
385393
| SynTypeDefnSimpleRepr.LibraryOnlyILAssembly(ilType, range) ->
386394
[]
@@ -1094,18 +1102,13 @@ module ASTVisit =
10941102
synModuleOrNamespaces
10951103
|> Seq.collect visitSynModuleOrNamespace
10961104
|> Seq.toArray
1097-
1105+
10981106
/// Extract partial module references from partial module or type references
1099-
let extractModuleSegments (stuff : ReferenceOrAbbreviation seq) : LongIdent[] * bool =
1100-
1101-
let refs =
1102-
stuff
1103-
|> Seq.choose (function | ReferenceOrAbbreviation.Reference r -> Some r | ReferenceOrAbbreviation.Abbreviation _ -> None)
1104-
|> Seq.toArray
1105-
let abbreviations =
1107+
let extractModuleSegments (stuff : ReferenceOrAbbreviation seq): LongIdent[] * Abbreviation[] =
1108+
let refs, abbreviations =
11061109
stuff
1107-
|> Seq.choose (function | ReferenceOrAbbreviation.Reference _ -> None | ReferenceOrAbbreviation.Abbreviation a -> Some a)
11081110
|> Seq.toArray
1111+
|> Array.split (function | ReferenceOrAbbreviation.Reference r -> Choice1Of2 r | ReferenceOrAbbreviation.Abbreviation a -> Choice2Of2 a)
11091112

11101113
let moduleRefs =
11111114
refs
@@ -1120,9 +1123,8 @@ module ASTVisit =
11201123
| n -> x.Ident.GetSlice(Some 0, n - 2 |> Some) |> Some
11211124
)
11221125
|> Seq.toArray
1123-
let containsModuleAbbreviations = abbreviations.Length > 0
11241126

1125-
moduleRefs, containsModuleAbbreviations
1127+
moduleRefs, abbreviations
11261128

11271129
let findModuleRefs (ast : ParsedInput) =
11281130
let typeAndModuleRefs = findModuleAndTypeRefs ast
@@ -1158,7 +1160,7 @@ module TopModulesExtraction =
11581160
| SynModuleOrNamespace(longId, isRecursive, synModuleOrNamespaceKind, synModuleDecls, preXmlDoc, synAttributeLists, synAccessOption, range, synModuleOrNamespaceTrivia) ->
11591161
if mightHaveAutoOpen synAttributeLists then
11601162
// Contents of a module that's potentially AutoOpen are available from its parent without a prefix.
1161-
// Treat it as a type - as soon as the parent module is reachable, consider the file being used
1163+
// Stay safe and as soon as the parent module is reachable, consider this module reachable as well
11621164
[|LongIdent.Empty|]
11631165
else
11641166
[|longId|]

tests/ParallelTypeCheckingTests/Code/DepResolving.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ module internal AutomatedDependencyResolving =
143143
printfn $"{backed.Length} backed files found"
144144
let filesWithModuleAbbreviations =
145145
nodes
146-
|> Array.filter (fun n -> n.Data.ContainsModuleAbbreviations)
146+
|> Array.filter (fun n -> n.Data.Abbreviations |> Array.exists (function Abbreviation.ModuleAbbreviation _ -> true | _ -> false))
147147

148148
let trie = buildTrie nodes
149149

@@ -161,7 +161,7 @@ module internal AutomatedDependencyResolving =
161161
else
162162
[||]
163163
// Assume that a file with module abbreviations can depend on anything
164-
match node.Data.ContainsModuleAbbreviations with
164+
match node.Data.Abbreviations |> Array.isEmpty |> not with
165165
| true -> nodes |> Array.map (fun n -> n.File)
166166
| false ->
167167
// Clone the original Trie as we're going to mutate the copy
@@ -272,13 +272,13 @@ module internal AutomatedDependencyResolving =
272272

273273
let totalSize1 =
274274
graph
275-
|> Seq.sumBy (fun (KeyValue(k,v)) -> v.Length)
275+
|> Seq.sumBy (fun (KeyValue(_k,v)) -> v.Length)
276276
let t =
277277
graph
278278
|> Graph.transitive
279279
let totalSize2 =
280280
t
281-
|> Seq.sumBy (fun (KeyValue(k,v)) -> v.Length)
281+
|> Seq.sumBy (fun (KeyValue(_k,v)) -> v.Length)
282282

283283
printfn $"Non-transitive size: {totalSize1}, transitive size: {totalSize2}"
284284

tests/ParallelTypeCheckingTests/Code/FileInfoGathering.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type ExtractedData =
3333
{
3434
/// Order of the file in the project. Files with lower number cannot depend on files with higher number
3535
Tops : LongIdent[]
36-
ContainsModuleAbbreviations : bool
36+
Abbreviations : Abbreviation[]
3737
/// All partial module references found in this file's AST
3838
ModuleRefs : LongIdent[]
3939
}
@@ -47,14 +47,14 @@ type FileData =
4747
with member this.CodeSize = this.File.CodeSize
4848

4949
let private gatherFileData (ast : ParsedInput) : ExtractedData =
50-
let moduleRefs, containsModuleAbbreviations = ASTVisit.findModuleRefs ast
50+
let moduleRefs, abbreviations = ASTVisit.findModuleRefs ast
5151
let tops = TopModulesExtraction.topModuleOrNamespaces ast
5252
// TODO As a perf optimisation we can skip top-level ids scanning for FsiBacked .fs files
5353
// However, it is unlikely to give a noticable speedup due to parallelism (citation needed)
5454
{
5555
ModuleRefs = moduleRefs
5656
Tops = tops
57-
ContainsModuleAbbreviations = containsModuleAbbreviations
57+
Abbreviations = abbreviations
5858
}
5959

6060
/// Extract necessary information from all files in parallel - top-level items and all (partial) module references

tests/ParallelTypeCheckingTests/Code/GraphProcessing.fs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ let combineResults
147147
let state = Array.fold folder firstState resultsToAdd
148148
state
149149

150-
151150
// TODO Could be replaced with a simpler recursive approach with memoised per-item results
152151
let processGraph<'Item, 'State, 'Result, 'FinalFileResult when 'Item : equality and 'Item : comparison>
153152
(graph : Graph<'Item>)
@@ -243,13 +242,13 @@ let processGraph<'Item, 'State, 'Result, 'FinalFileResult when 'Item : equality
243242
let nodesArray = nodes.Values |> Seq.toArray
244243
let finals, {State = state}: 'FinalFileResult[] * StateWrapper<'Item, 'State> =
245244
nodesArray
245+
|> Array.filter (fun node -> includeInFinalState node.Info.Item)
246246
|> Array.sortBy (fun node -> node.Info.Item)
247247
|> fun nodes ->
248248
printfn $"%+A{nodes |> Array.map (fun n -> n.Info.Item.ToString())}"
249249
nodes
250250
|> Array.fold (fun (fileResults, state) node ->
251-
let fileResult, newState = folder state (node.Result.Value |> snd)
252-
let state = if includeInFinalState node.Info.Item then newState else state
251+
let fileResult, state = folder state (node.Result.Value |> snd)
253252
Array.append fileResults [|fileResult|], state
254253
) ([||], emptyState)
255254

0 commit comments

Comments
 (0)