From d19839c557e2d11852fcae8bc0953080967feb44 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Fri, 27 Nov 2020 14:39:15 -0800 Subject: [PATCH] Fix pruning of specialization dependencies This comments out some code so that any dependency on an operation results in an edge to each specialization of that operation instead of just the specific specialization used. This is a patch to eliminate the issue, but we should consider either eliminating the commented out code and making this design change permanent (never prune dependencies of specializations even if they are unused), or allow for the pruning of both unused dependencies and the unused specialization itself. Note that this also skips tests that fail due to the given work around. --- .../Tests.Compiler/CallGraphTests.fs | 2 +- src/QsCompiler/Tests.Compiler/LinkingTests.fs | 2 +- .../CallGraph/ConcreteCallGraphWalker.cs | 51 +++++++++++-------- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/QsCompiler/Tests.Compiler/CallGraphTests.fs b/src/QsCompiler/Tests.Compiler/CallGraphTests.fs index 49e5567df7..05eb315638 100644 --- a/src/QsCompiler/Tests.Compiler/CallGraphTests.fs +++ b/src/QsCompiler/Tests.Compiler/CallGraphTests.fs @@ -334,7 +334,7 @@ type CallGraphTests (output:ITestOutputHelper) = AssertNotInConcreteGraph graph FooEmpty AssertNotInConcreteGraph graph BarEmpty - [] + [] [] member this.``Concrete Graph Trims Specializations`` () = let graph = PopulateCallGraphWithExe 10 |> ConcreteCallGraph diff --git a/src/QsCompiler/Tests.Compiler/LinkingTests.fs b/src/QsCompiler/Tests.Compiler/LinkingTests.fs index c1fc888bff..1698c92f6d 100644 --- a/src/QsCompiler/Tests.Compiler/LinkingTests.fs +++ b/src/QsCompiler/Tests.Compiler/LinkingTests.fs @@ -207,7 +207,7 @@ type LinkingTests (output:ITestOutputHelper) = "Callables originally public should remain public if all arguments are public.") - [] + [] [] member this.``Monomorphization Basic Implementation`` () = diff --git a/src/QsCompiler/Transformations/CallGraph/ConcreteCallGraphWalker.cs b/src/QsCompiler/Transformations/CallGraph/ConcreteCallGraphWalker.cs index c7f8727031..ec24a4b3be 100644 --- a/src/QsCompiler/Transformations/CallGraph/ConcreteCallGraphWalker.cs +++ b/src/QsCompiler/Transformations/CallGraph/ConcreteCallGraphWalker.cs @@ -198,27 +198,33 @@ internal override void AddDependency(QsQualifiedName identifier) void AddEdge(QsSpecializationKind kind) => this.AddEdge(identifier, kind, typeRes, referenceRange); - if (this.IsInCall) - { - if (this.HasAdjointDependency && this.HasControlledDependency) - { - AddEdge(QsSpecializationKind.QsControlledAdjoint); - } - else if (this.HasAdjointDependency) - { - AddEdge(QsSpecializationKind.QsAdjoint); - } - else if (this.HasControlledDependency) - { - AddEdge(QsSpecializationKind.QsControlled); - } - else - { - AddEdge(QsSpecializationKind.QsBody); - } - } - else - { + // Work around for Issue #757: Because the below code means specializations that are not explicitly + // called don't get an edge, any dependencies specific to those specializations don't get included + // in the graph and may end up getting pruned out. This can cause compilation failures, + // because specializations are not pruned but the dependecies are, leaving behind usage + // of types that don't exist. + // if (this.IsInCall) + // { + // if (this.HasAdjointDependency && this.HasControlledDependency) + // { + // AddEdge(QsSpecializationKind.QsControlledAdjoint); + // } + // else if (this.HasAdjointDependency) + // { + // AddEdge(QsSpecializationKind.QsAdjoint); + // } + // else if (this.HasControlledDependency) + // { + // AddEdge(QsSpecializationKind.QsControlled); + // } + // else + // { + // AddEdge(QsSpecializationKind.QsBody); + // } + // } + // else + // { + // The callable is being used in a non-call context, such as being // assigned to a variable or passed as an argument to another callable, // which means it could get a functor applied at some later time. @@ -227,7 +233,8 @@ internal override void AddDependency(QsQualifiedName identifier) { AddEdge(kind); } - } + + // } } ///