Skip to content

Commit 87725ff

Browse files
committed
Try out the new approach on Fantomas.Core.Tests.
1 parent d320c81 commit 87725ff

File tree

6 files changed

+19
-29
lines changed

6 files changed

+19
-29
lines changed

tests/ParallelTypeCheckingTests/Code/TrieApproach/AutoOpenDetection.fs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,14 @@ let hasAutoOpenAttributeInFile (ast: ParsedInput) : bool =
5959
// ==============================================================================================================================
6060
// ==============================================================================================================================
6161

62+
open System.IO
6263
open NUnit.Framework
6364
open FSharp.Compiler.Service.Tests.Common
6465

6566
[<Test>]
6667
let ``detect auto open`` () =
6768
let file =
68-
@"C:\Users\nojaf\Projects\safesparrow-fsharp\src\Compiler\Utilities\ImmutableArray.fsi"
69+
Path.Combine(__SOURCE_DIRECTORY__, "..", "..", "..", "..", "src", "Compiler", "Utilities", "ImmutableArray.fsi")
6970

70-
let ast = parseSourceCode (file, System.IO.File.ReadAllText(file))
71+
let ast = parseSourceCode (file, File.ReadAllText(file))
7172
Assert.True(hasAutoOpenAttributeInFile ast)

tests/ParallelTypeCheckingTests/Code/TrieApproach/DependencyResolution.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ let time msg f a =
124124
result
125125

