Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class SyntaxTreeTrimming : IRewriteStep
public bool ImplementsPostconditionVerification => false;

/// <summary>
/// Constructor for the SyntaxTreeTrimming Rewrite Step.
/// Initializes a new instance of the <see cref="SyntaxTreeTrimming"/> class.
/// </summary>
/// <param name="keepAllIntrinsics">When true, intrinsics will not be removed as part of the rewrite step.</param>
public SyntaxTreeTrimming(bool keepAllIntrinsics = true, IEnumerable<QsQualifiedName>? dependencies = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,17 @@

namespace Microsoft.Quantum.QsCompiler.Transformations.Monomorphization.Validation
{
/// <summary>
/// Validates that the monomorphization transformation has removed all references to
/// generic objects.
/// </summary>
public class ValidateMonomorphization : SyntaxTreeTransformation<ValidateMonomorphization.TransformationState>
{
/// <summary>
/// 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.
/// </summary>
public static void Apply(QsCompilation compilation, bool allowTypeParametersForIntrinsics = true)
{
var intrinsicCallableSet = allowTypeParametersForIntrinsics
Expand Down
15 changes: 15 additions & 0 deletions src/QsCompiler/Transformations/SyntaxTreeTrimming.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,20 @@

namespace Microsoft.Quantum.QsCompiler.Transformations.SyntaxTreeTrimming
{
/// <summary>
/// Removes unused callables from the syntax tree.
/// </summary>
public static class TrimSyntaxTree
{
/// <summary>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth calling out what happens to types and type constructors. (I think the types may be preserved but the type constructors are subject to the same trimming rules as other callables?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking for that. I thought we had updated the code to prevent type constructors from being removed at some point. Do you remember?

/// 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 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. Note that unused type constructors will be subject to
/// trimming as any other callable.
/// </summary>
public static QsCompilation Apply(QsCompilation compilation, bool keepAllIntrinsics, IEnumerable<QsQualifiedName>? dependencies = null)
{
return TrimTree.Apply(compilation, keepAllIntrinsics, dependencies);
Expand Down Expand Up @@ -68,6 +80,9 @@ private static bool Filter(QsNamespaceElement elem, ImmutableHashSet<QsQualified
}
}

/// <summary>
/// Class representing the state of the transformation.
/// </summary>
public class TransformationState
{
public Func<QsNamespaceElement, bool> NamespaceElementFilter { get; }
Expand Down