Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Closed
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
23 changes: 9 additions & 14 deletions src/QsCompiler/Core/SymbolTable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -941,24 +941,19 @@ and NamespaceManager
errs.Add (decl.Position, signature.Characteristics.Range.ValueOr decl.Range |> QsCompilerDiagnostic.Error (ErrorCode.InvalidEntryPointSpecialization, []))

// validate entry point argument and return type
let rec validateArgAndReturnTypes (isArg, inArray) (t : QsType) =
let supportedItemType = function
| Int | Double | Bool | String -> true
| _ -> false
match t.Type with
let validateArgAndReturnTypes isArg (qsType : QsType) =
let rec IsArray = function
| ArrayType _ -> true
| TupleType (ts : ImmutableArray<QsType>) when ts.Length = 1 -> IsArray ts.[0].Type
| _ -> false
qsType.ExtractAll (fun t -> t.Type |> function // ExtractAll recurs on all subtypes (e.g. callable in- and output types as well)
| Qubit -> (decl.Position, t.Range |> orDefault |> QsCompilerDiagnostic.Error (ErrorCode.QubitTypeInEntryPointSignature, [])) |> Seq.singleton
| UserDefinedType _ -> (decl.Position, t.Range |> orDefault |> QsCompilerDiagnostic.Error (ErrorCode.UserDefinedTypeInEntryPointSignature, [])) |> Seq.singleton
| QsTypeKind.Operation _ -> (decl.Position, t.Range |> orDefault |> QsCompilerDiagnostic.Error (ErrorCode.CallableTypeInEntryPointSignature, [])) |> Seq.singleton
| QsTypeKind.Function _ -> (decl.Position, t.Range |> orDefault |> QsCompilerDiagnostic.Error (ErrorCode.CallableTypeInEntryPointSignature, [])) |> Seq.singleton
| UserDefinedType _ -> (decl.Position, t.Range |> orDefault |> QsCompilerDiagnostic.Error (ErrorCode.UserDefinedTypeInEntryPointSignature, [])) |> Seq.singleton
| TupleType ts when ts.Length > 1 && isArg -> (decl.Position, t.Range |> orDefault |> QsCompilerDiagnostic.Error (ErrorCode.InnerTupleInEntryPointArgument, [])) |> Seq.singleton
| TupleType ts -> ts |> Seq.collect (validateArgAndReturnTypes (isArg, inArray))
| ArrayType _ when isArg && inArray -> (decl.Position, t.Range |> orDefault |> QsCompilerDiagnostic.Error (ErrorCode.ArrayOfArrayInEntryPointArgument, [])) |> Seq.singleton
| ArrayType bt -> validateArgAndReturnTypes (isArg, true) bt
| _ when isArg && inArray ->
if supportedItemType t.Type then Seq.empty
else (decl.Position, t.Range |> orDefault |> QsCompilerDiagnostic.Error (ErrorCode.UnsupportedItemTypeInEntryPointArgument, [])) |> Seq.singleton
| _ -> Seq.empty
let validateArgAndReturnTypes isArg = validateArgAndReturnTypes (isArg, false)
| ArrayType bt when isArg && bt.Type |> IsArray -> (decl.Position, t.Range |> orDefault |> QsCompilerDiagnostic.Error (ErrorCode.ArrayOfArrayInEntryPointArgument, [])) |> Seq.singleton
| _ -> Seq.empty)
let inErrs = signature.Argument.Items.Select snd |> Seq.collect (validateArgAndReturnTypes true)
let outErrs = signature.ReturnType |> validateArgAndReturnTypes false
let signatureErrs = inErrs.Concat outErrs
Expand Down
24 changes: 11 additions & 13 deletions src/QsCompiler/DataStructures/Diagnostics.fs
Original file line number Diff line number Diff line change
Expand Up @@ -236,18 +236,17 @@ type ErrorCode =
| UserDefinedTypeInEntryPointSignature = 6233
| InnerTupleInEntryPointArgument = 6234
| ArrayOfArrayInEntryPointArgument = 6235
| UnsupportedItemTypeInEntryPointArgument = 6236
| OtherEntryPointExists = 6237
| MultipleEntryPoints = 6238
| MissingEntryPoint = 6239
| InvalidEntryPointSpecialization = 6240
| DuplicateEntryPointArgumentName = 6241
| EntryPointInLibrary = 6242
| InvalidTestAttributePlacement = 6243
| InvalidExecutionTargetForTest = 6244
| ExpectingFullNameAsAttributeArgument = 6245
| AttributeInvalidOnSpecialization = 6246
| AttributeInvalidOnCallable = 6247
| OtherEntryPointExists = 6236
| MultipleEntryPoints = 6237
| MissingEntryPoint = 6238
| InvalidEntryPointSpecialization = 6239
| DuplicateEntryPointArgumentName = 6240
| EntryPointInLibrary = 6241
| InvalidTestAttributePlacement = 6242
| InvalidExecutionTargetForTest = 6243
| ExpectingFullNameAsAttributeArgument = 6244
| AttributeInvalidOnSpecialization = 6245
| AttributeInvalidOnCallable = 6246

| TypeMismatchInReturn = 6301
| TypeMismatchInValueUpdate = 6302
Expand Down Expand Up @@ -614,7 +613,6 @@ type DiagnosticItem =
| ErrorCode.UserDefinedTypeInEntryPointSignature -> "Invalid entry point. Values of user defined type may not be used as arguments or return values to entry points."
| ErrorCode.InnerTupleInEntryPointArgument -> "Anonymous tuple items or arrays of tuples are not supported in entry point arguments. All items need to be named."
| ErrorCode.ArrayOfArrayInEntryPointArgument -> "Multi-dimensional arrays are not supported in entry point arguments."
| ErrorCode.UnsupportedItemTypeInEntryPointArgument -> "Unsupported item type in entry point argument. Array items may only contain values of type Int, Double, Bool, and String."
| ErrorCode.OtherEntryPointExists -> "Invalid entry point. An entry point {0} already exists in {1}."
| ErrorCode.MultipleEntryPoints -> "The project contains more than one entry point."
| ErrorCode.MissingEntryPoint -> "Missing entry point. Execution on a quantum processor requires that a Q# entry point is defined using the @EntryPoint() attribute. Any C# driver code should be defined in a separate project."
Expand Down
40 changes: 18 additions & 22 deletions src/QsCompiler/Tests.Compiler/LinkingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -294,56 +294,52 @@ type LinkingTests (output:ITestOutputHelper) =
member this.``Entry point argument and return type verification`` () =

