From 29a30fad9ef0f62b079d30128ac5779c0f392ccb Mon Sep 17 00:00:00 2001 From: Sarah Marshall Date: Fri, 6 Nov 2020 18:31:24 -0800 Subject: [PATCH 1/4] Remove NonNullable --- src/Simulation/CsharpGeneration/Context.fs | 16 +-- src/Simulation/CsharpGeneration/EntryPoint.fs | 10 +- .../CsharpGeneration/SimulationCode.fs | 124 +++++++++--------- .../Microsoft.Quantum.QSharp.Core.csproj | 1 + 4 files changed, 76 insertions(+), 75 deletions(-) diff --git a/src/Simulation/CsharpGeneration/Context.fs b/src/Simulation/CsharpGeneration/Context.fs index c692c705e9a..3b409babf65 100644 --- a/src/Simulation/CsharpGeneration/Context.fs +++ b/src/Simulation/CsharpGeneration/Context.fs @@ -19,19 +19,19 @@ module internal DeclarationLocations = type TransformationState() = member val internal CurrentSource = null with get, set - member val internal DeclarationLocations = new List * Position>() + member val internal DeclarationLocations = new List() type NamespaceTransformation(parent : SyntaxTreeTransformation) = inherit NamespaceTransformation(parent) override this.OnSourceFile file = - this.SharedState.CurrentSource <- file.Value + this.SharedState.CurrentSource <- file file override this.OnLocation sourceLocation = match sourceLocation with | Value (loc : QsLocation) when this.SharedState.CurrentSource <> null -> - this.SharedState.DeclarationLocations.Add (NonNullable.New this.SharedState.CurrentSource, loc.Offset) + this.SharedState.DeclarationLocations.Add (this.SharedState.CurrentSource, loc.Offset) | _ -> () sourceLocation @@ -60,8 +60,8 @@ type CodegenContext = { allQsElements : IEnumerable allUdts : ImmutableDictionary allCallables : ImmutableDictionary - declarationPositions : ImmutableDictionary, ImmutableSortedSet> - byName : ImmutableDictionary,(NonNullable*QsCallable) list> + declarationPositions : ImmutableDictionary> + byName : ImmutableDictionary current : QsQualifiedName option signature : ResolvedSignature option fileName : string option @@ -73,7 +73,7 @@ type CodegenContext = { let callables = GlobalCallableResolutions syntaxTree let positionInfos = DeclarationLocations.Accumulate syntaxTree let callablesByName = - let result = new Dictionary,(NonNullable*QsCallable) list>() + let result = new Dictionary() syntaxTree |> Seq.collect (fun ns -> ns.Elements |> Seq.choose (function | QsCallable c -> Some (ns, c) | _ -> None)) @@ -124,10 +124,10 @@ type CodegenContext = { | true, propVal -> propVal = "true" | false, _ -> false - member internal this.GenerateCodeForSource (fileName : NonNullable) = + member internal this.GenerateCodeForSource (fileName : string) = let targetsQuantumProcessor = match this.assemblyConstants.TryGetValue AssemblyConstants.ProcessorArchitecture with | true, target -> target = AssemblyConstants.HoneywellProcessor || target = AssemblyConstants.IonQProcessor || target = AssemblyConstants.QCIProcessor | _ -> false - not (fileName.Value.EndsWith ".dll") || targetsQuantumProcessor + not (fileName.EndsWith ".dll") || targetsQuantumProcessor diff --git a/src/Simulation/CsharpGeneration/EntryPoint.fs b/src/Simulation/CsharpGeneration/EntryPoint.fs index a1937bcf88b..2cd9b328a9b 100644 --- a/src/Simulation/CsharpGeneration/EntryPoint.fs +++ b/src/Simulation/CsharpGeneration/EntryPoint.fs @@ -49,10 +49,10 @@ let rec private parameters context doc = function | QsTupleItem variable -> match variable.VariableName with | ValidName name -> - Seq.singleton { Name = name.Value + Seq.singleton { Name = name QsharpType = variable.Type CsharpTypeName = SimulationCode.roslynTypeName context variable.Type - Description = ParameterDescription doc name.Value } + Description = ParameterDescription doc name } | InvalidName -> Seq.empty | QsTuple items -> items |> Seq.map (parameters context doc) |> Seq.concat @@ -113,8 +113,8 @@ let private createArgument context entryPoint = /// A tuple of the callable's name, argument type name, and return type name. let private callableTypeNames context (callable : QsCallable) = let callableName = - SimulationCode.userDefinedName None callable.FullName.Name.Value - |> sprintf "global::%s.%s" callable.FullName.Namespace.Value + SimulationCode.userDefinedName None callable.FullName.Name + |> sprintf "global::%s.%s" callable.FullName.Namespace let argTypeName = SimulationCode.roslynTypeName context callable.Signature.ArgumentType let returnTypeName = SimulationCode.roslynTypeName context callable.Signature.ReturnType callableName, argTypeName, returnTypeName @@ -173,7 +173,7 @@ let private entryPointClass context entryPoint = /// Generates C# source code for a standalone executable that runs the Q# entry point. let generate context (entryPoint : QsCallable) = let ns = - ``namespace`` entryPoint.FullName.Namespace.Value + ``namespace`` entryPoint.FullName.Namespace ``{`` (Seq.map using SimulationCode.autoNamespaces) [entryPointClass context entryPoint] diff --git a/src/Simulation/CsharpGeneration/SimulationCode.fs b/src/Simulation/CsharpGeneration/SimulationCode.fs index b7db959d2a4..89e49873194 100644 --- a/src/Simulation/CsharpGeneration/SimulationCode.fs +++ b/src/Simulation/CsharpGeneration/SimulationCode.fs @@ -46,10 +46,10 @@ module SimulationCode = ] let funcsAsProps = [ - ("Length", { Namespace = "Microsoft.Quantum.Core" |> NonNullable.New; Name = "Length" |> NonNullable.New } ) - ("Start", { Namespace = "Microsoft.Quantum.Core" |> NonNullable.New; Name = "RangeStart" |> NonNullable.New } ) - ("End", { Namespace = "Microsoft.Quantum.Core" |> NonNullable.New; Name = "RangeEnd" |> NonNullable.New } ) - ("Step", { Namespace = "Microsoft.Quantum.Core" |> NonNullable.New; Name = "RangeStep" |> NonNullable.New } ) + ("Length", { Namespace = "Microsoft.Quantum.Core"; Name = "Length" } ) + ("Start", { Namespace = "Microsoft.Quantum.Core"; Name = "RangeStart" } ) + ("End", { Namespace = "Microsoft.Quantum.Core"; Name = "RangeEnd" } ) + ("Step", { Namespace = "Microsoft.Quantum.Core"; Name = "RangeStep" } ) ] let internal userDefinedName (parent : QsQualifiedName option) name = @@ -61,13 +61,13 @@ module SimulationCode = | "Run" -> true | _ -> Regex.IsMatch (name, @"^Item\d+$") || - parent |> Option.exists (fun current' -> name = current'.Name.Value) + parent |> Option.exists (fun current' -> name = current'.Name) if isReserved then name + "__" else name let isCurrentOp context n = match context.current with | None -> false | Some name -> name = n let prependNamespaceString (name : QsQualifiedName) = - name.Namespace.Value.Replace (".", "__") + "__" + name.Name.Value + name.Namespace.Replace (".", "__") + "__" + name.Name let needsFullPath context (op:QsQualifiedName) = let hasMultipleDefinitions() = if context.byName.ContainsKey op.Name then context.byName.[op.Name].Length > 1 else false @@ -78,12 +78,12 @@ module SimulationCode = elif hasMultipleDefinitions() then true else - not (autoNamespaces |> List.contains op.Namespace.Value) + not (autoNamespaces |> List.contains op.Namespace) let getOpName context n = if isCurrentOp context n then Directives.Self elif needsFullPath context n then prependNamespaceString n - else n.Name.Value + "__" + else n.Name + "__" let getTypeParameters types = let findAll (t: ResolvedType) = t.ExtractAll (fun item -> item.Resolution |> function @@ -105,8 +105,8 @@ module SimulationCode = let hasTypeParameters types = not (getTypeParameters types).IsEmpty let justTheName context (n: QsQualifiedName) = - let name = userDefinedName None n.Name.Value - if needsFullPath context n then n.Namespace.Value + "." + name else name + let name = userDefinedName None n.Name + if needsFullPath context n then n.Namespace + "." + name else name let isGeneric context (n: QsQualifiedName) = if context.allCallables.ContainsKey n then @@ -166,7 +166,7 @@ module SimulationCode = |> sprintf "(%s)" and roslynTypeParameterName (t:QsTypeParameter) = - sprintf "__%s__" t.TypeName.Value + sprintf "__%s__" t.TypeName and roslynCallableInterfaceName characteristics = let (adj, ctrl) = characteristics.SupportedFunctors |> hasAdjointControlled @@ -178,7 +178,7 @@ module SimulationCode = and roslynCallableTypeName context (name:QsQualifiedName) = if not (context.allCallables.ContainsKey name) then - userDefinedName None name.Name.Value + userDefinedName None name.Name else let signature = context.allCallables.[name].Signature let tIn = signature.ArgumentType @@ -236,10 +236,10 @@ module SimulationCode = type StatementKindSeeker(parent : SyntaxTreeTransformation>) = inherit StatementKindTransformation>(parent, TransformationOptions.NoRebuild) - let ALLOCATE = { Name = "Allocate" |> NonNullable.New; Namespace = "Microsoft.Quantum.Intrinsic" |> NonNullable.New } - let RELEASE = { Name = "Release" |> NonNullable.New; Namespace = "Microsoft.Quantum.Intrinsic" |> NonNullable.New } - let BORROW = { Name = "Borrow" |> NonNullable.New; Namespace = "Microsoft.Quantum.Intrinsic" |> NonNullable.New } - let RETURN = { Name = "Return" |> NonNullable.New; Namespace = "Microsoft.Quantum.Intrinsic" |> NonNullable.New } + let ALLOCATE = { Name = "Allocate"; Namespace = "Microsoft.Quantum.Intrinsic" } + let RELEASE = { Name = "Release"; Namespace = "Microsoft.Quantum.Intrinsic" } + let BORROW = { Name = "Borrow"; Namespace = "Microsoft.Quantum.Intrinsic" } + let RETURN = { Name = "Return"; Namespace = "Microsoft.Quantum.Intrinsic" } override this.OnAllocateQubits node = this.SharedState.Add ALLOCATE |> ignore @@ -360,7 +360,7 @@ module SimulationCode = | ResultLiteral r -> (``ident`` "Result") <|.|> (``ident`` (match r with | Zero -> "Zero" | One -> "One")) | PauliLiteral p -> (``ident`` "Pauli") <|.|> (``ident`` (match p with | PauliI -> "PauliI" | PauliX -> "PauliX" | PauliY -> "PauliY" | PauliZ -> "PauliZ")) | Identifier (id,_) -> buildId id - | StringLiteral (s,e) -> buildInterpolatedString s.Value e + | StringLiteral (s,e) -> buildInterpolatedString s e | RangeLiteral (r,e) -> buildRange r e | NEG n -> ``-`` (buildExpression n) | NOT r -> ! (buildExpression r) @@ -415,8 +415,8 @@ module SimulationCode = let name' = match ex.ResolvedType.Resolution with | UserDefinedType udt -> - name.Value |> userDefinedName (Some { Namespace = udt.Namespace; Name = udt.Name }) - | _ -> name.Value + name |> userDefinedName (Some { Namespace = udt.Namespace; Name = udt.Name }) + | _ -> name buildExpression ex <|.|> ident name' | _ -> // TODO: Diagnostics @@ -435,7 +435,7 @@ module SimulationCode = and buildId id : ExpressionSyntax = match id with - | LocalVariable n -> n.Value |> ident :> ExpressionSyntax + | LocalVariable n -> n |> ident :> ExpressionSyntax | GlobalCallable n -> getOpName context n |> ident :> ExpressionSyntax | InvalidIdentifier -> // TODO: Diagnostics @@ -453,7 +453,7 @@ module SimulationCode = let isUserDefinedType = function | UserDefinedType _ -> true | _ -> false let getItemName = function - | Identifier (LocalVariable id, Null) -> id.Value + | Identifier (LocalVariable id, Null) -> id // TODO: Diagnostics | _ -> failwith "item access expression in copy-and-update expression for user defined type is not a suitable identifier" let updatedItems = new Dictionary() @@ -471,7 +471,7 @@ module SimulationCode = let items = getAllItems root decl.Type let rec buildArg = function | QsTuple args -> args |> Seq.map buildArg |> Seq.toList |> ``tuple`` - | QsTupleItem (Named item) -> updatedItems.TryGetValue item.VariableName.Value |> function + | QsTupleItem (Named item) -> updatedItems.TryGetValue item.VariableName |> function | true, rhs -> items.Dequeue() |> ignore rhs @@ -593,7 +593,7 @@ module SimulationCode = let rec buildOne = function // TODO: Diagnostics | InvalidItem -> failwith ("InvalidItem received") - | VariableName one -> one.Value |> buildSymbol + | VariableName one -> one |> buildSymbol | VariableNameTuple many -> many |> Seq.map buildOne |> Seq.toList |> buildTuple | DiscardedItem -> "_" |> buildSymbol // While _ inside C# tuple destructs will properly discard the assignment, @@ -654,10 +654,10 @@ module SimulationCode = | VariableName varName -> match node.Rhs.ResolvedType.Resolution |> QArrayType with | Some _ when isArrayInit node.Rhs -> // avoid unnecessary copies on construction - ``var`` varName.Value (``:=`` <| rhs ) |> this.AddStatement + ``var`` varName (``:=`` <| rhs ) |> this.AddStatement | Some arrType -> // we need to make sure to bind to a new QArray instance here let qArray = ``new`` arrType ``(`` [rhs] ``)`` - ``var`` varName.Value (``:=`` <| qArray ) |> this.AddStatement + ``var`` varName (``:=`` <| qArray ) |> this.AddStatement | _ -> buildBinding id // we first need to destruct here, and then make sure all QArrays are built @@ -669,7 +669,7 @@ module SimulationCode = // build the actual binding, making sure all necessary QArrays instances are created for localVar in parent.DeclarationsInStatement.Variables do - let varName = localVar.VariableName.Value + let varName = localVar.VariableName match localVar.Type.Resolution |> QArrayType with | Some arrType -> let qArray = ``new`` arrType ``(`` [``ident`` (imName varName)] ``)`` @@ -683,7 +683,7 @@ module SimulationCode = let rec varNames onTuple onItem (ex : TypedExpression) = match ex.Expression with | MissingExpr -> onItem "_" - | Identifier (LocalVariable id, Null) -> onItem id.Value + | Identifier (LocalVariable id, Null) -> onItem id | ValueTuple vs -> vs |> Seq.map (varNames onTuple onItem) |> onTuple // TODO: diagnostics. | _ -> failwith "unexpected expression in lhs of value update" @@ -696,7 +696,7 @@ module SimulationCode = | Identifier (LocalVariable id, Null) -> let matchesIdentifier (ex : TypedExpression) = match ex.Expression with - | Identifier (LocalVariable rhsId, Null) when rhsId.Value = id.Value -> true + | Identifier (LocalVariable rhsId, Null) when rhsId = id -> true | _ -> false let isArray = function | ArrayType _ -> true | _ -> false match node.Rhs.Expression with @@ -723,7 +723,7 @@ module SimulationCode = // build the actual binding, making sure all necessary QArrays instances are created let ids = varNames (Seq.collect id) (fun id -> seq{ if id <> "_" then yield id}) node.Lhs for id in ids do - let decl = parent.DeclarationsInScope.Variables |> Seq.tryFind (fun d -> d.VariableName.Value = id) + let decl = parent.DeclarationsInScope.Variables |> Seq.tryFind (fun d -> d.VariableName = id) match decl |> Option.map (fun d -> d.Type.Resolution |> QArrayType) |> Option.flatten with | Some arrType -> // we need to make sure to create a new QArray instance here let qArray = ``new`` arrType ``(`` [imName id |> ``ident``] ``)`` @@ -785,7 +785,7 @@ module SimulationCode = let rec removeDiscarded sym = match sym with | VariableName _ -> sym - | DiscardedItem -> nextArgName() |> NonNullable.New |> VariableName + | DiscardedItem -> nextArgName() |> VariableName | VariableNameTuple many -> many |> Seq.map removeDiscarded |> ImmutableArray.CreateRange |> VariableNameTuple | InvalidItem -> failwith ("InvalidItem received") let rec buildInitializeExpression (exp:ResolvedInitializer) = @@ -808,9 +808,9 @@ module SimulationCode = | InvalidInitializer -> failwith ("InvalidInitializer received") let releases = match (symbol, expr.Resolution) with - | VariableName one, SingleQubitAllocation -> [ buildOne one.Value ] - | VariableName one, QubitRegisterAllocation _ -> [ buildOne one.Value ] - | VariableName one, QubitTupleAllocation _ -> (buildDeconstruct one.Value expr) + | VariableName one, SingleQubitAllocation -> [ buildOne one ] + | VariableName one, QubitRegisterAllocation _ -> [ buildOne one ] + | VariableName one, QubitTupleAllocation _ -> (buildDeconstruct one expr) | VariableNameTuple ss, QubitTupleAllocation aa -> Seq.zip ss aa |> Seq.map buildReleaseExpression |> Seq.toList |> List.concat | _ -> failwith ("InvalidItem received") parent.LineNumber <- currentLine @@ -872,8 +872,8 @@ module SimulationCode = let sameNamespace = match context.current with | None -> false | Some o -> o.Namespace = n.Namespace let opName = if sameNamespace - then userDefinedName None n.Name.Value - else "global::" + n.Namespace.Value + "." + userDefinedName None n.Name.Value + then userDefinedName None n.Name + else "global::" + n.Namespace + "." + userDefinedName None n.Name if isGeneric context n then let signature = context.allCallables.[n].Signature let count = signature.TypeParameters.Length @@ -978,7 +978,7 @@ module SimulationCode = [] let (argName, argsInit) = //TODO: diagnostics. - let name = function | ValidName n -> n.Value | InvalidName -> "" + let name = function | ValidName n -> n | InvalidName -> "" let rec buildVariableName = function | QsTupleItem one -> one.VariableName |> name | QsTuple many -> "(" + (many |> Seq.map buildVariableName |> String.concat ",") + ")" @@ -1029,7 +1029,7 @@ module SimulationCode = //TODO: diagnostics. | false, _ -> startLine ``attribute`` None (``ident`` "SourceLocation") [ - ``literal`` sp.SourceFile.Value + ``literal`` sp.SourceFile ``ident`` "OperationFunctor" <|.|> ``ident`` bodyName ``literal`` startLine ``literal`` endLine @@ -1052,7 +1052,7 @@ module SimulationCode = let rec flatOne found = function | QsTupleItem one -> match one.VariableName with - | ValidName n -> found @ [n.Value, one.Type |> roslynTypeName context] + | ValidName n -> found @ [n, one.Type |> roslynTypeName context] | InvalidName -> found | QsTuple many -> many |> Seq.fold flatOne found @@ -1064,7 +1064,7 @@ module SimulationCode = let rec buildTuple = function | QsTupleItem one -> match one.VariableName with - | ValidName n -> mapping (n.Value, roslynTypeName context one.Type) :> ExpressionSyntax + | ValidName n -> mapping (n, roslynTypeName context one.Type) :> ExpressionSyntax | InvalidName -> mapping ("", roslynTypeName context one.Type) :> ExpressionSyntax | QsTuple many -> many |> Seq.map buildTuple |> List.ofSeq |> ``tuple`` @@ -1219,8 +1219,8 @@ module SimulationCode = let buildFullName (name : QsQualifiedName) = let fqn = - let ns = name.Namespace.Value - let n = name.Name.Value + let ns = name.Namespace + let n = name.Name if ns = "" then n else ns + "." + n ``property-arrow_get`` "String" "ICallable.FullName" [ ] ``get`` (``=>`` (``literal`` fqn) ) @@ -1274,7 +1274,7 @@ module SimulationCode = ``attributes`` [ ``attribute`` None (``ident`` "Xunit.Fact") []; - ``attribute`` None (``ident`` "Xunit.Trait") [``literal`` "Target"; ``literal`` targetName.Name.Value] + ``attribute`` None (``ident`` "Xunit.Trait") [``literal`` "Target"; ``literal`` targetName.Name] ``attribute`` None (``ident`` "Xunit.Trait") [``literal`` "Name"; ``literal`` opName] ] (``method`` "void" opName ``<<`` [] ``>>`` ``(`` [] ``)`` [``public``] @@ -1327,11 +1327,11 @@ module SimulationCode = let typeParametersNames signature = // TODO Diagnostics - let name = function | ValidName n -> sprintf "__%s__" n.Value | InvalidName -> "__" + let name = function | ValidName n -> sprintf "__%s__" n | InvalidName -> "__" signature.TypeParameters |> Seq.map name |> Seq.sort |> Seq.toList let findClassName (op: QsCallable) = - let name = userDefinedName None op.FullName.Name.Value + let name = userDefinedName None op.FullName.Name let typeParameters = typeParametersNames op.Signature let nonGeneric = if typeParameters.IsEmpty then name else sprintf "%s<%s>" name (String.Join(",", typeParameters)) (name, nonGeneric) @@ -1344,9 +1344,9 @@ module SimulationCode = let buildTestClass (testTargets : QsQualifiedName list) (targetName : QsQualifiedName) opName (op : QsCallable) = let className = - let requiresQualification = (testTargets |> List.filter (fun t -> t.Name.Value = targetName.Name.Value)).Length > 1 - if requiresQualification then sprintf "%s_%s" (targetName.Namespace.Value.Replace('.', '_')) targetName.Name.Value - else targetName.Name.Value + let requiresQualification = (testTargets |> List.filter (fun t -> t.Name = targetName.Name)).Length > 1 + if requiresQualification then sprintf "%s_%s" (targetName.Namespace.Replace('.', '_')) targetName.Name + else targetName.Name let constructors = [ ``constructor`` className ``(`` [ (testOutputHandle, ``type`` outputHelperInterface) ] ``)`` @@ -1363,7 +1363,7 @@ module SimulationCode = let properties = buildOutput () let methods = match op.Location with - | Value location -> [ buildUnitTest targetName opName location.Offset.Line op.SourceFile.Value ] + | Value location -> [ buildUnitTest targetName opName location.Offset.Line op.SourceFile ] // TODO: diagnostics | Null -> failwith "missing location for unit test" @@ -1416,7 +1416,7 @@ module SimulationCode = let inData = (buildDataWrapper context "In" op.Signature.ArgumentType) let outData = (buildDataWrapper context "Out" op.Signature.ReturnType) - let defaultTargetNs = NonNullable<_>.New("Microsoft.Quantum.Simulation.Simulators") + let defaultTargetNs = "Microsoft.Quantum.Simulation.Simulators" let testTargets = op.Attributes |> SymbolResolution.TryFindTestTargets @@ -1424,8 +1424,8 @@ module SimulationCode = |> Seq.map (function | x when x.Contains(".") -> let indexOfDot = x.LastIndexOf('.') - {Namespace = NonNullable<_>.New(x.Substring(0, indexOfDot)); Name = NonNullable<_>.New(x.Substring(indexOfDot+1))} - | str -> {Namespace = defaultTargetNs; Name = NonNullable<_>.New(str)} ) + {Namespace = x.Substring(0, indexOfDot); Name = x.Substring(indexOfDot+1)} + | str -> {Namespace = defaultTargetNs; Name = str} ) |> Seq.sort |> Seq.toList @@ -1459,7 +1459,7 @@ module SimulationCode = let buildUdtClass (globalContext:CodegenContext) (udt: QsCustomType) = let context = globalContext.setUdt udt - let name = userDefinedName None udt.FullName.Name.Value + let name = userDefinedName None udt.FullName.Name let qsharpType = udt.Type let buildEmptyConstructor = let defaultValue = @@ -1483,10 +1483,10 @@ module SimulationCode = ``}`` :> MemberDeclarationSyntax let buildNamedItemFields = - let produceProperty (decl : LocalVariableDeclaration>) valueExpr = + let produceProperty (decl : LocalVariableDeclaration<_>) valueExpr = ``property-arrow_get`` (roslynTypeName context decl.Type) - (userDefinedName context.current decl.VariableName.Value) + (userDefinedName context.current decl.VariableName) [ ``public`` ] ``get`` (``=>`` valueExpr) :> MemberDeclarationSyntax let rec buildProps current = function @@ -1551,7 +1551,7 @@ module SimulationCode = :> MemberDeclarationSyntax // Generates the code for all the elements of the given namespace. - let buildNamespace globalContext (nsName : NonNullable, localElements : QsNamespaceElement list) = + let buildNamespace globalContext (nsName, localElements) = let buildOne = function | QsCallable op when op.Kind = TypeConstructor -> None | QsCustomType udt -> udt |> buildUdtClass globalContext |> Some @@ -1562,7 +1562,7 @@ module SimulationCode = |> List.choose id ``#line hidden`` <| - ``namespace`` nsName.Value + ``namespace`` nsName ``{`` [] (members) @@ -1604,7 +1604,7 @@ module SimulationCode = generator.Apply elements // Returns only those namespaces and their elements that are defined for the given file. - let findLocalElements selector (fileName : NonNullable) syntaxTree = + let findLocalElements selector (fileName : string) syntaxTree = syntaxTree |> Seq.map (fun ns -> (ns.Name, (FilterBySourceFile.Apply (ns, fileName)).Elements |> Seq.choose selector |> Seq.toList)) @@ -1654,7 +1654,7 @@ module SimulationCode = /// Builds the SyntaxTree for callables and types loaded via test names, /// formats it and returns it as a string. /// Returns null if no elements have been loaded via test name. - let loadedViaTestNames (dllName : NonNullable) (globalContext : CodegenContext) = + let loadedViaTestNames dllName (globalContext : CodegenContext) = let isLoadedViaTestName nsElement = if globalContext.ExposeReferencesViaTestNames then let asOption = function | Value _ -> Some nsElement | _ -> None @@ -1663,7 +1663,7 @@ module SimulationCode = | QsCustomType t -> SymbolResolution.TryGetTestName t.Attributes |> asOption else None - let context = {globalContext with fileName = Some dllName.Value} + let context = {globalContext with fileName = Some dllName} let localElements = findLocalElements isLoadedViaTestName dllName context.allQsElements let getNameCollisions (_, elems : QsNamespaceElement list) = @@ -1699,15 +1699,15 @@ module SimulationCode = /// Main entry method for a CodeGenerator. /// Builds the SyntaxTree for the given Q# syntax tree, formats it and returns it as a string. /// Omits code generation for intrinsic callables in references. - let generate (fileName : NonNullable) globalContext = + let generate fileName globalContext = let isIntrinsic = function | QsCallable c -> c.Signature.Information.InferredInformation.IsIntrinsic | QsCustomType _ -> false let filterIntrinsics (ns, elems) = ns, elems |> List.filter (not << isIntrinsic) - let context = {globalContext with fileName = Some fileName.Value} + let context = {globalContext with fileName = Some fileName} let localElements = let elements = findLocalElements Some fileName context.allQsElements - if fileName.Value.EndsWith ".dll" then elements |> List.map filterIntrinsics + if fileName.EndsWith ".dll" then elements |> List.map filterIntrinsics else elements buildSyntaxTree localElements context |> formatSyntaxTree diff --git a/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj b/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj index 36526c2956b..b2e7e439f0f 100644 --- a/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj +++ b/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj @@ -8,6 +8,7 @@ true false false + detailed From 56f0e63d3f5f51c1a8c446601d9972974e8c6062 Mon Sep 17 00:00:00 2001 From: Sarah Marshall Date: Sun, 8 Nov 2020 11:56:44 -0800 Subject: [PATCH 2/4] Update compiler packages --- .../SimulationCodeTests.fs | 20 +++++++++---------- .../Microsoft.Quantum.CsharpGeneration.fsproj | 2 +- .../EntryPointDriver.Tests/Tests.fs | 3 +-- ....Simulation.QCTraceSimulatorRuntime.csproj | 3 +-- .../Microsoft.Quantum.QSharp.Core.csproj | 3 +-- .../HoneywellExe/HoneywellExe.csproj | 2 +- .../IntrinsicTests/IntrinsicTests.csproj | 2 +- .../TestProjects/IonQExe/IonQExe.csproj | 2 +- .../Library with Spaces.csproj | 2 +- .../TestProjects/Library1/Library1.csproj | 2 +- .../TestProjects/Library2/Library2.csproj | 2 +- .../TestProjects/QCIExe/QCIExe.csproj | 2 +- .../TestProjects/QsharpExe/QsharpExe.csproj | 2 +- .../TargetedExe/TargetedExe.csproj | 2 +- .../TestProjects/UnitTests/UnitTests.csproj | 2 +- .../Tests.Microsoft.Quantum.Simulators.csproj | 2 +- .../Microsoft.Quantum.Simulators.csproj | 2 +- 17 files changed, 25 insertions(+), 30 deletions(-) diff --git a/src/Simulation/CsharpGeneration.Tests/SimulationCodeTests.fs b/src/Simulation/CsharpGeneration.Tests/SimulationCodeTests.fs index 8b28e6cc3d5..f62be54fc08 100644 --- a/src/Simulation/CsharpGeneration.Tests/SimulationCodeTests.fs +++ b/src/Simulation/CsharpGeneration.Tests/SimulationCodeTests.fs @@ -19,7 +19,6 @@ open Xunit open Microsoft.Quantum.QsCompiler.CompilationBuilder open Microsoft.Quantum.QsCompiler.CsharpGeneration open Microsoft.Quantum.QsCompiler.CsharpGeneration.SimulationCode -open Microsoft.Quantum.QsCompiler.DataTypes open Microsoft.Quantum.QsCompiler.ReservedKeywords open Microsoft.Quantum.QsCompiler.SyntaxTree @@ -116,13 +115,12 @@ namespace N1 let globalContext = CodegenContext.Create syntaxTree let findCallable name = - let key = NonNullable.New name - match globalContext.byName.TryGetValue key with + match globalContext.byName.TryGetValue name with | true, v -> v |> List.sort |> List.head | false, _ -> sprintf "no callable with name %s has been successfully compiled" name |> failwith let findUdt name = - let key = globalContext.allUdts.Keys |> Seq.sort |> Seq.find (fun n -> n.Name.Value = name) + let key = globalContext.allUdts.Keys |> Seq.sort |> Seq.find (fun n -> n.Name = name) match globalContext.allUdts.TryGetValue key with | true, v -> key.Namespace, v | false, _ -> sprintf "no type with name %s has been successfully compiled" name |> failwith @@ -229,7 +227,7 @@ namespace N1 let tree = parse [Path.Combine ("Circuits", "Intrinsic.qs"); fileName] let actual = CodegenContext.Create (tree, ImmutableDictionary.Empty) - |> generate (Path.GetFullPath fileName |> NonNullable.New) + |> generate (Path.GetFullPath fileName) Assert.Equal(expected |> clearFormatting, actual |> clearFormatting) let testOneBody (builder:SyntaxBuilder) (expected: string list) = @@ -297,7 +295,7 @@ namespace N1 let actual = op |> operationDependencies - |> List.map (fun n -> ((n.Namespace.Value, n.Name.Value), (n |> roslynCallableTypeName context))) + |> List.map (fun n -> ((n.Namespace, n.Name), (n |> roslynCallableTypeName context))) List.zip (expected |> sortByNames) (actual |> sortByNames) |> List.iter Assert.Equal @@ -853,7 +851,7 @@ namespace N1 |> testOne nestedArgTuple2 - let depsByName (l : QsQualifiedName list) = l |> List.sortBy (fun n -> n.Namespace.Value) |> List.sortBy (fun n -> n.Name.Value) + let depsByName (l : QsQualifiedName list) = l |> List.sortBy (fun n -> n.Namespace) |> List.sortBy (fun n -> n.Name) [] let ``buildInit test`` () = @@ -2333,7 +2331,7 @@ namespace N1 false |> testOne randomOperation let testOneClass (_,op : QsCallable) executionTarget (expected : string) = - let expected = expected.Replace("%%%", HttpUtility.JavaScriptStringEncode op.SourceFile.Value) + let expected = expected.Replace("%%%", HttpUtility.JavaScriptStringEncode op.SourceFile) let assemblyConstants = new Collections.Generic.KeyValuePair<_,_> (AssemblyConstants.ProcessorArchitecture, executionTarget) |> Seq.singleton @@ -3388,11 +3386,11 @@ namespace Microsoft.Quantum [] let ``find local elements `` () = - let oneName = function | QsCustomType udt -> udt.FullName.Name.Value | QsCallable op -> op.FullName.Name.Value + let oneName = function | QsCustomType udt -> udt.FullName.Name | QsCallable op -> op.FullName.Name let expected = [ "H"; "M"; "Qubits"; "Qubits"; "R"; "S"; "X"; "Z"; ] // Qubits is two times: one for UDT and one for constructor. - let local = syntaxTree |> findLocalElements Some (Path.GetFullPath (Path.Combine("Circuits","Intrinsic.qs")) |> NonNullable.New) + let local = syntaxTree |> findLocalElements Some (Path.GetFullPath (Path.Combine("Circuits","Intrinsic.qs"))) Assert.Equal(1, local.Length) - Assert.Equal("Microsoft.Quantum.Intrinsic", (fst local.[0]).Value) + Assert.Equal("Microsoft.Quantum.Intrinsic", (fst local.[0])) let actual = (snd local.[0]) |> List.map oneName |> List.sort List.zip expected actual |> List.iter Assert.Equal diff --git a/src/Simulation/CsharpGeneration/Microsoft.Quantum.CsharpGeneration.fsproj b/src/Simulation/CsharpGeneration/Microsoft.Quantum.CsharpGeneration.fsproj index af3730c200d..be39b8edeab 100644 --- a/src/Simulation/CsharpGeneration/Microsoft.Quantum.CsharpGeneration.fsproj +++ b/src/Simulation/CsharpGeneration/Microsoft.Quantum.CsharpGeneration.fsproj @@ -22,7 +22,7 @@ - + diff --git a/src/Simulation/EntryPointDriver.Tests/Tests.fs b/src/Simulation/EntryPointDriver.Tests/Tests.fs index 99bafc265f3..1f4283e860e 100644 --- a/src/Simulation/EntryPointDriver.Tests/Tests.fs +++ b/src/Simulation/EntryPointDriver.Tests/Tests.fs @@ -18,7 +18,6 @@ open Xunit open Microsoft.Quantum.QsCompiler.CompilationBuilder open Microsoft.Quantum.QsCompiler.CsharpGeneration -open Microsoft.Quantum.QsCompiler.DataTypes open Microsoft.Quantum.QsCompiler.ReservedKeywords open Microsoft.Quantum.QsCompiler.SyntaxTree open Microsoft.Quantum.Simulation.Simulators @@ -73,7 +72,7 @@ let private generateCSharp constants (compilation : QsCompilation) = let context = CodegenContext.Create (compilation, constants) let entryPoint = context.allCallables.[Seq.exactlyOne compilation.EntryPoints] [ - SimulationCode.generate (NonNullable<_>.New testFile) context + SimulationCode.generate testFile context EntryPoint.generate context entryPoint ] diff --git a/src/Simulation/QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj b/src/Simulation/QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj index 385e3f72955..4be621628ae 100644 --- a/src/Simulation/QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj +++ b/src/Simulation/QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj @@ -1,4 +1,4 @@ - + @@ -22,4 +22,3 @@ - diff --git a/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj b/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj index b2e7e439f0f..aa56561c174 100644 --- a/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj +++ b/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj @@ -1,4 +1,4 @@ - + @@ -42,4 +42,3 @@ - diff --git a/src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/HoneywellExe.csproj b/src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/HoneywellExe.csproj index 1c6c0ca6ff1..12fd65d55b0 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/HoneywellExe.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/HoneywellExe.csproj @@ -1,4 +1,4 @@ - + Library diff --git a/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj b/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj index 0ac78267fc2..e0ac7e6c07c 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj @@ -1,4 +1,4 @@ - + netcoreapp3.1 diff --git a/src/Simulation/Simulators.Tests/TestProjects/IonQExe/IonQExe.csproj b/src/Simulation/Simulators.Tests/TestProjects/IonQExe/IonQExe.csproj index a6ce0a7ac4c..4a49760ae8e 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/IonQExe/IonQExe.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/IonQExe/IonQExe.csproj @@ -1,4 +1,4 @@ - + Library diff --git a/src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library with Spaces.csproj b/src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library with Spaces.csproj index c9ac1c5b763..f98e674ef78 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library with Spaces.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library with Spaces.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 false diff --git a/src/Simulation/Simulators.Tests/TestProjects/Library1/Library1.csproj b/src/Simulation/Simulators.Tests/TestProjects/Library1/Library1.csproj index df6982c8806..af6733c8685 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/Library1/Library1.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/Library1/Library1.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 diff --git a/src/Simulation/Simulators.Tests/TestProjects/Library2/Library2.csproj b/src/Simulation/Simulators.Tests/TestProjects/Library2/Library2.csproj index df6982c8806..af6733c8685 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/Library2/Library2.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/Library2/Library2.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 diff --git a/src/Simulation/Simulators.Tests/TestProjects/QCIExe/QCIExe.csproj b/src/Simulation/Simulators.Tests/TestProjects/QCIExe/QCIExe.csproj index 25f9c944593..57ad5f9a890 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/QCIExe/QCIExe.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/QCIExe/QCIExe.csproj @@ -1,4 +1,4 @@ - + Library diff --git a/src/Simulation/Simulators.Tests/TestProjects/QsharpExe/QsharpExe.csproj b/src/Simulation/Simulators.Tests/TestProjects/QsharpExe/QsharpExe.csproj index c1f7e32dd60..c27439aab8f 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/QsharpExe/QsharpExe.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/QsharpExe/QsharpExe.csproj @@ -1,4 +1,4 @@ - + Exe diff --git a/src/Simulation/Simulators.Tests/TestProjects/TargetedExe/TargetedExe.csproj b/src/Simulation/Simulators.Tests/TestProjects/TargetedExe/TargetedExe.csproj index 7e3f9d41998..a6397927088 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/TargetedExe/TargetedExe.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/TargetedExe/TargetedExe.csproj @@ -1,4 +1,4 @@ - + Exe diff --git a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj b/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj index 927e6f19089..4445e69a21b 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj @@ -1,4 +1,4 @@ - + netcoreapp3.1 diff --git a/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj b/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj index 093d36e4e83..9b6aa3d35a9 100644 --- a/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj +++ b/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj @@ -1,4 +1,4 @@ - + diff --git a/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj b/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj index 598b15cabc8..6fcc2a76321 100644 --- a/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj +++ b/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj @@ -1,4 +1,4 @@ - + From f5ce1ef10fd8db9ec18c732f94cc05d116a9fb0a Mon Sep 17 00:00:00 2001 From: Sarah Marshall Date: Sun, 8 Nov 2020 12:21:09 -0800 Subject: [PATCH 3/4] Bump minor version to 13 --- build/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/ci.yml b/build/ci.yml index b194fa64afd..afbfdec1aa4 100644 --- a/build/ci.yml +++ b/build/ci.yml @@ -10,7 +10,7 @@ pr: variables: Build.Major: 0 - Build.Minor: 11 + Build.Minor: 13 Drops.Dir: $(Build.ArtifactStagingDirectory)/drops Drop.Native: $(System.DefaultWorkingDirectory)/xplat From 050cdd9ae3adeb66ecac3f3595afaee02f052eb4 Mon Sep 17 00:00:00 2001 From: Sarah Marshall <33814365+samarsha@users.noreply.github.com> Date: Thu, 12 Nov 2020 11:48:29 -0800 Subject: [PATCH 4/4] Update minor version to 14 --- build/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/ci.yml b/build/ci.yml index afbfdec1aa4..929dacad46c 100644 --- a/build/ci.yml +++ b/build/ci.yml @@ -10,7 +10,7 @@ pr: variables: Build.Major: 0 - Build.Minor: 13 + Build.Minor: 14 Drops.Dir: $(Build.ArtifactStagingDirectory)/drops Drop.Native: $(System.DefaultWorkingDirectory)/xplat