Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
safesparrow committed Oct 29, 2022
1 parent 2ec476d commit fd67ddb
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 439 deletions.
343 changes: 126 additions & 217 deletions tests/FSharp.Compiler.Service.Tests2/DepResolving.fs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@
<Link>Common.fs</Link>
</Compile>
<Compile Include="Utils.fs" />
<Compile Include="Types.fs" />
<Compile Include="ASTVisit.fs" />
<Compile Include="TestASTVisit.fs" />
<Compile Include="DepResolving.fs" />
<Compile Include="TestDepResolving.fs" />
<Compile Include="FileInfoGathering.fs" />
<Compile Include="Graph.fs" />
<Compile Include="RunCompiler.fs" />
<Compile Include="DepResolving.fs" />
<None Include="Big.fs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Compile Include="Types.fs" />
<Compile Include="Program.fs" />
<Compile Include="Parallel.fs" />
<Compile Include="GraphProcessing.fs" />
<Compile Include="FileInfoGathering.fs" />
<Compile Include="code2.fs" />
<Compile Include="ParallelTypeChecking.fs" />
<Content Include="Docs.md" />
<Compile Include="Tests\TestASTVisit.fs" />
<Compile Include="Tests\TestDepResolving.fs" />
<Compile Include="Tests\RunCompiler.fs" />
<Compile Include="Program.fs" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 5 additions & 1 deletion tests/FSharp.Compiler.Service.Tests2/FileInfoGathering.fs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ let private gatherBackingInfo (files : SourceFiles) : Files =

type ExtractedData =
{
ModuleRefs : LongIdent[]
/// Order of the file in the project. Files with lower number cannot depend on files with higher number
Tops : LongIdent[]
ContainsModuleAbbreviations : bool
/// All partial module references found in this file's AST
ModuleRefs : LongIdent[]
}

/// All the data about a single file needed for the dependency resolution algorithm
type FileData =
{
File : File
Data : ExtractedData
}
with member this.CodeSize = this.File.CodeSize

let private gatherFileData (file : File) : ExtractedData =
let moduleRefs, containsModuleAbbreviations = ASTVisit.findModuleRefs file.AST
Expand Down
8 changes: 5 additions & 3 deletions tests/FSharp.Compiler.Service.Tests2/GraphProcessing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ let combineResults
// TODO Could be replaced with a simpler recursive approach with memoised per-item results
let processGraph<'Item, 'State, 'Result when 'Item : equality>
(graph : Graph<'Item>)
(doWork : 'Item -> 'State -> 'State * 'Result)
(doWork : 'Item -> 'State -> 'Result)
(folder : 'State -> 'Result -> 'State)
(parallelism : int)
: 'State
Expand Down Expand Up @@ -109,8 +109,10 @@ let processGraph<'Item, 'State, 'Result when 'Item : equality>
let deps = lookupMany node.Info.Deps
let transitiveDeps = lookupMany node.Info.TransitiveDeps
let inputState = combineResults deps transitiveDeps folder
let res = doWork node.Info.Item inputState
node.Result <- Some res
let singleRes = doWork node.Info.Item inputState
let state = folder inputState singleRes
node.Result <- Some (state, singleRes)

// Need to double-check that only one dependency schedules this dependant
let unblocked =
node.Info.Dependants
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module FSharp.Compiler.Service.Tests.code
module FSharp.Compiler.Service.Tests.ParallelTypeChecking

open FSharp.Compiler.ParseAndCheckInputs
open FSharp.Compiler.Service.Tests.Graph
open FSharp.Compiler.Service.Tests.Types

Expand All @@ -9,27 +8,31 @@ type FileGraph = Graph<File>
let calcFileGraph (files : SourceFiles) : FileGraph =
failwith ""

// TODO Use real things
type State = string
type SingleResult = int

// TODO Use the real thing
let typeCheckFile (file : File) (state : State) : SingleResult
=
file.Idx.Idx

// TODO Use the real thing
let folder (state : string) (result : int) =
$"{state}+{result}"
$"{state}+{result}"

let typeCheckGraph (graph : FileGraph) : TcState =
// TODO We probably need to return partial results as well
let typeCheckGraph (graph : FileGraph) : State =
let parallelism = 4 // cpu count?
let state =
GraphProcessing.processGraph
graph
typeCheckFile
folder
parallelism
state
state

let typeCheck (files : SourceFiles) : TcState =
let typeCheck (files : SourceFiles) : State =
let graph = calcFileGraph files
let state = typeCheckGraph graph
state
199 changes: 0 additions & 199 deletions tests/FSharp.Compiler.Service.Tests2/RunCompiler.fs

This file was deleted.

57 changes: 57 additions & 0 deletions tests/FSharp.Compiler.Service.Tests2/Tests/RunCompiler.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module FSharp.Compiler.Service.Tests2.RunCompiler

open System
open System.Collections.Concurrent
open System.Collections.Generic
open System.Threading
open System.Threading.Tasks
open FSharp.Compiler.Service.Tests
open FSharp.Compiler.Service.Tests.Graph
open NUnit.Framework

[<Test>]
let runCompiler () =
let args =
System.IO.File.ReadAllLines(@"C:\projekty\fsharp\heuristic\tests\FSharp.Compiler.Service.Tests2\args.txt") |> Array.skip 1
FSharp.Compiler.CommandLineMain.main args |> ignore

[<Test>]
let runGrapher () =
// let args =
// System.IO.File.ReadAllLines(@"C:\projekty\fsharp\heuristic\tests\FSharp.Compiler.Service.Tests2\args.txt") |> Array.skip 1
// FSharp.Compiler.CommandLineMain.main args |> ignore

let deps : Graph<int> =
[|
0, [||] // A
1, [|0|] // B1 -> A
2, [|1|] // B2 -> B1
3, [|0|] // C1 -> A
4, [|3|] // C2 -> C1
5, [|2; 4|] // D -> B2, C2
|]
|> readOnlyDict

let dependants = deps |> Graph.reverse
let transitiveDeps = deps |> Graph.transitive
let transitiveDependants = transitiveDeps |> Graph.reverse

let nodes =
deps.Keys
|> Seq.map (fun idx -> idx, {Idx = idx; Deps = [||]; Dependants = [||]; TransitiveDeps = [||]; Result = None; UnprocessedDepsCount = 0; _lock = Object()})
|> readOnlyDict

let processs deps = deps |> Array.map (fun d -> nodes[d])

let graph =
nodes
|> Seq.iter (fun (KeyValue(idx, node)) ->
node.Deps <- processs deps[idx]
node.TransitiveDeps <- processs transitiveDeps[idx]
node.Dependants <- processs dependants[idx]
node.UnprocessedDepsCount <- node.Deps.Length
)
nodes.Values
|> Seq.toArray

GraphProcessing.processGraph graph

0 comments on commit fd67ddb

Please sign in to comment.