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
2 changes: 1 addition & 1 deletion build/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pr:

variables:
Build.Major: 0
Build.Minor: 11
Build.Minor: 14
Drops.Dir: $(Build.ArtifactStagingDirectory)/drops
Drop.Native: $(System.DefaultWorkingDirectory)/xplat

Expand Down
20 changes: 9 additions & 11 deletions src/Simulation/CsharpGeneration.Tests/SimulationCodeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -116,13 +115,12 @@ namespace N1
let globalContext = CodegenContext.Create syntaxTree

let findCallable name =
let key = NonNullable<string>.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
Expand Down Expand Up @@ -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<string>.New)
|> generate (Path.GetFullPath fileName)
Assert.Equal(expected |> clearFormatting, actual |> clearFormatting)

let testOneBody (builder:SyntaxBuilder) (expected: string list) =
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

[<Fact>]
let ``buildInit test`` () =
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -3388,11 +3386,11 @@ namespace Microsoft.Quantum

[<Fact>]
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<string>.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

Expand Down
16 changes: 8 additions & 8 deletions src/Simulation/CsharpGeneration/Context.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ module internal DeclarationLocations =
type TransformationState() =

member val internal CurrentSource = null with get, set
member val internal DeclarationLocations = new List<NonNullable<string> * Position>()
member val internal DeclarationLocations = new List<string * Position>()

type NamespaceTransformation(parent : SyntaxTreeTransformation<TransformationState>) =
inherit NamespaceTransformation<TransformationState>(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<string>.New this.SharedState.CurrentSource, loc.Offset)
this.SharedState.DeclarationLocations.Add (this.SharedState.CurrentSource, loc.Offset)
| _ -> ()
sourceLocation

Expand Down Expand Up @@ -60,8 +60,8 @@ type CodegenContext = {
allQsElements : IEnumerable<QsNamespace>
allUdts : ImmutableDictionary<QsQualifiedName,QsCustomType>
allCallables : ImmutableDictionary<QsQualifiedName,QsCallable>
declarationPositions : ImmutableDictionary<NonNullable<string>, ImmutableSortedSet<Position>>
byName : ImmutableDictionary<NonNullable<string>,(NonNullable<string>*QsCallable) list>
declarationPositions : ImmutableDictionary<string, ImmutableSortedSet<Position>>
byName : ImmutableDictionary<string, (string * QsCallable) list>
current : QsQualifiedName option
signature : ResolvedSignature option
fileName : string option
Expand All @@ -73,7 +73,7 @@ type CodegenContext = {
let callables = GlobalCallableResolutions syntaxTree
let positionInfos = DeclarationLocations.Accumulate syntaxTree
let callablesByName =
let result = new Dictionary<NonNullable<string>,(NonNullable<string>*QsCallable) list>()
let result = new Dictionary<string, (string * QsCallable) list>()
syntaxTree |> Seq.collect (fun ns -> ns.Elements |> Seq.choose (function
| QsCallable c -> Some (ns, c)
| _ -> None))
Expand Down Expand Up @@ -124,10 +124,10 @@ type CodegenContext = {
| true, propVal -> propVal = "true"
| false, _ -> false

member internal this.GenerateCodeForSource (fileName : NonNullable<string>) =
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

10 changes: 5 additions & 5 deletions src/Simulation/CsharpGeneration/EntryPoint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<ItemGroup>
<PackageReference Update="FSharp.Core" Version="4.7.0" />
<PackageReference Include="Microsoft.Quantum.Compiler" Version="0.13.20102604" />
<PackageReference Include="Microsoft.Quantum.Compiler" Version="0.13.2011.802-alpha" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading