Ejemplo n.º 1
0
        public async Task TestSpec2SpecMapGeneratedByTypeChecker(SimpleGraph file2file)
        {
            var helper    = new WorkspaceEvaluationHelper(TestOutputDirectory, null, forTesting: true);
            var repo      = GenerateFullWorkspaceRepo(helper, file2file);
            var workspace = await helper.ParseAsync(repo);

            var semanticModel = helper.Typecheck(workspace);

            Func <int, AbsolutePath> specIdxToSpecPath = (specIdx) => SpecIdxToSpecPath(repo, specIdx);
            var relevantSpecPaths = file2file.Nodes.Select(specIdxToSpecPath).ToList();
            Func <RoaringBitSet, IEnumerable <AbsolutePath> > materializeRelevant = (bitSet) =>
            {
                bitSet.MaterializeSetIfNeeded(string.Empty, (s, i) => workspace.GetAllSourceFiles()[i].GetAbsolutePath(helper.PathTable));
                return(bitSet.MaterializedSetOfPaths.Intersect(relevantSpecPaths));
            };

            // test the spec2spec map generated by TypeChecker
            XAssert.All(
                file2file.Nodes,
                specIdx =>
            {
                var specSourceFile       = workspace.GetSourceFile(SpecIdxToSpecPath(repo, specIdx));
                var computedDependencies = materializeRelevant(semanticModel.GetFileDependenciesOf(specSourceFile));
                var computedDependents   = materializeRelevant(semanticModel.GetFileDependentFilesOf(specSourceFile));
                var expectedDependents   = file2file.OutgoingEdges(specIdx).Select(e => specIdxToSpecPath(e.Dest));
                var expectedDependencies = file2file.IncomingEdges(specIdx).Select(e => specIdxToSpecPath(e.Src));

                XAssert.SetEqual(expectedDependencies, computedDependents);
                XAssert.SetEqual(expectedDependents, computedDependencies);
            });
        }
Ejemplo n.º 2
0
        private async Task DoPartialEvalTest(SimpleGraph file2file, int[] changed,
                                             int[] expectedDownstream, int[] expectedUpstream, int[] expectedIndirectUpstream, int[] expectedAffected)
        {
            ComputeAndCheckSpecStates(file2file, changed, expectedDownstream, expectedUpstream, expectedIndirectUpstream, expectedAffected);

            // helpers
            var helper = new WorkspaceEvaluationHelper(TestOutputDirectory, null, forTesting: true);
            var repo   = GenerateFullWorkspaceRepo(helper, file2file);
            Func <int, AbsolutePath> specIdxToSpecPath = (specIdx) => SpecIdxToSpecPath(repo, specIdx);

            // create workspace and semantic model
            var workspace = await helper.ParseAsync(repo);

            var semanticModel = helper.Typecheck(workspace);

            var changedWithDownstream      = changed.Union(expectedDownstream).ToArray();
            var changedWithDownstreamPaths = changedWithDownstream.Select(specIdxToSpecPath).ToArray();

            // test workspace 'closure of dependent files' computation
            var specDepProvider       = new WorkspaceBasedSpecDependencyProvider(workspace, helper.PathTable);
            var dependentPathsClosure = specDepProvider.ComputeReflectiveClosureOfDependentFiles(changed.Select(specIdxToSpecPath));

            XAssert.SetEqual(changedWithDownstreamPaths.ToStrings(helper.PathTable), dependentPathsClosure.ToStrings(helper.PathTable));

            // test workspace 'closure of dependency files' computation
            var dependencyPathsClosure = specDepProvider
                                         .ComputeReflectiveClosureOfDependencyFiles(changedWithDownstreamPaths)
                                         .Intersect(file2file.Nodes.Select(specIdxToSpecPath)); // this leaves only spec files from TestModule, i.e., filters out prelude files etc.
            var expectedAffectedPaths = expectedAffected.Select(specIdxToSpecPath);

            XAssert.SetEqual(expectedAffectedPaths.ToStrings(helper.PathTable), dependencyPathsClosure.ToStrings(helper.PathTable));

            // full evaluation
            var interpreter = await helper.ConvertAsync(workspace, oldPipGraph : null);

            var pipGraph = await helper.EvaluateAsync(workspace, interpreter);

            AssertPipGraphContent(pipGraph, file2file, helper.StringTable);

            // partial evaluation
            var helper2     = new WorkspaceEvaluationHelper(TestOutputDirectory, helper.FrontEndContext, forTesting: true);
            var partialRepo = GenerateWorkspaceRepo(helper2, file2file, expectedAffected);
            var pipGraph2   = await helper2.EvaluateWithGraphPatchingAsync(
                repo : partialRepo,
                oldPipGraph : pipGraph,
                changedSpecs : changedWithDownstreamPaths,
                specsToIgnore : expectedUpstream.Union(expectedIndirectUpstream).Select(specIdxToSpecPath));

            // assert we still get the full graph
            AssertPipGraphContent(pipGraph2, file2file, helper2.StringTable);
        }