Skip to content

Commit

Permalink
FCS works.
Browse files Browse the repository at this point in the history
  • Loading branch information
safesparrow committed Nov 8, 2022
1 parent 9beca10 commit 783a253
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/Compiler/Driver/ParseAndCheckInputs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,7 @@ let CheckOneInputAux'

match inp with
| ParsedInput.SigFile file ->
printfn $"Processing Sig {file.FileName}"
// printfn $"Processing Sig {file.FileName}"
let qualNameOfFile = file.QualifiedName

// Check if we've seen this top module signature before.
Expand Down Expand Up @@ -1462,7 +1462,7 @@ let CheckOneInputAux'


// Save info needed for type-checking .fs file later on
printfn $"[{Thread.CurrentThread.ManagedThreadId}] Saving fsiBackedInfos for {file.FileName}"
// printfn $"[{Thread.CurrentThread.ManagedThreadId}] Saving fsiBackedInfos for {file.FileName}"
fsiBackedInfos[file.FileName] <- sigFileType

// printfn $"Finished Processing Sig {file.FileName}"
Expand Down
6 changes: 5 additions & 1 deletion tests/ParallelTypeCheckingTests/Code/ASTVisit.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,11 @@ module TopModulesExtraction =
// Stay safe and as soon as the parent module is reachable, consider this module reachable as well
[|LongIdent.Empty|]
else
[|longId|]
// 'module A.B' is equivalent to 'namespace A; module B', meaning that 'A' is opened implicitly
if synModuleOrNamespaceKind.IsModule then
[|longId.GetSlice(None, Some <| longId.Length-2); longId|]
else
[|longId|]
// TODO Temporarily disabled digging into the file's structure to avoid edge cases where another file depends on this file's namespace existing (but nothing else)
// synModuleDecls
// |> moduleDecls
Expand Down
13 changes: 13 additions & 0 deletions tests/ParallelTypeCheckingTests/Code/GraphProcessing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ let processGraph<'Item, 'State, 'Result, 'FinalFileResult when 'Item : equality
}
finalFileResult, state

printfn $"Node count: {nodes.Count}"
// let mutable cnt = 1

let work
(node : Node<'Item, StateWrapper<'Item, 'State>, ResultWrapper<'Item, 'Result>>)
: Node<'Item, StateWrapper<'Item, 'State>, ResultWrapper<'Item, 'Result>>[]
Expand Down Expand Up @@ -230,6 +233,16 @@ let processGraph<'Item, 'State, 'Result, 'FinalFileResult when 'Item : equality
)
pdc = x.Info.Deps.Length
)
// printfn $"State after {node.Info.Item}"
// nodes
// |> Seq.map (fun (KeyValue(_, v)) ->
// let x = v.Info.Deps.Length - v.ProcessedDepsCount
// $"{v.Info.Item} - {x} deps left"
// )
// |> Seq.iter (fun x -> printfn $"{x}")
// let c = cnt
// cnt <- cnt+1
// printfn $"Finished processing node. {unblocked.Length} nodes unblocked"
unblocked

