From f6cc1f55e0c09ad7ebea09694d787fd9ce3ea926 Mon Sep 17 00:00:00 2001 From: Scott Carda Date: Tue, 15 Jun 2021 11:13:34 -0700 Subject: [PATCH 1/3] Added doc to TrimSyntaxTree transformation --- .../Compiler/RewriteSteps/SyntaxTreeTrimming.cs | 2 +- .../Transformations/SyntaxTreeTrimming.cs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/QsCompiler/Compiler/RewriteSteps/SyntaxTreeTrimming.cs b/src/QsCompiler/Compiler/RewriteSteps/SyntaxTreeTrimming.cs index 34100e4e47..bd9529099b 100644 --- a/src/QsCompiler/Compiler/RewriteSteps/SyntaxTreeTrimming.cs +++ b/src/QsCompiler/Compiler/RewriteSteps/SyntaxTreeTrimming.cs @@ -31,7 +31,7 @@ internal class SyntaxTreeTrimming : IRewriteStep public bool ImplementsPostconditionVerification => false; /// - /// Constructor for the SyntaxTreeTrimming Rewrite Step. + /// Initializes a new instance of the class. /// /// When true, intrinsics will not be removed as part of the rewrite step. public SyntaxTreeTrimming(bool keepAllIntrinsics = true, IEnumerable? dependencies = null) diff --git a/src/QsCompiler/Transformations/SyntaxTreeTrimming.cs b/src/QsCompiler/Transformations/SyntaxTreeTrimming.cs index d2eff5d6c0..5176773d8c 100644 --- a/src/QsCompiler/Transformations/SyntaxTreeTrimming.cs +++ b/src/QsCompiler/Transformations/SyntaxTreeTrimming.cs @@ -11,8 +11,19 @@ namespace Microsoft.Quantum.QsCompiler.Transformations.SyntaxTreeTrimming { + /// + /// Removes unused callables from the syntax tree. + /// public static class TrimSyntaxTree { + /// + /// Applies the transformation that removes from the syntax tree all callables that + /// are unused, meaning they are not a descendant of at least one entry point in + /// the call graph. If keepAllIntrinsics is true, callables with a body intrinsic + /// will not be trimmed, regardless of usage. Any callables that later + /// transformations will depend on should be passed in and will not be trimmed, + /// regardless of usage. + /// public static QsCompilation Apply(QsCompilation compilation, bool keepAllIntrinsics, IEnumerable? dependencies = null) { return TrimTree.Apply(compilation, keepAllIntrinsics, dependencies); @@ -68,6 +79,9 @@ private static bool Filter(QsNamespaceElement elem, ImmutableHashSet + /// Class representing the state of the transformation. + /// public class TransformationState { public Func NamespaceElementFilter { get; } From 149e6b3ab6cc11dd8ec8d7693c5efb7b2c628e83 Mon Sep 17 00:00:00 2001 From: Scott Carda Date: Tue, 15 Jun 2021 11:19:58 -0700 Subject: [PATCH 2/3] Doc for ValidateMonomorphization --- .../Transformations/MonomorphizationValidation.cs | 9 +++++++++ src/QsCompiler/Transformations/SyntaxTreeTrimming.cs | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/QsCompiler/Transformations/MonomorphizationValidation.cs b/src/QsCompiler/Transformations/MonomorphizationValidation.cs index deb45147ac..07f1e5fb40 100644 --- a/src/QsCompiler/Transformations/MonomorphizationValidation.cs +++ b/src/QsCompiler/Transformations/MonomorphizationValidation.cs @@ -10,8 +10,17 @@ namespace Microsoft.Quantum.QsCompiler.Transformations.Monomorphization.Validation { + /// + /// Validates that the monomorphization transformation has removed all references to + /// generic objects. + /// public class ValidateMonomorphization : SyntaxTreeTransformation { + /// + /// Applies the transformation that walks through the syntax tree, checking to ensure + /// that all generic data has been removed. If allowTypeParametersForIntrinsics is true, + /// then generic data is allowed for type parameters of callables that have an intrinsic body. + /// public static void Apply(QsCompilation compilation, bool allowTypeParametersForIntrinsics = true) { var intrinsicCallableSet = allowTypeParametersForIntrinsics diff --git a/src/QsCompiler/Transformations/SyntaxTreeTrimming.cs b/src/QsCompiler/Transformations/SyntaxTreeTrimming.cs index 5176773d8c..ceddd68c7b 100644 --- a/src/QsCompiler/Transformations/SyntaxTreeTrimming.cs +++ b/src/QsCompiler/Transformations/SyntaxTreeTrimming.cs @@ -19,7 +19,7 @@ public static class TrimSyntaxTree /// /// Applies the transformation that removes from the syntax tree all callables that /// are unused, meaning they are not a descendant of at least one entry point in - /// the call graph. If keepAllIntrinsics is true, callables with a body intrinsic + /// the call graph. If keepAllIntrinsics is true, callables with an intrinsic body /// will not be trimmed, regardless of usage. Any callables that later /// transformations will depend on should be passed in and will not be trimmed, /// regardless of usage. From 50b671e697e9100f96aace887aedc66cb61d18e2 Mon Sep 17 00:00:00 2001 From: Scott Carda Date: Tue, 15 Jun 2021 11:43:43 -0700 Subject: [PATCH 3/3] added note about type constructors --- src/QsCompiler/Transformations/SyntaxTreeTrimming.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/QsCompiler/Transformations/SyntaxTreeTrimming.cs b/src/QsCompiler/Transformations/SyntaxTreeTrimming.cs index ceddd68c7b..09fb31fce9 100644 --- a/src/QsCompiler/Transformations/SyntaxTreeTrimming.cs +++ b/src/QsCompiler/Transformations/SyntaxTreeTrimming.cs @@ -22,7 +22,8 @@ public static class TrimSyntaxTree /// the call graph. If keepAllIntrinsics is true, callables with an intrinsic body /// will not be trimmed, regardless of usage. Any callables that later /// transformations will depend on should be passed in and will not be trimmed, - /// regardless of usage. + /// regardless of usage. Note that unused type constructors will be subject to + /// trimming as any other callable. /// public static QsCompilation Apply(QsCompilation compilation, bool keepAllIntrinsics, IEnumerable? dependencies = null) {