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
Show all changes
126 commits
Select commit Hold shift + click to select a range
12dc61b
individual classes wtih each a handle back to the parent
Feb 11, 2020
becdd9f
... to be simplified
Feb 11, 2020
012db79
going with a simplified setup
Feb 11, 2020
b7cc7fd
this should be the most straightforward setup and hopefully work...
Feb 11, 2020
966377a
inheriting from the already defined classes
Feb 11, 2020
b4bb9db
some renaming
Feb 11, 2020
554bbfb
wip
Feb 11, 2020
fba4cc7
yuk - so much for making it nice and clean...
Feb 11, 2020
892a86d
now that actually works
Feb 11, 2020
b8423bc
some renaming
Feb 11, 2020
8300921
almost done with #2
Feb 11, 2020
3e9b963
... concluding that it makes sense to allow for a parameter less cons…
Feb 11, 2020
843ebeb
minor constructor changes
Feb 11, 2020
597c9f7
adding constructors that allow to construct subtransformations on the…
Feb 11, 2020
65aa8d6
second transformation done
Feb 11, 2020
866c195
wip
Feb 11, 2020
d435a7a
more wip
Feb 12, 2020
d027df0
...wip
Feb 12, 2020
6ce2d66
all search and replace transformations are migrated - need to double …
Feb 12, 2020
10eef67
found the issue - looks ok so far
Feb 12, 2020
30e4efd
updated two of the BasicTransformations
Feb 12, 2020
235e631
functor generation, first half
Feb 12, 2020
53991b5
wip
Feb 13, 2020
b343a9b
that should be ok in terms of the SelectByFoldingOverExpressions tran…
Feb 13, 2020
ceb48ac
allowing to parameterize the StatementTransformation within SelectByF…
Feb 13, 2020
6adedde
... and now this is a stackoverflow
Feb 13, 2020
e2d3427
... fixing the stackoverflow - still need to check correctness
Feb 13, 2020
2a26252
some clean-up
Feb 13, 2020
5f84795
Merge branch 'features/transformationSetup' into beheim/transformatio…
Feb 13, 2020
253ada4
whitespace
Feb 13, 2020
b70ab90
migrated the conjugations
Feb 13, 2020
f90ff17
wip
Feb 13, 2020
70ce747
migrated the type transformation
Feb 13, 2020
84a2945
expressions
Feb 13, 2020
3013af4
that should take care of the statement transformation
Feb 13, 2020
4e6dcd1
starting on the namespace transformation
Feb 13, 2020
0cfa8d0
wip
Feb 13, 2020
907c825
almost there
Feb 14, 2020
96e8b7c
now I just need to take case of the tests
Feb 14, 2020
cc6f2ee
... and the tests work again
Feb 14, 2020
2215708
making sure we get the right diff
Feb 14, 2020
3201b1e
doc comment
Feb 14, 2020
0594281
Merge branch 'beheim/codeOutput' into beheim/transformations
Feb 14, 2020
d93913b
renaming the type transformation
Feb 14, 2020
d53d474
migrated the StripRangeInfo transformation
Feb 14, 2020
df9203a
... let's see if that can be cleaner
Feb 14, 2020
a3dc6f3
wip
Feb 14, 2020
d6ba14b
more wip
Feb 14, 2020
103d7d1
... unfortunatly doesn't seem to be happy
Feb 15, 2020
d935b7e
removing the let static
Feb 15, 2020
a7234c5
the migration of StripPositionInfo is the problem ...
Feb 15, 2020
371a030
well, that works ...
Feb 15, 2020
97728ae
removing the virtual members
Feb 15, 2020
5d1b649
reverting 2215708814d003f112c8e65843c043a43800717a
Feb 15, 2020
65af81d
... and updating new code
Feb 15, 2020
ef3fe35
cleaned up expression transformation
Feb 15, 2020
92d90a4
adapting the statement and namespace transformation to follow the sam…
Feb 15, 2020
5e7bc79
migrated DistinctQubits
Feb 15, 2020
6a6fa1b
migrated MutationChecker
Feb 15, 2020
5bd316f
reference counter
Feb 15, 2020
ccc94d7
migrated ReplaceTypeParams
Feb 15, 2020
5d63479
migrated the side effect checker
Feb 15, 2020
b52bfc7
migrated the OptimizingTransformation
Feb 15, 2020
7c1c2aa
migrated VariableRenaming
Feb 16, 2020
28ea13b
no need to define a transformation state in F# (we can just keep it i…
Feb 16, 2020
3c01758
migrated the evaluation
Feb 16, 2020
e58ebe0
migrated VariableRemoving
Feb 16, 2020
b58fd21
migrated StatementRemoval
Feb 16, 2020
bad936a
... need to go over the code to make sure new transformations are con…
Feb 16, 2020
28b11b1
Comment
Feb 16, 2020
d09378c
minor thing
Feb 16, 2020
d8e0df7
minor things
Feb 16, 2020
5234dea
forgot something
Feb 16, 2020
783a771
using a dictionary instead of a map for constant propagation
Feb 16, 2020
21d84f8
removing the fixme
Feb 16, 2020
61ca58b
migrated LoopUnrolling
Feb 16, 2020
01708e6
migrated the callable inlining
Feb 16, 2020
221fe27
migrated statement grouping
Feb 16, 2020
5577133
last one down
Feb 16, 2020
f2fef67
updated the transformations in the Transformation project
Feb 16, 2020
38a37dc
temporarily disable execution tests
Feb 16, 2020
6b12369
disable C# warning for unused variables in example project
Feb 16, 2020
344e48f
that was surprisingly painless - all tests pass again
Feb 16, 2020
63cc58f
getting updates from feature branch
Feb 16, 2020
6d7c5c4
resolving issues due to merg
Feb 16, 2020
8f72525
forgot to make one merge adaption
Feb 16, 2020
7a72d6f
Revert "temporarily disable execution tests"
Feb 16, 2020
0ba5dfc
right package to reenable execution tests
Feb 16, 2020
59b9596
getting a proper diff
Feb 17, 2020
4e70bd9
renamed a file
Feb 17, 2020
92cc4e4
adapting comments
Feb 17, 2020
4fd1692
doc comment edit
Feb 18, 2020
ae36ce5
Merge branch 'features/transformationSetup' into beheim/transformations
Feb 18, 2020
b77bc78
Revert "getting a proper diff"
Feb 19, 2020
33a9bba
Merge branch 'beheim/transformationNodes' into beheim/transformations
Feb 19, 2020
0275aeb
doesn't look like we can have a generic let ...
Feb 19, 2020
12f53f4
we would need the if on each node
Feb 19, 2020
bc7bc6b
that should safe the if query on each node
Feb 19, 2020
c0de289
putting options into a separate file
Feb 19, 2020
8a7a5d5
that should do for the type transformations
Feb 19, 2020
4d7701a
that should do for the expression kind transformation
Feb 19, 2020
9b201c4
that should do for the expression transformation
Feb 19, 2020
7767343
same for statements, added an EmptyStatement
Feb 19, 2020
3476541
getting closer
Feb 19, 2020
0b820f4
that should do it as a first draft
Feb 19, 2020
ef6cc70
removing the walkers
Feb 19, 2020
d2f18b4
minor thing
Feb 20, 2020
3e9bb8c
adding a class version without type parameter and going over the opti…
Feb 20, 2020
4a87401
Merge branch 'beheim/transformations' into beheim/transformationNodes
Feb 20, 2020
f0aeb0a
adapted the transformation test to use the new setup
Feb 20, 2020
ef2d4b3
Merge branch 'features/transformationSetup' into beheim/transformatio…
Feb 20, 2020
683b7ba
forgot a comment
Feb 20, 2020
9e35b0d
removing changes that shouldn't have been committed
Feb 20, 2020
a7a1317
replacing "unsafe"
Feb 22, 2020
52c6a4c
getting updates from feature branch
Feb 22, 2020
668672f
deleting the transformation definitions
Feb 22, 2020
cebe220
rename QsSyntaxTreeTransformation to SyntaxTreeTransformation
Feb 22, 2020
5181b22
to be reverted
Feb 22, 2020
888f488
renaming InternalState to SharedState and adding a direct handle to s…
Feb 22, 2020
b0f8f67
removing the options to override handles to other subtransformations
Feb 22, 2020
9b9b07d
sorting specializations by their kind upon transformation
Feb 22, 2020
738b220
disabling subtransformations if no parent is specified
Feb 23, 2020
7eed928
adapting a test to respect the order in which specializations are walked
Feb 23, 2020
7093e7e
Revert "to be reverted"
Feb 23, 2020
91778a0
updated runtime packages
Feb 23, 2020
5f6d5b9
adding a couple of doc comments
Feb 23, 2020
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
4 changes: 1 addition & 3 deletions src/QsCompiler/Core/Core.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
</Compile>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="ConstructorExtensions.fs" />
<Compile Include="TransformationOptions.fs" />
<Compile Include="TypeTransformation.fs" />
<Compile Include="ExpressionTransformation.fs" />
<Compile Include="StatementTransformation.fs" />
<Compile Include="NamespaceTransformation.fs" />
<Compile Include="SyntaxTreeTransformation.fs" />
<Compile Include="ExpressionWalker.fs" />
<Compile Include="StatementWalker.fs" />
<Compile Include="TreeWalker.fs" />
<Compile Include="Dependencies.fs" />
<Compile Include="SyntaxGenerator.fs" />
<Compile Include="DeclarationHeaders.fs" />
Expand Down
2 changes: 1 addition & 1 deletion src/QsCompiler/Core/DeclarationHeaders.fs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ type CallableDeclarationHeader = {
static member FromJson json =
let info = {IsMutable = false; HasLocalQuantumDependency = false}
let rec setInferredInfo = function // no need to raise an error if anything needs to be set - the info above is always correct
| QsTuple ts -> (ts |> Seq.map setInferredInfo).ToImmutableArray() |> QsTuple
| QsTuple ts -> ts |> Seq.map setInferredInfo |> ImmutableArray.CreateRange |> QsTuple
| QsTupleItem (decl : LocalVariableDeclaration<_>) -> QsTupleItem {decl with InferredInformation = info}
// we need to make sure that all fields that could possibly be null after deserializing
// due to changes of fields over time are initialized to a proper value
Expand Down
390 changes: 247 additions & 143 deletions src/QsCompiler/Core/ExpressionTransformation.fs

Large diffs are not rendered by default.

451 changes: 0 additions & 451 deletions src/QsCompiler/Core/ExpressionWalker.fs

This file was deleted.

94 changes: 57 additions & 37 deletions src/QsCompiler/Core/NamespaceTransformation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,35 @@ open Microsoft.Quantum.QsCompiler.DataTypes
open Microsoft.Quantum.QsCompiler.SyntaxExtensions
open Microsoft.Quantum.QsCompiler.SyntaxTokens
open Microsoft.Quantum.QsCompiler.SyntaxTree
open Microsoft.Quantum.QsCompiler.Transformations.Core.Utils

type QsArgumentTuple = QsTuple<LocalVariableDeclaration<QsLocalSymbol>>


type NamespaceTransformationBase internal (unsafe) =
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

member val internal StatementTransformationHandle = missingTransformation "statement" with get, set
member this.Statements = this.StatementTransformationHandle()

// TODO: this should be a protected member
abstract member Statements : StatementTransformationBase
default this.Statements = this.StatementTransformationHandle()

new (statementTransformation : unit -> StatementTransformationBase) as this =
new NamespaceTransformationBase("unsafe") then
new (statementTransformation : unit -> StatementTransformationBase, options : TransformationOptions) as this =
new NamespaceTransformationBase(options, "_internal_") then
this.StatementTransformationHandle <- statementTransformation

new () as this =
new NamespaceTransformationBase("unsafe") then
let statementTransformation = new StatementTransformationBase()
new (options : TransformationOptions) as this =
new NamespaceTransformationBase(options, "_internal_") then
let statementTransformation = new StatementTransformationBase(options)
this.StatementTransformationHandle <- fun _ -> statementTransformation

new (statementTransformation : unit -> StatementTransformationBase) =
new NamespaceTransformationBase(statementTransformation, TransformationOptions.Default)

new () = new NamespaceTransformationBase(TransformationOptions.Default)


// methods invoked before selective nodes

abstract member beforeNamespaceElement : QsNamespaceElement -> QsNamespaceElement
default this.beforeNamespaceElement e = e
Expand All @@ -49,6 +56,8 @@ type NamespaceTransformationBase internal (unsafe) =
default this.beforeGeneratedImplementation dir = dir


// subconstructs used within declarations

abstract member onLocation : QsNullable<QsLocation> -> QsNullable<QsLocation>
default this.onLocation l = l

Expand All @@ -58,43 +67,46 @@ type NamespaceTransformationBase internal (unsafe) =
abstract member onSourceFile : NonNullable<string> -> NonNullable<string>
default this.onSourceFile f = f

abstract member onAttribute : QsDeclarationAttribute -> QsDeclarationAttribute
default this.onAttribute att = att

abstract member onTypeItems : QsTuple<QsTypeItem> -> QsTuple<QsTypeItem>
default this.onTypeItems tItem =
match tItem with
| QsTuple items -> (items |> Seq.map this.onTypeItems).ToImmutableArray() |> QsTuple
| QsTupleItem (Anonymous itemType) ->
| QsTuple items as original ->
let transformed = items |> Seq.map this.onTypeItems |> ImmutableArray.CreateRange
QsTuple |> Node.BuildOr original transformed
| QsTupleItem (Anonymous itemType) as original ->
let t = this.Statements.Expressions.Types.Transform itemType
Anonymous t |> QsTupleItem
| QsTupleItem (Named item) ->
QsTupleItem << Anonymous |> Node.BuildOr original t
| QsTupleItem (Named item) as original ->
let loc = item.Position, item.Range
let t = this.Statements.Expressions.Types.Transform item.Type
let info = this.Statements.Expressions.onExpressionInformation item.InferredInformation
LocalVariableDeclaration<_>.New info.IsMutable (loc, item.VariableName, t, info.HasLocalQuantumDependency) |> Named |> QsTupleItem
QsTupleItem << Named << LocalVariableDeclaration<_>.New info.IsMutable |> Node.BuildOr original (loc, item.VariableName, t, info.HasLocalQuantumDependency)

abstract member onArgumentTuple : QsArgumentTuple -> QsArgumentTuple
default this.onArgumentTuple arg =
match arg with
| QsTuple items -> (items |> Seq.map this.onArgumentTuple).ToImmutableArray() |> QsTuple
| QsTupleItem item ->
| QsTuple items as original ->
let transformed = items |> Seq.map this.onArgumentTuple |> ImmutableArray.CreateRange
QsTuple |> Node.BuildOr original transformed
| QsTupleItem item as original ->
let loc = item.Position, item.Range
let t = this.Statements.Expressions.Types.Transform item.Type
let info = this.Statements.Expressions.onExpressionInformation item.InferredInformation
LocalVariableDeclaration<_>.New info.IsMutable (loc, item.VariableName, t, info.HasLocalQuantumDependency) |> QsTupleItem
QsTupleItem << LocalVariableDeclaration<_>.New info.IsMutable |> Node.BuildOr original (loc, item.VariableName, t, info.HasLocalQuantumDependency)

abstract member onSignature : ResolvedSignature -> ResolvedSignature
default this.onSignature (s : ResolvedSignature) =
let typeParams = s.TypeParameters
let argType = this.Statements.Expressions.Types.Transform s.ArgumentType
let returnType = this.Statements.Expressions.Types.Transform s.ReturnType
let info = this.Statements.Expressions.Types.onCallableInformation s.Information
ResolvedSignature.New ((argType, returnType), info, typeParams)


abstract member onExternalImplementation : unit -> unit
default this.onExternalImplementation () = ()
ResolvedSignature.New |> Node.BuildOr s ((argType, returnType), info, typeParams)

abstract member onIntrinsicImplementation : unit -> unit
default this.onIntrinsicImplementation () = ()

// specialization declarations and implementations

abstract member onProvidedImplementation : QsArgumentTuple * QsScope -> QsArgumentTuple * QsScope
default this.onProvidedImplementation (argTuple, body) =
Expand All @@ -114,6 +126,12 @@ type NamespaceTransformationBase internal (unsafe) =
abstract member onInvalidGeneratorDirective : unit -> unit
default this.onInvalidGeneratorDirective () = ()

abstract member onExternalImplementation : unit -> unit
default this.onExternalImplementation () = ()

abstract member onIntrinsicImplementation : unit -> unit
default this.onIntrinsicImplementation () = ()

member this.dispatchGeneratedImplementation (dir : QsGeneratorDirective) =
match this.beforeGeneratedImplementation dir with
| SelfInverse -> this.onSelfInverseDirective (); SelfInverse
Expand All @@ -122,24 +140,24 @@ type NamespaceTransformationBase internal (unsafe) =
| InvalidGenerator -> this.onInvalidGeneratorDirective(); InvalidGenerator

member this.dispatchSpecializationImplementation (impl : SpecializationImplementation) =
let Build kind transformed = kind |> Node.BuildOr impl transformed
match this.beforeSpecializationImplementation impl with
| External -> this.onExternalImplementation(); External
| Intrinsic -> this.onIntrinsicImplementation(); Intrinsic
| Generated dir -> this.dispatchGeneratedImplementation dir |> Generated
| Provided (argTuple, body) -> this.onProvidedImplementation (argTuple, body) |> Provided

| Generated dir -> this.dispatchGeneratedImplementation dir |> Build Generated
| Provided (argTuple, body) -> this.onProvidedImplementation (argTuple, body) |> Build Provided

abstract member onSpecializationImplementation : QsSpecialization -> QsSpecialization
default this.onSpecializationImplementation (spec : QsSpecialization) =
let source = this.onSourceFile spec.SourceFile
let loc = this.onLocation spec.Location
let attributes = spec.Attributes |> Seq.map this.onAttribute |> ImmutableArray.CreateRange
let typeArgs = spec.TypeArguments |> QsNullable<_>.Map (fun args -> (args |> Seq.map this.Statements.Expressions.Types.Transform).ToImmutableArray())
let typeArgs = spec.TypeArguments |> QsNullable<_>.Map (fun args -> args |> Seq.map this.Statements.Expressions.Types.Transform |> ImmutableArray.CreateRange)
let signature = this.onSignature spec.Signature
let impl = this.dispatchSpecializationImplementation spec.Implementation
let doc = this.onDocumentation spec.Documentation
let comments = spec.Comments
QsSpecialization.New spec.Kind (source, loc) (spec.Parent, attributes, typeArgs, signature, impl, doc, comments)
QsSpecialization.New spec.Kind (source, loc) |> Node.BuildOr spec (spec.Parent, attributes, typeArgs, signature, impl, doc, comments)

abstract member onBodySpecialization : QsSpecialization -> QsSpecialization
default this.onBodySpecialization spec = this.onSpecializationImplementation spec
Expand All @@ -161,6 +179,8 @@ type NamespaceTransformationBase internal (unsafe) =
| QsSpecializationKind.QsControlled -> this.onControlledSpecialization spec
| QsSpecializationKind.QsControlledAdjoint -> this.onControlledAdjointSpecialization spec


// type and callable declarations and implementations

abstract member onType : QsCustomType -> QsCustomType
default this.onType t =
Expand All @@ -171,7 +191,7 @@ type NamespaceTransformationBase internal (unsafe) =
let typeItems = this.onTypeItems t.TypeItems
let doc = this.onDocumentation t.Documentation
let comments = t.Comments
QsCustomType.New (source, loc) (t.FullName, attributes, typeItems, underlyingType, doc, comments)
QsCustomType.New (source, loc) |> Node.BuildOr t (t.FullName, attributes, typeItems, underlyingType, doc, comments)

abstract member onCallableImplementation : QsCallable -> QsCallable
default this.onCallableImplementation (c : QsCallable) =
Expand All @@ -180,10 +200,10 @@ type NamespaceTransformationBase internal (unsafe) =
let attributes = c.Attributes |> Seq.map this.onAttribute |> ImmutableArray.CreateRange
let signature = this.onSignature c.Signature
let argTuple = this.onArgumentTuple c.ArgumentTuple
let specializations = c.Specializations |> Seq.map this.dispatchSpecialization
let specializations = c.Specializations |> Seq.sortBy (fun c -> c.Kind) |> Seq.map this.dispatchSpecialization |> ImmutableArray.CreateRange
let doc = this.onDocumentation c.Documentation
let comments = c.Comments
QsCallable.New c.Kind (source, loc) (c.FullName, attributes, argTuple, signature, specializations, doc, comments)
QsCallable.New c.Kind (source, loc) |> Node.BuildOr c (c.FullName, attributes, argTuple, signature, specializations, doc, comments)

abstract member onOperation : QsCallable -> QsCallable
default this.onOperation c = this.onCallableImplementation c
Expand All @@ -202,8 +222,7 @@ type NamespaceTransformationBase internal (unsafe) =
| QsCallableKind.TypeConstructor -> this.onTypeConstructor c


abstract member onAttribute : QsDeclarationAttribute -> QsDeclarationAttribute
default this.onAttribute att = att
// transformation roots called on each namespace

member this.dispatchNamespaceElement element =
match this.beforeNamespaceElement element with
Expand All @@ -212,9 +231,10 @@ type NamespaceTransformationBase internal (unsafe) =

abstract member Transform : QsNamespace -> QsNamespace
default this.Transform ns =
if options.Disable 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)
let elements = ns.Elements |> Seq.map this.dispatchNamespaceElement
QsNamespace.New (name, elements, doc)
let elements = ns.Elements |> Seq.map this.dispatchNamespaceElement |> ImmutableArray.CreateRange
QsNamespace.New |> Node.BuildOr ns (name, elements, doc)

Loading