126126
let mkGraph (files: FileWithAST array) =
127+
// Implementation files backed by signatures should be excluded to construct the trie.
127128
let trieInput =
128129
files
129130
|> Array.filter (fun f ->
@@ -150,11 +151,13 @@ let mkGraph (files: FileWithAST array) =
150151
let fileContent = fileContents.[file.Idx]
151152
let knownFiles = getFileNameBefore files file.Idx
152153

154+
// Process all entries of a file and query the trie when required to find the dependent files.
153155
let result =
154156
Seq.fold (processStateEntry queryTrie) (FileContentQueryState.Create file.Idx knownFiles) fileContent
155157

156158
let allDependencies =
157159
if filesWithAutoOpen.Length > 0 then
160+
// Automatically add all files that came before the current file that use the [<AutoOpen>] attribute.
158161
let autoOpenDependencies =
159162
set ([| 0 .. (file.Idx - 1) |].Intersect(filesWithAutoOpen))
160163

tests/ParallelTypeCheckingTests/Code/TrieApproach/SampleData.fs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ open System.Collections.Generic
44
open NUnit.Framework
55
open ParallelTypeCheckingTests.Code.TrieApproach.DependencyResolution
66

7+
// This file contains some hard coded data to easily debug the various aspects of the dependency resolution.
8+
79
// Some helper DSL functions to construct the FileContentEntry items
810
// This should again be mapped from the AST
911

@@ -30,8 +32,7 @@ let prefIdent (lid: string) =
3032
let parts = lid.Split(".")
3133
Array.take (parts.Length - 1) parts |> List.ofArray |> PrefixedIdentifier
3234

33-
// Some hardcoded files processing, this was done by the naked eye and some regexes.
34-
35+
// Some hardcoded files that reflect the file content of the first files in the Fantomas.Core project.
3536
let files =
3637
[|
3738
{
@@ -615,7 +616,7 @@ let emptyHS () = HashSet(0)
615616
let indexOf name =
616617
Array.find (fun (fc: FileContent) -> fc.Name = name) files |> fun fc -> fc.Idx
617618

618-
// This should be constructed from the AST
619+
// This should be constructed from the AST, again a hard coded subset of Fantomas.Core
619620
let fantomasCoreTrie: TrieNode =
620621
{
621622
Current = TrieNodeInfo.Root
@@ -797,15 +798,3 @@ let ``ProcessOpenStatement full path match`` () =
797798

798799
let dep = Seq.exactlyOne result.FoundDependencies
799800
Assert.AreEqual(indexOf "AstExtensions.fsi", dep)
800-
801-
#if INTERACTIVE
802-
open System.Text.RegularExpressions
803-
804-
let fileContent =
805-
System.IO.File.ReadAllText(@"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\SourceParser.fs")
806-
807-
Regex.Matches(fileContent, "(\\w)+(\\.(\\w)+)+")
808-
|> Seq.cast<Match>
809-
|> Seq.distinctBy (fun m -> m.Value)
810-
|> Seq.iter (fun m -> printfn "prefIdent \"%s\"" m.Value)
811-
#endif

tests/ParallelTypeCheckingTests/Code/TrieApproach/TrieMapping.fs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,30 +228,23 @@ let ``Fantomas Core trie`` () =
228228
@"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\ISourceTextExtensions.fs"
229229
@"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\RangeHelpers.fs"
230230
@"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\AstExtensions.fsi"
231-
// @"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\AstExtensions.fs"
232231
@"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\TriviaTypes.fs"
233232
@"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\Utils.fs"
234233
@"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\SourceParser.fs"
235234
@"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\AstTransformer.fsi"
236-
// @"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\AstTransformer.fs"
237235
@"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\Version.fs"
238236
@"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\Queue.fs"
239237
@"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\FormatConfig.fs"
240238
@"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\Defines.fsi"
241-
// @"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\Defines.fs"
242239
@"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\Trivia.fsi"
243240
@"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\Trivia.fs"
244241
@"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\SourceTransformer.fs"
245242
@"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\Context.fs"
246243
@"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\CodePrinter.fsi"
247-
// @"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\CodePrinter.fs"
248244
@"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\CodeFormatterImpl.fsi"
249-
// @"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\CodeFormatterImpl.fs"
250245
@"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\Validation.fs"
251246
@"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\Selection.fsi"
252-
// @"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\Selection.fs"
253247
@"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\CodeFormatter.fsi"
254-
// @"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\CodeFormatter.fs"
255248
|]
256249
|> Array.mapi (fun idx file ->
257250
let ast = parseSourceCode (file, System.IO.File.ReadAllText(file))

tests/ParallelTypeCheckingTests/Code/TrieApproach/Types.fs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ open System.Collections.Generic
44
open FSharp.Compiler.Syntax
55

66
type File = string
7-
type Files = Set<File>
87
type ModuleSegment = string
98

109
type FileWithAST =

tests/ParallelTypeCheckingTests/Tests/TypedTreeGraph.fs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,19 @@ let codebases =
2121
WorkDir = $@"{__SOURCE_DIRECTORY__}\.fcs_test\src\compiler"
2222
Path = $@"{__SOURCE_DIRECTORY__}\FCS.args.txt"
2323
}
24-
// {
25-
// WorkDir = $@"{__SOURCE_DIRECTORY__}\.fcs_test\tests\FSharp.Compiler.ComponentTests"
26-
// Path = $@"{__SOURCE_DIRECTORY__}\ComponentTests.args.txt"
27-
// }
24+
{
25+
WorkDir = $@"{__SOURCE_DIRECTORY__}\.fcs_test\tests\FSharp.Compiler.ComponentTests"
26+
Path = $@"{__SOURCE_DIRECTORY__}\ComponentTests.args.txt"
27+
}
2828
// Hard coded example ;)
2929
{
3030
WorkDir = @"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core"
3131
Path = @"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core\args.txt"
3232
}
33+
{
34+
WorkDir = @"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core.Tests"
35+
Path = @"C:\Users\nojaf\Projects\main-fantomas\src\Fantomas.Core.Tests\args.txt"
36+
}
3337
|]
3438

3539
let checker = FSharpChecker.Create(keepAssemblyContents = true)
@@ -227,6 +231,7 @@ let ``Create Graph from typed tree`` (code: Codebase) =
227231
let typedTreeMap = collectAllDeps graphFromTypedTree
228232
let heuristicMap = collectAllDeps graphFromHeuristic.Graph
229233

234+
/// Compare the found dependencies of a specified heuristic versus the dependencies found in the typed tree
230235
let compareDeps source fileName idx (depsFromHeuristic: Set<int>) =
231236
let depsFromTypedTree = Map.find idx typedTreeMap
232237

0 commit comments

Comments
 (0)