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
8 changes: 4 additions & 4 deletions src/QsCompiler/Core/ExpressionTransformation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type private ExpressionKind =
type ExpressionKindTransformationBase internal (options : TransformationOptions, _internal_) =

let missingTransformation name _ = new InvalidOperationException(sprintf "No %s transformation has been specified." name) |> raise
let Node = if options.DisableRebuild then Walk else Fold
let Node = if options.Rebuild then Fold else Walk

member val internal TypeTransformationHandle = missingTransformation "type" with get, set
member val internal ExpressionTransformationHandle = missingTransformation "expression" with get, set
Expand Down Expand Up @@ -280,7 +280,7 @@ type ExpressionKindTransformationBase internal (options : TransformationOptions,

abstract member OnExpressionKind : ExpressionKind -> ExpressionKind
default this.OnExpressionKind kind =
if options.Disable then kind else
if not options.Enable then kind else
let transformed = kind |> function
| Identifier (sym, tArgs) -> this.OnIdentifier (sym, tArgs)
| CallLikeExpression (method,arg) -> this.OnCallLikeExpression (method, arg)
Expand Down Expand Up @@ -333,7 +333,7 @@ type ExpressionKindTransformationBase internal (options : TransformationOptions,
and ExpressionTransformationBase internal (options : TransformationOptions, _internal_) =

let missingTransformation name _ = new InvalidOperationException(sprintf "No %s transformation has been specified." name) |> raise
let Node = if options.DisableRebuild then Walk else Fold
let Node = if options.Rebuild then Fold else Walk

member val internal TypeTransformationHandle = missingTransformation "type" with get, set
member val internal ExpressionKindTransformationHandle = missingTransformation "expression kind" with get, set
Expand Down Expand Up @@ -386,7 +386,7 @@ and ExpressionTransformationBase internal (options : TransformationOptions, _int

abstract member OnTypedExpression : TypedExpression -> TypedExpression
default this.OnTypedExpression (ex : TypedExpression) =
if options.Disable then ex else
if not options.Enable then ex else
let range = this.OnRangeInformation ex.Range
let typeParamResolutions = this.OnTypeParamResolutions ex.TypeParameterResolutions
let kind = this.ExpressionKinds.OnExpressionKind ex.Expression
Expand Down
6 changes: 3 additions & 3 deletions src/QsCompiler/Core/NamespaceTransformation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type QsArgumentTuple = QsTuple<LocalVariableDeclaration<QsLocalSymbol>>
type NamespaceTransformationBase internal (options : TransformationOptions, _internal_) =

let missingTransformation name _ = new InvalidOperationException(sprintf "No %s transformation has been specified." name) |> raise
let Node = if options.DisableRebuild then Walk else Fold
let Node = if options.Rebuild then Fold else Walk

member val internal StatementTransformationHandle = missingTransformation "statement" with get, set
member this.Statements = this.StatementTransformationHandle()
Expand Down Expand Up @@ -212,14 +212,14 @@ type NamespaceTransformationBase internal (options : TransformationOptions, _int

abstract member OnNamespaceElement : QsNamespaceElement -> QsNamespaceElement
default this.OnNamespaceElement element =
if options.Disable then element else
if not options.Enable then element else
match element with
| QsCustomType t -> t |> this.OnTypeDeclaration |> QsCustomType
| QsCallable c -> c |> this.OnCallableDeclaration |> QsCallable

abstract member OnNamespace : QsNamespace -> QsNamespace
default this.OnNamespace ns =
if options.Disable then ns else
if not options.Enable then ns else
let name = ns.Name
let doc = ns.Documentation.AsEnumerable().SelectMany(fun entry ->
entry |> Seq.map (fun doc -> entry.Key, this.OnDocumentation doc)).ToLookup(fst, snd)
Expand Down
10 changes: 5 additions & 5 deletions src/QsCompiler/Core/StatementTransformation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ open Microsoft.Quantum.QsCompiler.Transformations.Core.Utils
type StatementKindTransformationBase internal (options : TransformationOptions, _internal_) =

let missingTransformation name _ = new InvalidOperationException(sprintf "No %s transformation has been specified." name) |> raise
let Node = if options.DisableRebuild then Walk else Fold
let Node = if options.Rebuild then Fold else Walk

member val internal ExpressionTransformationHandle = missingTransformation "expression" with get, set
member val internal StatementTransformationHandle = missingTransformation "statement" with get, set
Expand Down Expand Up @@ -162,7 +162,7 @@ type StatementKindTransformationBase internal (options : TransformationOptions,

abstract member OnStatementKind : QsStatementKind -> QsStatementKind
default this.OnStatementKind kind =
if options.Disable then kind else
if not options.Enable then kind else
let transformed = kind |> function
| QsExpressionStatement ex -> this.OnExpressionStatement ex
| QsReturnStatement ex -> this.OnReturnStatement ex
Expand All @@ -182,7 +182,7 @@ type StatementKindTransformationBase internal (options : TransformationOptions,
and StatementTransformationBase internal (options : TransformationOptions, _internal_) =

let missingTransformation name _ = new InvalidOperationException(sprintf "No %s transformation has been specified." name) |> raise
let Node = if options.DisableRebuild then Walk else Fold
let Node = if options.Rebuild then Fold else Walk

member val internal ExpressionTransformationHandle = missingTransformation "expression" with get, set
member val internal StatementKindTransformationHandle = missingTransformation "statement kind" with get, set
Expand Down Expand Up @@ -229,7 +229,7 @@ and StatementTransformationBase internal (options : TransformationOptions, _inte

abstract member OnStatement : QsStatement -> QsStatement
default this.OnStatement stm =
if options.Disable then stm else
if not options.Enable then stm else
let location = this.OnLocation stm.Location
let comments = stm.Comments
let kind = this.StatementKinds.OnStatementKind stm.Statement
Expand All @@ -238,7 +238,7 @@ and StatementTransformationBase internal (options : TransformationOptions, _inte

abstract member OnScope : QsScope -> QsScope
default this.OnScope scope =
if options.Disable then scope else
if not options.Enable then scope else
let parentSymbols = this.OnLocalDeclarations scope.KnownSymbols
let statements = scope.Statements |> Seq.map this.OnStatement |> ImmutableArray.CreateRange
QsScope.New |> Node.BuildOr scope (statements, parentSymbols)
18 changes: 9 additions & 9 deletions src/QsCompiler/Core/TransformationOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,38 @@ namespace Microsoft.Quantum.QsCompiler.Transformations.Core


/// Used to configure the behavior of the default implementations for transformations.
type TransformationOptions = {
type TransformationOptions = internal {
/// Disables the transformation at the transformation root,
/// meaning the transformation won't recur into leaf nodes or subnodes.
Disable : bool
Enable : bool
/// Indicates that the transformation is used to walk the syntax tree, but does not modify any of the nodes.
/// If set to true, the nodes will not be rebuilt during the transformation.
/// Setting this to true constitutes a promise that the return value of all methods will be ignored.
DisableRebuild : bool
Rebuild : bool
}
with

/// Default transformation setting.
/// The transformation will recur into leaf and subnodes,
/// and all nodes will be rebuilt upon transformation.
static member Default = {
Disable = false
DisableRebuild = false
Enable = true
Rebuild = true
}

/// Disables the transformation at the transformation root,
/// meaning the transformation won't recur into leaf nodes or subnodes.
static member Disabled = {
Disable = true
DisableRebuild = false
Enable = false
Rebuild = true
}

/// Indicates that the transformation is used to walk the syntax tree, but does not modify any of the nodes.
/// All nodes will be traversed recursively, but the nodes will not be rebuilt.
/// Setting this option constitutes a promise that the return value of all methods will be ignored.
static member NoRebuild = {
Disable = false
DisableRebuild = true
Enable = true
Rebuild = false
}


Expand Down
4 changes: 2 additions & 2 deletions src/QsCompiler/Core/TypeTransformation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type private ExpressionType =

type TypeTransformationBase(options : TransformationOptions) =

let Node = if options.DisableRebuild then Walk else Fold
let Node = if options.Rebuild then Fold else Walk
new () = new TypeTransformationBase(TransformationOptions.Default)


Expand Down Expand Up @@ -112,7 +112,7 @@ type TypeTransformationBase(options : TransformationOptions) =
// transformation root called on each node

member this.OnType (t : ResolvedType) =
if options.Disable then t else
if not options.Enable then t else
let transformed = t.Resolution |> function
| ExpressionType.UnitType -> this.OnUnitType ()
| ExpressionType.Operation ((it, ot), fs) -> this.OnOperation ((it, ot), fs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Quantum.Simulators" Version="0.10.2002.2404-alpha" />
<PackageReference Include="Microsoft.Quantum.Simulators" Version="0.10.2002.2701-alpha" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.Quantum.Sdk/0.10.2002.2405-alpha">
<Project Sdk="Microsoft.Quantum.Sdk/0.10.2002.2705-alpha">

<PropertyGroup>
<QscVerbosity>Detailed</QscVerbosity>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Quantum.CsharpGeneration" Version="0.10.2002.2404-alpha" />
<PackageReference Include="Microsoft.Quantum.CsharpGeneration" Version="0.10.2002.2701-alpha" />
</ItemGroup>

</Project>
Expand Down