This repository was archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 173
General tool for combining and verifying type resolution dictionaries #397
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
975120b
replaced GetCombinedTypeResolution with a more general method that pe…
3b32b6e
one more case to handle
f8e68ca
doc comment
1554db0
add a stump for cycle verification
398e304
setting up some tests
991c0cb
found and fixed a bug
4cdfc53
found and fixed another edge case
f645786
more tests - the current setup would require checking for each node i…
8bc17c9
Update src/QsCompiler/Transformations/ClassicallyControlled.cs
bettinaheim 0f85ec3
review comment
dd53a87
doc comment
20dc213
more review comments
74979a7
Merge branch 'beheim/typeResDicts' of https://github.com/microsoft/qs…
a64a849
Update src/QsCompiler/Transformations/CallGraphWalker.cs
bettinaheim e90082a
Update src/QsCompiler/Transformations/CallGraphWalker.cs
bettinaheim 5454320
adapting comment
1b02244
Merge branch 'beheim/typeResDicts' of https://github.com/microsoft/qs…
0d84170
test
92fee03
two more tests
8d68acd
comments
9f72a99
renaming
3c8a874
splitting tests into individual tests
ea7e68e
splitting out inconsistent resolution to native check
1a10823
helpful comment
83d089d
separate loops
602f4d5
disabling test as not yet supported for now
6866ca7
conflict resolution
0128937
removing tests for parent independent case
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,306 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Microsoft.Quantum.QsCompiler.Testing | ||
|
|
||
| open System | ||
| open System.Collections.Generic | ||
| open System.Collections.Immutable | ||
| 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 | ||
| open Xunit | ||
| open Xunit.Abstractions | ||
|
|
||
|
|
||
| type CallGraphTests (output:ITestOutputHelper) = | ||
|
|
||
| let qualifiedName name = | ||
| ("NS" |> NonNullable<string>.New, name |> NonNullable<string>.New) |> QsQualifiedName.New | ||
|
|
||
| let typeParameter (id : string) = | ||
| let pieces = id.Split(".") | ||
| Assert.True(pieces.Length = 2) | ||
| let parent = qualifiedName pieces.[0] | ||
| let name = pieces.[1] |> NonNullable<string>.New | ||
| QsTypeParameter.New (parent, name, Null) | ||
|
|
||
| let resolution (res : (QsTypeParameter * QsTypeKind<_,_,_,_>) list) = | ||
| res.ToImmutableDictionary((fun (tp,_) -> tp.Origin, tp.TypeName), snd >> ResolvedType.New) | ||
|
|
||
| let Foo = qualifiedName "Foo" | ||
| let Bar = qualifiedName "Bar" | ||
|
|
||
| let FooA = typeParameter "Foo.A" | ||
| let FooB = typeParameter "Foo.B" | ||
| let BarA = typeParameter "Bar.A" | ||
| let BarC = typeParameter "Bar.C" | ||
| let BazA = typeParameter "Baz.A" | ||
|
|
||
| static member CheckResolution (parent, expected : IDictionary<_,_>, [<ParamArray>] resolutions) = | ||
| let expectedKeys = ImmutableHashSet.CreateRange(expected.Keys) | ||
| let compareWithExpected (d : ImmutableDictionary<_,_>) = | ||
| let keysMismatch = expectedKeys.SymmetricExcept d.Keys | ||
| keysMismatch.Count = 0 && expected |> Seq.exists (fun kv -> d.[kv.Key] <> kv.Value) |> not | ||
| let mutable combined = ImmutableDictionary.Empty | ||
| let success = CallGraph.TryCombineTypeResolutions(parent, &combined, resolutions) | ||
| Assert.True(compareWithExpected combined, "combined resolutions did not match the expected ones") | ||
| success | ||
|
|
||
| static member AssertResolution (parent, expected, [<ParamArray>] resolutions) = | ||
| let success = CallGraphTests.CheckResolution (parent, expected, resolutions) | ||
| Assert.True(success, "Combining type resolutions was not successful.") | ||
|
|
||
| static member AssertResolutionFailure (parent, expected, [<ParamArray>] resolutions) = | ||
| let success = CallGraphTests.CheckResolution (parent, expected, resolutions) | ||
| Assert.False(success, "Combining type resolutions should have failed.") | ||
|
|
||
|
|
||
| [<Fact>] | ||
| [<Trait("Category","Type resolution")>] | ||
| member this.``Type resolution: resolution to concrete`` () = | ||
|
|
||
| let res1 = resolution [ | ||
| (FooA, BarA |> TypeParameter) | ||
| (FooB, Int) | ||
| ] | ||
| let res2 = resolution [ | ||
| (BarA, Int) | ||
| ] | ||
| let expected = resolution [ | ||
| (FooA, Int) | ||
| (FooB, Int) | ||
| ] | ||
| CallGraphTests.AssertResolution(Foo, expected, res1, res2) | ||
|
|
||
| [<Fact>] | ||
| [<Trait("Category","Type resolution")>] | ||
| member this.``Type resolution: resolution to type parameter`` () = | ||
|
|
||
| let res1 = resolution [ | ||
| (FooA, BarA |> TypeParameter) | ||
| ] | ||
| let res2 = resolution [ | ||
| (BarA, BazA |> TypeParameter) | ||
| ] | ||
| let expected = resolution [ | ||
| (FooA, BazA |> TypeParameter) | ||
| ] | ||
| CallGraphTests.AssertResolution(Foo, expected, res1, res2) | ||
|
|
||
| [<Fact>] | ||
| [<Trait("Category","Type resolution")>] | ||
| member this.``Type resolution: resolution via identity mapping`` () = | ||
|
|
||
| let res1 = resolution [ | ||
| (FooA, FooA |> TypeParameter) | ||
| ] | ||
| let res2 = resolution [ | ||
| (FooA, Int) | ||
| ] | ||
| let expected = resolution [ | ||
| (FooA, Int) | ||
| ] | ||
| CallGraphTests.AssertResolution(Foo, expected, res1, res2) | ||
|
|
||
| [<Fact>] | ||
| [<Trait("Category","Type resolution")>] | ||
| member this.``Type resolution: multi-stage resolution`` () = | ||
|
|
||
| let res1 = resolution [ | ||
| (FooA, BarA |> TypeParameter) | ||
| ] | ||
| let res2 = resolution [ | ||
| (BarA, Int) | ||
| (FooB, Int) | ||
| ] | ||
| let expected = resolution [ | ||
| (FooA, Int) | ||
| (FooB, Int) | ||
| ] | ||
| CallGraphTests.AssertResolution(Foo, expected, res1, res2) | ||
|
|
||
| [<Fact>] | ||
| [<Trait("Category","Type resolution")>] | ||
| member this.``Type resolution: multiple resolutions to concrete`` () = | ||
|
|
||
| let res1 = resolution [ | ||
| (FooA, BarA |> TypeParameter) | ||
| (FooB, BarA |> TypeParameter) | ||
| ] | ||
| let res2 = resolution [ | ||
| (BarA, Int) | ||
| ] | ||
| let expected = resolution [ | ||
| (FooA, Int) | ||
| (FooB, Int) | ||
| ] | ||
| CallGraphTests.AssertResolution(Foo, expected, res1, res2) | ||
|
|
||
| [<Fact>] | ||
| [<Trait("Category","Type resolution")>] | ||
| member this.``Type resolution: multiple resolutions to type parameter`` () = | ||
|
|
||
| let res1 = resolution [ | ||
| (FooA, BarA |> TypeParameter) | ||
| (FooB, BarA |> TypeParameter) | ||
| ] | ||
| let res2 = resolution [ | ||
| (BarA, BazA |> TypeParameter) | ||
| ] | ||
| let res3 = resolution [ | ||
| (BazA, Double) | ||
| ] | ||
| let expected = resolution [ | ||
| (FooA, Double) | ||
| (FooB, Double) | ||
| ] | ||
| CallGraphTests.AssertResolution(Foo, expected, res1, res2, res3) | ||
|
|
||
| [<Fact>] | ||
| [<Trait("Category","Type resolution")>] | ||
| member this.``Type resolution: multi-stage resolution of multiple resolutions to concrete`` () = | ||
|
|
||
| let res1 = resolution [ | ||
| (FooA, BarA |> TypeParameter) | ||
| ] | ||
| let res2 = resolution [ | ||
| (FooB, BarA |> TypeParameter) | ||
| ] | ||
| let res3 = resolution [ | ||
| (BarA, Int) | ||
| ] | ||
| let expected = resolution [ | ||
| (FooA, Int) | ||
| (FooB, Int) | ||
| ] | ||
| CallGraphTests.AssertResolution(Foo, expected, res1, res2, res3) | ||
|
|
||
| [<Fact>] | ||
| [<Trait("Category","Type resolution")>] | ||
| member this.``Type resolution: redundant resolution to concrete`` () = | ||
|
|
||
| let res1 = resolution [ | ||
| (FooA, BarA |> TypeParameter) | ||
| ] | ||
| let res2 = resolution [ | ||
| (BarA, Int) | ||
| (FooA, Int) | ||
| ] | ||
| let expected = resolution [ | ||
| (FooA, Int) | ||
| ] | ||
| CallGraphTests.AssertResolution(Foo, expected, res1, res2) | ||
|
|
||
| [<Fact>] | ||
| [<Trait("Category","Type resolution")>] | ||
| member this.``Type resolution: redundant resolution to type parameter`` () = | ||
|
|
||
| let res1 = resolution [ | ||
| (FooA, BarA |> TypeParameter) | ||
| ] | ||
| let res2 = resolution [ | ||
| (BarA, BazA |> TypeParameter) | ||
| ] | ||
| let res3 = resolution [ | ||
| (FooA, BazA |> TypeParameter) | ||
| ] | ||
| let expected = resolution [ | ||
| (FooA, BazA |> TypeParameter) | ||
| ] | ||
| CallGraphTests.AssertResolution(Foo, expected, res1, res2, res3) | ||
|
|
||
| [<Fact>] | ||
| [<Trait("Category","Type resolution")>] | ||
| member this.``Type resolution: conflicting resolution to concrete`` () = | ||
|
|
||
| let res1 = resolution [ | ||
| (FooA, BarA |> TypeParameter) | ||
| ] | ||
| let res2 = resolution [ | ||
| (BarA, Int) | ||
| (FooA, Double) | ||
| ] | ||
| let expected = resolution [ | ||
| (FooA, Double) | ||
| ] | ||
| CallGraphTests.AssertResolutionFailure(Foo, expected, res1, res2) | ||
|
|
||
| [<Fact>] | ||
| [<Trait("Category","Type resolution")>] | ||
| member this.``Type resolution: conflicting resolution to type parameter`` () = | ||
|
|
||
| let res1 = resolution [ | ||
| (FooA, BarA |> TypeParameter) | ||
| ] | ||
| let res2 = resolution [ | ||
| (BarA, BazA |> TypeParameter) | ||
| (FooA, BarC |> TypeParameter) | ||
| ] | ||
| let expected = resolution [ | ||
| (FooA, BarC |> TypeParameter) | ||
| ] | ||
| CallGraphTests.AssertResolutionFailure(Foo, expected, res1, res2) | ||
|
|
||
| [<Fact>] | ||
| [<Trait("Category","Type resolution")>] | ||
| member this.``Type resolution: direct resolution to native`` () = | ||
|
|
||
| let res1 = resolution [ | ||
| (FooA, FooA |> TypeParameter) | ||
| ] | ||
| let expected = resolution [ | ||
| (FooA, FooA |> TypeParameter) | ||
| ] | ||
| CallGraphTests.AssertResolution(Foo, expected, res1) | ||
|
|
||
| [<Fact>] | ||
| [<Trait("Category","Type resolution")>] | ||
| member this.``Type resolution: indirect resolution to native`` () = | ||
|
|
||
| let res1 = resolution [ | ||
| (FooA, BarA |> TypeParameter) | ||
| ] | ||
| let res2 = resolution [ | ||
| (BarA, BazA |> TypeParameter) | ||
| ] | ||
| let res3 = resolution [ | ||
| (BazA, FooA |> TypeParameter) | ||
| ] | ||
| let expected = resolution [ | ||
| (FooA, FooA |> TypeParameter) | ||
| ] | ||
| CallGraphTests.AssertResolution(Foo, expected, res1, res2, res3) | ||
|
|
||
| [<Fact>] | ||
| [<Trait("Category","Type resolution")>] | ||
| member this.``Type resolution: direct resolution constrains native`` () = | ||
|
|
||
| let res1 = resolution [ | ||
| (FooA, FooB |> TypeParameter) | ||
| ] | ||
| let expected = resolution [ | ||
| (FooA, FooB |> TypeParameter) | ||
| ] | ||
| CallGraphTests.AssertResolutionFailure(Foo, expected, res1) | ||
|
|
||
| [<Fact>] | ||
| [<Trait("Category","Type resolution")>] | ||
| member this.``Type resolution: indirect resolution constrains native`` () = | ||
|
|
||
| let res1 = resolution [ | ||
| (FooA, BarA |> TypeParameter) | ||
| ] | ||
| let res2 = resolution [ | ||
| (BarA, BazA |> TypeParameter) | ||
| ] | ||
| let res3 = resolution [ | ||
| (BazA, FooB |> TypeParameter) | ||
| ] | ||
| let expected = resolution [ | ||
| (FooA, FooB |> TypeParameter) | ||
| ] | ||
| CallGraphTests.AssertResolutionFailure(Foo, expected, res1, res2, res3) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.