Skip to content

Commit 7fb31ec

Browse files
committed
Port code to target projects.
1 parent a20c50d commit 7fb31ec

Some content is hidden

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

62 files changed

+709
-2885
lines changed

FSharp.Compiler.Service.sln

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
4040
src\Compiler\FSComp.txt = src\Compiler\FSComp.txt
4141
EndProjectSection
4242
EndProject
43-
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "ParallelTypeCheckingTests", "tests\ParallelTypeCheckingTests\ParallelTypeCheckingTests.fsproj", "{60EDC1C4-5B8B-4211-94CD-4CF5F9E0FC8B}"
44-
EndProject
45-
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "DiamondTest", "tests\DiamondTest\DiamondTest.fsproj", "{62288B06-B682-4774-A8A5-A21D677A7C70}"
46-
EndProject
4743
Global
4844
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4945
Debug|Any CPU = Debug|Any CPU
@@ -90,14 +86,6 @@ Global
9086
{07CD957A-3C31-4F75-A735-16CE72E1BD71}.Debug|Any CPU.Build.0 = Debug|Any CPU
9187
{07CD957A-3C31-4F75-A735-16CE72E1BD71}.Release|Any CPU.ActiveCfg = Release|Any CPU
9288
{07CD957A-3C31-4F75-A735-16CE72E1BD71}.Release|Any CPU.Build.0 = Release|Any CPU
93-
{60EDC1C4-5B8B-4211-94CD-4CF5F9E0FC8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
94-
{60EDC1C4-5B8B-4211-94CD-4CF5F9E0FC8B}.Debug|Any CPU.Build.0 = Debug|Any CPU
95-
{60EDC1C4-5B8B-4211-94CD-4CF5F9E0FC8B}.Release|Any CPU.ActiveCfg = Release|Any CPU
96-
{60EDC1C4-5B8B-4211-94CD-4CF5F9E0FC8B}.Release|Any CPU.Build.0 = Release|Any CPU
97-
{62288B06-B682-4774-A8A5-A21D677A7C70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
98-
{62288B06-B682-4774-A8A5-A21D677A7C70}.Debug|Any CPU.Build.0 = Debug|Any CPU
99-
{62288B06-B682-4774-A8A5-A21D677A7C70}.Release|Any CPU.ActiveCfg = Release|Any CPU
100-
{62288B06-B682-4774-A8A5-A21D677A7C70}.Release|Any CPU.Build.0 = Release|Any CPU
10189
EndGlobalSection
10290
GlobalSection(SolutionProperties) = preSolution
10391
HideSolutionNode = FALSE

tests/ParallelTypeCheckingTests/Code/Utils.fs renamed to src/Compiler/Driver/GraphChecking/Continuation.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[<RequireQualifiedAccess>]
2-
module ParallelTypeCheckingTests.Continuation
2+
module Continuation
33

44
let rec sequence<'a, 'ret> (recursions: (('a -> 'ret) -> 'ret) list) (finalContinuation: 'a list -> 'ret) : 'ret =
55
match recursions with

tests/ParallelTypeCheckingTests/Code/DependencyResolution.fs renamed to src/Compiler/Driver/GraphChecking/DependencyResolution.fs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
module ParallelTypeCheckingTests.DependencyResolution
1+
module FSharp.Compiler.GraphChecking.DependencyResolution
22

33
open FSharp.Compiler.Syntax
4-
open ParallelTypeCheckingTests
54

65
// This code just looks for a path in the trie
76
// It could be cached and is easy to reason about.
@@ -130,7 +129,7 @@ let indicesUnderNode (node: TrieNode) : Set<int> =
130129
Set.ofList (collect node id)
131130

132131
/// <summary>
133-
/// For a given file's content, find all missing ("ghost") file dependencies that are required to satisfy the type-checker.
132+
/// For a given file's content, find all missing ("ghost") file dependencies that are required to satisfy the type-checker.
134133
/// </summary>
135134
/// <remarks>
136135
/// A "ghost" dependency is a link between files that actually should be avoided.
File renamed without changes.

tests/ParallelTypeCheckingTests/Code/FileContentMapping.fs renamed to src/Compiler/Driver/GraphChecking/FileContentMapping.fs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
module rec ParallelTypeCheckingTests.FileContentMapping
1+
module rec FSharp.Compiler.GraphChecking.FileContentMapping
22

33
open FSharp.Compiler.Syntax
44
open FSharp.Compiler.SyntaxTreeOps
5-
open ParallelTypeCheckingTests
65

76
type Continuations = ((FileContentEntry list -> FileContentEntry list) -> FileContentEntry list) list
87

tests/ParallelTypeCheckingTests/Code/Graph.fs renamed to src/Compiler/Driver/GraphChecking/Graph.fs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
namespace ParallelTypeCheckingTests
1+
namespace FSharp.Compiler.GraphChecking
22

33
#nowarn "1182"
44
#nowarn "40"
55

66
open System.Collections.Concurrent
77
open System.Collections.Generic
8-
open System.IO
9-
open Newtonsoft.Json
8+
open System.Linq
109

1110
/// <summary> Directed Acyclic Graph (DAG) of arbitrary nodes </summary>
1211
type Graph<'Node> = IReadOnlyDictionary<'Node, 'Node[]>
@@ -36,9 +35,8 @@ module Graph =
3635
|> Seq.except (graph.Keys |> Seq.toArray)
3736
|> fun missing ->
3837
let toAdd = missing |> Seq.map (fun n -> KeyValuePair(n, [||])) |> Seq.toArray
39-
40-
let x = Array.append (graph |> Seq.toArray) toAdd
41-
x |> Dictionary<_, _> |> (fun x -> x :> IReadOnlyDictionary<_, _>)
38+
let x: KeyValuePair<'Node, 'Node[]>[] = Array.append (graph |> Seq.toArray) toAdd
39+
x.ToDictionary((fun (KeyValue (x, _)) -> x), (fun (KeyValue (_, v)) -> v)) :> IReadOnlyDictionary<_, _>
4240

4341
/// Create entries for nodes that don't have any dependencies but are mentioned as dependencies themselves
4442
let fillEmptyNodes<'Node when 'Node: equality> (graph: Graph<'Node>) : Graph<'Node> =
@@ -85,7 +83,17 @@ module Graph =
8583
let print (graph: Graph<'Node>) : unit =
8684
printCustom graph (fun node -> node.ToString())
8785

88-
let serialiseToJson (path: string) (graph: Graph<'Node>) : unit =
89-
let json = JsonConvert.SerializeObject(graph, Formatting.Indented)
90-
printfn $"Serialising graph as JSON in {path}"
91-
File.WriteAllText(path, json)
86+
let serialiseToJson (path: string) (graph: Graph<string>) : unit =
87+
let escapeName (name: string) =
88+
name.Replace("\\", "\\\\") |> sprintf "\"%s\""
89+
90+
let entries =
91+
graph
92+
|> Seq.map (fun (KeyValue (file, deps)) ->
93+
let deps = deps |> Seq.map escapeName |> String.concat "," |> sprintf "[ %s ]"
94+
95+
$" {escapeName file}: {deps}")
96+
|> String.concat ","
97+
98+
let json = $"{{\n{entries}\n}}"
99+
System.IO.File.WriteAllText(path, json)

tests/ParallelTypeCheckingTests/Code/GraphProcessing.fs renamed to src/Compiler/Driver/GraphChecking/GraphProcessing.fs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/// Parallel processing of graph of work items with dependencies
2-
module ParallelTypeCheckingTests.GraphProcessing
2+
module FSharp.Compiler.GraphChecking.GraphProcessing
33

44
open System.Threading
55

6-
/// Information about the node in a graph, describing its relation with other nodes.
6+
/// Information about the node in a graph, describing its relation with other nodes.
77
type NodeInfo<'Item> =
88
{
99
Item: 'Item
@@ -17,8 +17,7 @@ type IncrementableInt(value: int) =
1717
with
1818
member this.Value = value
1919
// Increment the value in a thread-safe manner and return the new value.
20-
member this.Increment() =
21-
Interlocked.Increment (&value)
20+
member this.Increment() = Interlocked.Increment(&value)
2221

2322
type private GraphNode<'Item, 'Result> =
2423
{
@@ -101,29 +100,28 @@ let processGraph<'Item, 'Result when 'Item: equality and 'Item: comparison>
101100
}
102101

103102
let processedCount = IncrementableInt(0)
104-
let mutable exn : ('Item * System.Exception) option = None
103+
let mutable exn: ('Item * System.Exception) option = None
104+
105105
let incrementProcessedNodesCount () =
106106
if processedCount.Increment() = nodes.Count then
107-
waitHandle.Set() |> ignore
107+
waitHandle.Set()
108108

109109
let rec queueNode node =
110110
Async.Start(
111111
async {
112-
let! res =
113-
async {
114-
processNode node
115-
}
116-
|> Async.Catch
112+
let! res = async { processNode node } |> Async.Catch
113+
117114
match res with
118115
| Choice1Of2 () -> ()
119116
| Choice2Of2 ex ->
120-
exn <- Some (node.Info.Item, ex)
121-
waitHandle.Set() |> ignore
122-
}
123-
,ct)
117+
exn <- Some(node.Info.Item, ex)
118+
waitHandle.Set()
119+
},
120+
ct
121+
)
124122

125123
and processNode (node: GraphNode<'Item, 'Result>) : unit =
126-
124+
127125
let info = node.Info
128126

129127
let singleRes = work getItemPublicNode info
@@ -141,14 +139,14 @@ let processGraph<'Item, 'Result when 'Item: equality and 'Item: comparison>
141139

142140
unblockedDependants |> Array.iter queueNode
143141
incrementProcessedNodesCount ()
144-
142+
145143
leaves |> Array.iter queueNode
146144

147-
waitHandle.Wait(ct) |> ignore
145+
waitHandle.Wait(ct)
146+
148147
match exn with
149148
| None -> ()
150-
| Some (item, ex) ->
151-
raise (System.Exception($"Encountered exception when processing item '{item}'", ex))
149+
| Some (item, ex) -> raise (System.Exception($"Encountered exception when processing item '{item}'", ex))
152150

153151
nodes.Values
154152
|> Seq.map (fun node ->

tests/ParallelTypeCheckingTests/Code/Parallel.fs renamed to src/Compiler/Driver/GraphChecking/Parallel.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module ParallelTypeCheckingTests.Parallel
1+
module FSharp.Compiler.GraphChecking.Parallel
22

33
open System
44
open System.Collections.Concurrent

tests/ParallelTypeCheckingTests/Code/TrieMapping.fs renamed to src/Compiler/Driver/GraphChecking/TrieMapping.fs

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
module ParallelTypeCheckingTests.TrieMapping
1+
module FSharp.Compiler.GraphChecking.TrieMapping
22

33
open System.Collections.Generic
44
open FSharp.Compiler.Syntax
55
open Microsoft.FSharp.Collections
66

77
let hs f = HashSet(Seq.singleton f)
8-
let emptyHS () = HashSet(0)
8+
let emptyHS () = HashSet(Seq.empty)
99

1010
let private autoOpenShapes =
1111
set
@@ -94,6 +94,19 @@ let mergeTrieNodes (defaultChildSize: int) (tries: TrieNode array) =
9494

9595
root
9696

97+
let private mkDictFromKeyValuePairs (items: KeyValuePair<'tkey, 'tvalue> seq) =
98+
let dict = Dictionary(Seq.length items)
99+
100+
for KeyValue (k, v) in items do
101+
dict.Add(k, v)
102+
103+
dict
104+
105+
let private mkSingletonDict key value =
106+
let dict = Dictionary(1)
107+
dict.Add(key, value)
108+
dict
109+
97110
/// Process a top level SynModuleOrNamespace(Sig)
98111
let processSynModuleOrNamespace<'Decl>
99112
(mkTrieForDeclaration: int -> 'Decl -> KeyValuePair<string, TrieNode> option)
@@ -136,21 +149,16 @@ let processSynModuleOrNamespace<'Decl>
136149
else
137150
TrieNodeInfo.Module(name, idx)
138151

139-
let children = List.choose (mkTrieForDeclaration idx) decls
140-
141-
continuation (
142-
Dictionary<_, _>(
143-
Seq.singleton (
144-
KeyValuePair(
145-
name,
146-
{
147-
Current = current
148-
Children = Dictionary(children)
149-
}
150-
)
151-
)
152-
)
153-
)
152+
let children =
153+
List.choose (mkTrieForDeclaration idx) decls |> mkDictFromKeyValuePairs
154+
155+
mkSingletonDict
156+
name
157+
{
158+
Current = current
159+
Children = children
160+
}
161+
|> continuation
154162
| head :: tail ->
155163
let name = head.idText
156164

@@ -175,14 +183,13 @@ let processSynModuleOrNamespace<'Decl>
175183

176184
let current = TrieNodeInfo.Namespace(name, files)
177185

178-
Dictionary<_, _>(Seq.singleton (KeyValuePair(name, { Current = current; Children = node })))
179-
|> continuation)
186+
mkSingletonDict name { Current = current; Children = node } |> continuation)
180187
tail
181188

182189
if List.isEmpty name then
183190
// This can happen for a namespace global.
184191
// We collect the child nodes from the decls
185-
List.choose (mkTrieForDeclaration idx) decls |> Dictionary
192+
List.choose (mkTrieForDeclaration idx) decls |> mkDictFromKeyValuePairs
186193
else
187194
visit id name
188195

@@ -243,14 +250,16 @@ and mkTrieForSynModuleDecl (fileIndex: int) (decl: SynModuleDecl) : KeyValuePair
243250
match decl with
244251
| SynModuleDecl.NestedModule (moduleInfo = SynComponentInfo(longId = [ nestedModuleIdent ]); decls = decls) ->
245252
let name = nestedModuleIdent.idText
246-
let children = List.choose (mkTrieForSynModuleDecl fileIndex) decls
253+
254+
let children =
255+
List.choose (mkTrieForSynModuleDecl fileIndex) decls |> mkDictFromKeyValuePairs
247256

248257
Some(
249258
KeyValuePair(
250259
name,
251260
{
252261
Current = TrieNodeInfo.Module(name, fileIndex)
253-
Children = Dictionary(children)
262+
Children = children
254263
}
255264
)
256265
)
@@ -260,14 +269,17 @@ and mkTrieForSynModuleSigDecl (fileIndex: int) (decl: SynModuleSigDecl) : KeyVal
260269
match decl with
261270
| SynModuleSigDecl.NestedModule (moduleInfo = SynComponentInfo(longId = [ nestedModuleIdent ]); moduleDecls = decls) ->
262271
let name = nestedModuleIdent.idText
263-
let children = List.choose (mkTrieForSynModuleSigDecl fileIndex) decls
272+
273+
let children =
274+
List.choose (mkTrieForSynModuleSigDecl fileIndex) decls
275+
|> mkDictFromKeyValuePairs
264276

265277
Some(
266278
KeyValuePair(
267279
name,
268280
{
269281
Current = TrieNodeInfo.Module(name, fileIndex)
270-
Children = Dictionary(children)
282+
Children = children
271283
}
272284
)
273285
)

tests/ParallelTypeCheckingTests/Code/TypeCheckingGraphProcessing.fs renamed to src/Compiler/Driver/GraphChecking/TypeCheckingGraphProcessing.fs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// Parallel processing of graph of work items with dependencies
2-
module ParallelTypeCheckingTests.TypeCheckingGraphProcessing
2+
module FSharp.Compiler.GraphChecking.TypeCheckingGraphProcessing
33

4-
open ParallelTypeCheckingTests.GraphProcessing
4+
open GraphProcessing
55
open System.Collections.Generic
66
open System.Threading
77

@@ -11,6 +11,7 @@ open System.Threading
1111
/// <summary>
1212
/// Combine type-checking results of dependencies needed to type-check a 'higher' node in the graph
1313
/// </summary>
14+
/// <param name="emptyState">Initial state</param>
1415
/// <param name="deps">Direct dependencies of a node</param>
1516
/// <param name="transitiveDeps">Transitive dependencies of a node</param>
1617
/// <param name="folder">A way to fold a single result into existing state</param>
@@ -42,6 +43,7 @@ let private combineResults
4243
let set = HashSet(biggestDependency.Info.TransitiveDeps)
4344
set.Add biggestDependency.Info.Item |> ignore
4445
set
46+
4547
let resultsToAdd =
4648
transitiveDeps
4749
|> Array.filter (fun dep -> itemsPresent.Contains dep.Info.Item = false)
@@ -68,10 +70,7 @@ let processTypeCheckingGraph<'Item, 'ChosenItem, 'State, 'Result, 'FinalFileResu
6870
(ct: CancellationToken)
6971
: ('ChosenItem * 'FinalFileResult) list * 'State =
7072

71-
let workWrapper
72-
(getProcessedNode: 'Item -> ProcessedNode<'Item, 'State * 'Result>)
73-
(node: NodeInfo<'Item>)
74-
: 'State * 'Result =
73+
let workWrapper (getProcessedNode: 'Item -> ProcessedNode<'Item, 'State * 'Result>) (node: NodeInfo<'Item>) : 'State * 'Result =
7574
let folder x y = folder x y |> snd
7675
let deps = node.Deps |> Array.except [| node.Item |] |> Array.map getProcessedNode
7776

@@ -91,9 +90,8 @@ let processTypeCheckingGraph<'Item, 'ChosenItem, 'State, 'Result, 'FinalFileResu
9190
results
9291
|> Array.choose (fun (item, res) ->
9392
match finalStateChooser item with
94-
| Some item -> Some (item, res)
95-
| None -> None
96-
)
93+
| Some item -> Some(item, res)
94+
| None -> None)
9795
|> Array.fold
9896
(fun (fileResults, state) (item, (_, itemRes)) ->
9997
let fileResult, state = folder state itemRes

0 commit comments

Comments
 (0)