public ThreeFiles(PathTable pathTable, ITypeChecker checker, [NotNull] ISourceFile spec1, [NotNull] ISourceFile spec2, [CanBeNull] ISourceFile spec3, ISourceFile[] files) : this() { Spec1 = new AnalyzedSourceFile(checker, spec1, files, pathTable); Spec2 = new AnalyzedSourceFile(checker, spec2, files, pathTable); if (spec3 != null) { Spec3 = new AnalyzedSourceFile(checker, spec3, files, pathTable); } }
public void TestBigGraphWithConcurrentTypeChecking() { var random = new Random(); // create a random big graph representing spec dependencies var numNodes = 500; var dependencyGraph = CreateRandomBigGraph(random, numNodes); // construct spec files according to generated spec dependencies var specs = dependencyGraph .Nodes .Select(i => GenerateSpecContent(i, dependencyGraph)) .ToList(); var randomSpecIdx = random.Next(dependencyGraph.NodeCount); var expectedDownstream = dependencyGraph.OutgoingEdges(randomSpecIdx).Select(e => AbsolutePath.Create(m_pathTable, GetSpecName(e.Dest))); var expectedUpstream = dependencyGraph.IncomingEdges(randomSpecIdx).Select(e => AbsolutePath.Create(m_pathTable, GetSpecName(e.Src))); // create a checker and add generated files to it var checker = dependencyGraph.Nodes.Aggregate( CheckerWithPrelude(), (checkerAcc, specIdx) => checkerAcc.AddSourceFileToDefaultModule(sourceFileContent: specs[specIdx], fileName: GetSpecName(specIdx))); // type check var diagnostics = checker.RunChecker(trackFileToFileDependencies: true, degreeOfParallelism: Math.Max(Environment.ProcessorCount, 5)); XAssert.AreEqual(0, diagnostics.Count, "Expected 0 diagnostics, got: " + string.Join(Environment.NewLine, diagnostics.Select(d => d.ToString()))); // get computed dependencies var sourceFile = checker.GetSourceFile(GetSpecName(randomSpecIdx)); var asf = new AnalyzedSourceFile(checker.TypeChecker, sourceFile, checker.GetSourceFiles(), m_pathTable); var downstream = asf.DownStreamDependencies; var upstream = asf.UpStreamDependencies; // assert computed dependencies are correct var messageFormat = "Dependencies do not match: node count = {0}; chosen node = {1}; graph = {2}"; var args = new object[] { numNodes, randomSpecIdx, dependencyGraph }; XAssert.AreSetsEqual(expectedDownstream, downstream, true, format: messageFormat, args: args); XAssert.AreSetsEqual(expectedUpstream, upstream, true, format: messageFormat, args: args); }
public static bool HasDependency(this AnalyzedSourceFile file, AbsolutePath dependencyCandidate) { return(file.DownStreamDependencies.Contains(dependencyCandidate)); }
public static bool DependsOn(this AnalyzedSourceFile file, AbsolutePath dependsOnCandidate) { return(file.UpStreamDependencies.Contains(dependsOnCandidate)); }