this.Expect "InvalidEntryPoint1" [Error ErrorCode.QubitTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint2" [Error ErrorCode.InnerTupleInEntryPointArgument]
this.Expect "InvalidEntryPoint2" [Error ErrorCode.QubitTypeInEntryPointSignature; Error ErrorCode.InnerTupleInEntryPointArgument]
this.Expect "InvalidEntryPoint3" [Error ErrorCode.QubitTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint4" [Error ErrorCode.QubitTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint5" [Error ErrorCode.QubitTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint6" [Error ErrorCode.QubitTypeInEntryPointSignature]

this.Expect "InvalidEntryPoint7" [Error ErrorCode.CallableTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint8" [Error ErrorCode.InnerTupleInEntryPointArgument]
this.Expect "InvalidEntryPoint9" [Error ErrorCode.InnerTupleInEntryPointArgument]
this.Expect "InvalidEntryPoint8" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.InnerTupleInEntryPointArgument]
this.Expect "InvalidEntryPoint9" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.InnerTupleInEntryPointArgument]
this.Expect "InvalidEntryPoint10" [Error ErrorCode.CallableTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint11" [Error ErrorCode.CallableTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint12" [Error ErrorCode.CallableTypeInEntryPointSignature]

this.Expect "InvalidEntryPoint13" [Error ErrorCode.CallableTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint14" [Error ErrorCode.CallableTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint15" [Error ErrorCode.CallableTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint16" [Error ErrorCode.CallableTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint13" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.QubitTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint14" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.QubitTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint15" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.QubitTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint16" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.QubitTypeInEntryPointSignature]

this.Expect "InvalidEntryPoint17" [Error ErrorCode.CallableTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint18" [Error ErrorCode.InnerTupleInEntryPointArgument]
this.Expect "InvalidEntryPoint19" [Error ErrorCode.InnerTupleInEntryPointArgument]
this.Expect "InvalidEntryPoint18" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.InnerTupleInEntryPointArgument]
this.Expect "InvalidEntryPoint19" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.InnerTupleInEntryPointArgument]
this.Expect "InvalidEntryPoint20" [Error ErrorCode.CallableTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint21" [Error ErrorCode.CallableTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint22" [Error ErrorCode.CallableTypeInEntryPointSignature]

this.Expect "InvalidEntryPoint23" [Error ErrorCode.CallableTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint24" [Error ErrorCode.CallableTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint25" [Error ErrorCode.CallableTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint26" [Error ErrorCode.CallableTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint23" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.QubitTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint24" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.QubitTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint25" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.QubitTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint26" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.QubitTypeInEntryPointSignature]

this.Expect "InvalidEntryPoint27" [Error ErrorCode.UserDefinedTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint28" [Error ErrorCode.InnerTupleInEntryPointArgument]
this.Expect "InvalidEntryPoint28" [Error ErrorCode.UserDefinedTypeInEntryPointSignature; Error ErrorCode.InnerTupleInEntryPointArgument]
this.Expect "InvalidEntryPoint29" [Error ErrorCode.UserDefinedTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint30" [Error ErrorCode.UserDefinedTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint31" [Error ErrorCode.UserDefinedTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint32" [Error ErrorCode.UserDefinedTypeInEntryPointSignature]

this.Expect "InvalidEntryPoint33" [Error ErrorCode.CallableTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint34" [Error ErrorCode.CallableTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint35" [Error ErrorCode.CallableTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint36" [Error ErrorCode.CallableTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint33" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.UserDefinedTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint34" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.UserDefinedTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint35" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.UserDefinedTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint36" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.UserDefinedTypeInEntryPointSignature]
this.Expect "InvalidEntryPoint37" [Error ErrorCode.InnerTupleInEntryPointArgument]
this.Expect "InvalidEntryPoint38" [Error ErrorCode.InnerTupleInEntryPointArgument]
this.Expect "InvalidEntryPoint39" [Error ErrorCode.ArrayOfArrayInEntryPointArgument]
this.Expect "InvalidEntryPoint40" [Error ErrorCode.ArrayOfArrayInEntryPointArgument]
this.Expect "InvalidEntryPoint41" [Error ErrorCode.ArrayOfArrayInEntryPointArgument]
this.Expect "InvalidEntryPoint42" [Error ErrorCode.UnsupportedItemTypeInEntryPointArgument]
this.Expect "InvalidEntryPoint43" [Error ErrorCode.UnsupportedItemTypeInEntryPointArgument]
this.Expect "InvalidEntryPoint44" [Error ErrorCode.UnsupportedItemTypeInEntryPointArgument]
this.Expect "InvalidEntryPoint45" [Error ErrorCode.UnsupportedItemTypeInEntryPointArgument]


[<Fact>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ namespace Microsoft.Quantum.Testing.EntryPoints {
operation InvalidEntryPoint38(arg1 : (Pauli, Result)[], arg2 : Double) : Unit {}


// array item type validation in entry point arguments
// no arrays of arrays in entry point arguments

@ EntryPoint()
operation InvalidEntryPoint39(arg : Int[][]) : Unit {}
Expand All @@ -237,16 +237,4 @@ namespace Microsoft.Quantum.Testing.EntryPoints {
@ EntryPoint()
operation InvalidEntryPoint41(a : Int[], (b : Int[][], c : Double)) : Unit {}

@ EntryPoint()
operation InvalidEntryPoint42(a : BigInt[]) : Unit {}

@ EntryPoint()
operation InvalidEntryPoint43(a : Range[]) : Unit {}

@ EntryPoint()
operation InvalidEntryPoint44(a : Result[]) : Unit {}

@ EntryPoint()
operation InvalidEntryPoint45(a : Pauli[]) : Unit {}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ namespace Microsoft.Quantum.Testing.EntryPoints {
namespace Microsoft.Quantum.Testing.EntryPoints {

@ EntryPoint()
operation ValidEntryPoint6(a : Int, b: Double[]) : Unit {}
operation ValidEntryPoint6(a : Int, b: BigInt[]) : Unit {}
}

// =================================

namespace Microsoft.Quantum.Testing.EntryPoints {

@ EntryPoint()
operation ValidEntryPoint7(arg1 : (Int)[], arg2 : Double) : Unit {}
operation ValidEntryPoint7(arg1 : (Pauli)[], arg2 : Double) : Unit {}
}

// =================================
Expand Down