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 @@ -1262,6 +1262,11 @@ namespace Microsoft.Quantum.Compiler.Generics {
genIter(genU1<Result>, a);
}

operation genericWithMultipleTypeParams<'A, 'B, 'C>() : Unit { }

operation callsGenericWithMultipleTypeParams () : Unit {
genericWithMultipleTypeParams<Double, Int, Int>();
}

operation composeImpl<'A, 'B> (second : ('A => Unit), first : ('B => 'A), arg : 'B) : Unit {

Expand Down
33 changes: 27 additions & 6 deletions src/Simulation/CsharpGeneration.Tests/SimulationCodeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ namespace N1
let genMapper = findCallable @"genMapper"
let genIter = findCallable @"genIter"
let usesGenerics = findCallable @"usesGenerics"
let callsGenericWithMultipleTypeParams = findCallable @"callsGenericWithMultipleTypeParams"
let duplicatedDefinitionsCaller = findCallable @"duplicatedDefinitionsCaller"
let nestedArgTuple1 = findCallable @"nestedArgTuple1"
let nestedArgTuple2 = findCallable @"nestedArgTuple2"
Expand Down Expand Up @@ -453,6 +454,11 @@ namespace N1
]
|> testOne usesGenerics

[
((NSG, "genericWithMultipleTypeParams"), "ICallable")
]
|> testOne callsGenericWithMultipleTypeParams

[
((NS2, "Allocate" ), "Allocate")
((NS2, "H" ), "IUnitary<Qubit>")
Expand Down Expand Up @@ -897,13 +903,18 @@ namespace N1
|> testOne usesGenerics

[
template "Z" "IUnitary<Qubit>" "Microsoft.Quantum.Intrinsic.Z"
template "genericWithMultipleTypeParams" "ICallable" "genericWithMultipleTypeParams<,,>"
]
|> testOne callsGenericWithMultipleTypeParams

[
template "Z" "IUnitary<Qubit>" "Microsoft.Quantum.Intrinsic.Z"
"this.self = this;"
]
|> testOne selfInvokingOperation

[
template "self" "ICallable" "genRecursion<>"
template "self" "ICallable" "genRecursion<>"
]
|> testOne genRecursion

Expand Down Expand Up @@ -934,6 +945,11 @@ namespace N1
|> List.sort
|> testOne usesGenerics

[
template "genericWithMultipleTypeParams<,,>"
]
|> testOne callsGenericWithMultipleTypeParams

[
template "composeImpl<,>"
]
Expand Down Expand Up @@ -979,6 +995,11 @@ namespace N1
]
|> testOne usesGenerics

[
template "ICallable" "genericWithMultipleTypeParams"
]
|> testOne callsGenericWithMultipleTypeParams

[
template "IUnitary<Qubit>" "Z"
template "IAdjointable<Qubit>" "self"
Expand Down Expand Up @@ -2502,7 +2523,7 @@ namespace N1
|> testOneClass genCtrl3 AssemblyConstants.HoneywellProcessor

"""
[SourceLocation("%%%", OperationFunctor.Body, 1266, 1272)]
[SourceLocation("%%%", OperationFunctor.Body, 1271, 1277)]
public partial class composeImpl<__A__, __B__> : Operation<(ICallable,ICallable,__B__), QVoid>, ICallable
{
public composeImpl(IOperationFactory m) : base(m)
Expand Down Expand Up @@ -2579,7 +2600,7 @@ namespace N1
[<Fact>]
let ``buildOperationClass - access modifiers`` () =
"""
[SourceLocation("%%%", OperationFunctor.Body, 1314, 1316)]
[SourceLocation("%%%", OperationFunctor.Body, 1319, 1321)]
internal partial class EmptyInternalFunction : Function<QVoid, QVoid>, ICallable
{
public EmptyInternalFunction(IOperationFactory m) : base(m)
Expand Down Expand Up @@ -2613,7 +2634,7 @@ internal partial class EmptyInternalFunction : Function<QVoid, QVoid>, ICallable
|> testOneClass emptyInternalFunction null

"""
[SourceLocation("%%%", OperationFunctor.Body, 1316, 1318)]
[SourceLocation("%%%", OperationFunctor.Body, 1321, 1323)]
internal partial class EmptyInternalOperation : Operation<QVoid, QVoid>, ICallable
{
public EmptyInternalOperation(IOperationFactory m) : base(m)
Expand Down Expand Up @@ -2730,7 +2751,7 @@ internal partial class EmptyInternalOperation : Operation<QVoid, QVoid>, ICallab
[<Fact>]
let ``buildOperationClass - concrete functions`` () =
"""
[SourceLocation("%%%", OperationFunctor.Body, 1301,1310)]
[SourceLocation("%%%", OperationFunctor.Body, 1306,1315)]
public partial class UpdateUdtItems : Function<MyType2, MyType2>, ICallable
{
public UpdateUdtItems(IOperationFactorym) : base(m)
Expand Down
8 changes: 2 additions & 6 deletions src/Simulation/CsharpGeneration/SimulationCode.fs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ module SimulationCode =
let isGeneric context (n: QsQualifiedName) =
if context.allCallables.ContainsKey n then
let signature = context.allCallables.[n].Signature
let tIn = signature.ArgumentType
let tOut = signature.ReturnType
hasTypeParameters [tIn;tOut]
not signature.TypeParameters.IsEmpty
else
false

Expand Down Expand Up @@ -861,9 +859,7 @@ module SimulationCode =
let opName = if sameNamespace then n.Name.Value else n.Namespace.Value + "." + n.Name.Value
if isGeneric context n then
let signature = context.allCallables.[n].Signature
let tIn = signature.ArgumentType
let tOut = signature.ReturnType
let count = (getTypeParameters [tIn;tOut]).Length
let count = signature.TypeParameters.Length
sprintf "%s<%s>" opName (String.replicate (count - 1) ",")
else
opName
Expand Down
Loading