use cts = new CancellationTokenSource()
Expand Down
6 changes: 3 additions & 3 deletions tests/ParallelTypeCheckingTests/Code/Parallel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,18 @@ let processInParallel
(parallelism : int)
(stop : int -> bool)
(ct : CancellationToken)
(itemToString)
(_itemToString)
: unit
=
let bc = new BlockingCollection<'Item>()
firstItems |> Array.iter bc.Add
let processedCountLock = Object()
let mutable processedCount = 0
let processItem item =
printfn $"Processing {itemToString item}"
// printfn $"Processing {itemToString item}"
let toSchedule = work item
let processedCount = lock processedCountLock (fun () -> processedCount <- processedCount + 1; processedCount)
printfn $"ToSchedule {toSchedule.Length}"
// printfn $"ToSchedule {toSchedule.Length}"
toSchedule
|> Array.iter (
fun next -> bc.Add(next)
Expand Down
18 changes: 11 additions & 7 deletions tests/ParallelTypeCheckingTests/Code/ParallelTypeChecking.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#nowarn "1182"
open System.Collections.Concurrent
open System.Collections.Generic
open System.Threading
open FSharp.Compiler
open FSharp.Compiler.CheckBasics
open FSharp.Compiler.CheckDeclarations
Expand Down Expand Up @@ -72,7 +73,7 @@ let CheckMultipleInputsInParallel
let mutable nextIdx = (graph.Files |> Array.map (fun f -> f.File.Idx.Idx) |> Array.max) + 1
let fakeX (idx : FileIdx) (fsi : File) : FileData =
{
File = File.FakeFs idx fsi.QualifiedName
File = File.FakeFs idx fsi.Name
Data =
{
Tops = [||]
Expand Down Expand Up @@ -131,6 +132,8 @@ let CheckMultipleInputsInParallel
// somewhere in the files processed prior to each one, or in the processing of this particular file.
let priorErrors = checkForErrors ()

let mutable cnt = 1

let processFile
(file : File)
((input, logger) : ParsedInput * DiagnosticsLogger)
Expand All @@ -143,10 +146,11 @@ let CheckMultipleInputsInParallel
let checkForErrors2 () = priorErrors || (logger.ErrorCount > 0)

let tcSink = TcResultsSink.NoSink

let c = cnt
cnt <- cnt + 1
match file.AST with
| ASTOrX.AST _ ->
// printfn $"Processing AST {file.ToString()}"
printfn $"#{c} [thread {Thread.CurrentThread.ManagedThreadId}] Type-checking {file.ToString()}"
let! f = CheckOneInput'(
checkForErrors2,
tcConfig,
Expand All @@ -159,7 +163,7 @@ let CheckMultipleInputsInParallel
false // skipImpFiles...
)

printfn $"Finished Processing AST {file.ToString()}"
// printfn $"Finished Processing AST {file.ToString()}"
return
(fun (state : State) ->
// printfn $"Applying {file.ToString()}"
Expand All @@ -174,7 +178,7 @@ let CheckMultipleInputsInParallel
partialResult, state
)
| ASTOrX.X fsi ->
// printfn $"Processing X {file.ToString()}"
// printfn $"[{c}] Processing X {file.ToString()}"

let hadSig = true
// Add dummy .fs results
Expand All @@ -188,7 +192,6 @@ let CheckMultipleInputsInParallel
// Don't use it for this file's type-checking - it will cause duplicates

let ccuSigForFile = fsiBackedInfos[fsi]
printfn $"Finished Processing X {file}"
return
(fun (state : State) ->
// (tcState.TcEnvFromImpls, EmptyTopAttrs, None, ccuSigForFile), state
Expand Down Expand Up @@ -236,14 +239,15 @@ let CheckMultipleInputsInParallel
let _qnof = QualifiedNameOfFile.QualifiedNameOfFile (Ident("", Range.Zero))
let state: State = tcState, priorErrors


let partialResults, (tcState, _) =
GraphProcessing.processGraph<File, State, SingleResult, FinalFileResult>
graph
processFile
folder
state
(fun it -> not <| it.Name.EndsWith(".fsix"))
8
10

partialResults |> Array.toList, tcState
)
2 changes: 1 addition & 1 deletion tests/ParallelTypeCheckingTests/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ let _parse (argv: string[]): Args =
[<EntryPoint>]
let main _argv =
let args = _parse _argv
let args = {args with LineLimit = Some 219}
let args = {args with LineLimit = None}
TestCompilationFromCmdlineArgs.TestCompilerFromArgs args
0
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Codebase =

let codebases =
[|
{ WorkDir = $@"{__SOURCE_DIRECTORY__}\.checkouts\fcs\src\compiler"; Path = $@"{__SOURCE_DIRECTORY__}\FCS.args.txt"; Limit = Some 237 }
{ WorkDir = $@"{__SOURCE_DIRECTORY__}\.checkouts\fcs\src\compiler"; Path = $@"{__SOURCE_DIRECTORY__}\FCS.args.txt"; Limit = Some 211 }
{ WorkDir = $@"{__SOURCE_DIRECTORY__}\.checkouts\fcs\tests\FSharp.Compiler.ComponentTests"; Path = $@"{__SOURCE_DIRECTORY__}\ComponentTests.args.txt"; Limit = None }
|]

Expand Down
19 changes: 19 additions & 0 deletions tests/ParallelTypeCheckingTests/Tests/TestDependencyResolution.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module ParallelTypeCheckingTests.TestDependencyResolution
#nowarn "1182"
open System.IO
open Buildalyzer
open ParallelTypeCheckingTests
open ParallelTypeCheckingTests.Types
Expand Down Expand Up @@ -116,6 +117,24 @@ type X = Y
assertGraphEqual deps expectedEdges


[<Test>]
let ``Test error``() =
let files =
[|
"pppars.fs", File.ReadAllText @"C:\projekty\fsharp\heuristic\tests\ParallelTypeCheckingTests\Tests\.checkouts\fcs\artifacts\obj\FSharp.Compiler.Service\Debug\netstandard2.0\pppars.fs"
"pplex.fs", File.ReadAllText @"C:\projekty\fsharp\heuristic\tests\ParallelTypeCheckingTests\Tests\.checkouts\fcs\artifacts\obj\FSharp.Compiler.Service\Debug\netstandard2.0\pplex.fs"
|]
|> buildFiles

let deps = DependencyResolution.detectFileDependencies files

let expectedEdges =
[
"pplex.fs", ["pppars.fs"]
]
assertGraphEqual deps expectedEdges


let sampleFiles =
[
"Abbr.fs", """
Expand Down

0 comments on commit 783a253

Please sign in to comment.