From 249cb0f19cf80499aed9efca6245afdac05516f3 Mon Sep 17 00:00:00 2001 From: Chris Granade Date: Thu, 20 Aug 2020 22:53:33 -0700 Subject: [PATCH 1/2] Write displayable diagnostics to console by default. (#348) --- src/Simulation/Common/SimulatorBase.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Simulation/Common/SimulatorBase.cs b/src/Simulation/Common/SimulatorBase.cs index bdb125468bf..849e0a82d1c 100644 --- a/src/Simulation/Common/SimulatorBase.cs +++ b/src/Simulation/Common/SimulatorBase.cs @@ -181,6 +181,7 @@ public virtual Task Run(I args) where T : AbstractCallable, ICallabl public void EnableLogToConsole() { OnLog += Console.WriteLine; + OnDisplayableDiagnostic += Console.WriteLine; } @@ -190,6 +191,7 @@ public void EnableLogToConsole() public void DisableLogToConsole() { OnLog -= Console.WriteLine; + OnDisplayableDiagnostic -= Console.WriteLine; } /// From 7385c62c18f2c3b391b624a61e7ca64ec6939c89 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Mon, 24 Aug 2020 12:31:04 -0700 Subject: [PATCH 2/2] Skip Csharp Generation of references with test names if not using test name (#355) * Only generate C# for reference when using testname This change makse it so that C# generation for references that have a test name attribute only happens when loading via test names is requested. * Update compiler version * Update src/Simulation/CsharpGeneration/SimulationCode.fs Remove unused `e` variable. Co-authored-by: Scott Carda <55811729+ScottCarda-MS@users.noreply.github.com> Co-authored-by: Scott Carda <55811729+ScottCarda-MS@users.noreply.github.com> --- NOTICE.txt | 2 +- src/Simulation/CsharpGeneration/Context.fs | 5 +++++ .../Microsoft.Quantum.CsharpGeneration.fsproj | 2 +- src/Simulation/CsharpGeneration/SimulationCode.fs | 14 ++++++++------ ...antum.Simulation.QCTraceSimulatorRuntime.csproj | 2 +- .../Microsoft.Quantum.QSharp.Core.csproj | 2 +- .../TestProjects/HoneywellExe/HoneywellExe.csproj | 2 +- .../IntrinsicTests/IntrinsicTests.csproj | 2 +- .../TestProjects/IonQExe/IonQExe.csproj | 2 +- .../Library with Spaces/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 +- .../TestProjects/TargetedExe/TargetedExe.csproj | 2 +- .../TestProjects/UnitTests/UnitTests.csproj | 2 +- .../Tests.Microsoft.Quantum.Simulators.csproj | 2 +- .../Simulators/Microsoft.Quantum.Simulators.csproj | 2 +- 18 files changed, 29 insertions(+), 22 deletions(-) diff --git a/NOTICE.txt b/NOTICE.txt index 98ac8599c49..ea1fd3063d2 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -2715,7 +2715,7 @@ SOFTWARE. ------------------------------------------------------------------- -Microsoft.Quantum.Compiler 0.12.20072031 - MIT +Microsoft.Quantum.Compiler 0.12.20082209-beta - MIT (c) 2008 VeriSign, Inc. diff --git a/src/Simulation/CsharpGeneration/Context.fs b/src/Simulation/CsharpGeneration/Context.fs index fa80c982c4f..514a7636577 100644 --- a/src/Simulation/CsharpGeneration/Context.fs +++ b/src/Simulation/CsharpGeneration/Context.fs @@ -119,6 +119,11 @@ type CodegenContext = { | true, name -> name | false, _ -> null + member public this.ExposeReferencesViaTestNames = + match this.assemblyConstants.TryGetValue AssemblyConstants.ExposeReferencesViaTestNames with + | true, propVal -> propVal = "true" + | false, _ -> false + member internal this.GenerateCodeForSource (fileName : NonNullable) = let targetsQuantumProcessor = match this.assemblyConstants.TryGetValue AssemblyConstants.ProcessorArchitecture with diff --git a/src/Simulation/CsharpGeneration/Microsoft.Quantum.CsharpGeneration.fsproj b/src/Simulation/CsharpGeneration/Microsoft.Quantum.CsharpGeneration.fsproj index dddbbf8c3bb..65b75b2e1df 100644 --- a/src/Simulation/CsharpGeneration/Microsoft.Quantum.CsharpGeneration.fsproj +++ b/src/Simulation/CsharpGeneration/Microsoft.Quantum.CsharpGeneration.fsproj @@ -21,7 +21,7 @@ - + diff --git a/src/Simulation/CsharpGeneration/SimulationCode.fs b/src/Simulation/CsharpGeneration/SimulationCode.fs index dd853127c13..8b2b10ebfd5 100644 --- a/src/Simulation/CsharpGeneration/SimulationCode.fs +++ b/src/Simulation/CsharpGeneration/SimulationCode.fs @@ -1619,13 +1619,15 @@ 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 = + let loadedViaTestNames (dllName : NonNullable) (globalContext : CodegenContext) = let isLoadedViaTestName nsElement = - let asOption = function | Value _ -> Some nsElement | _ -> None - match nsElement with - | QsCallable c as e -> SymbolResolution.TryGetTestName c.Attributes - | QsCustomType t as e -> SymbolResolution.TryGetTestName t.Attributes - |> asOption + if globalContext.ExposeReferencesViaTestNames then + let asOption = function | Value _ -> Some nsElement | _ -> None + match nsElement with + | QsCallable c -> SymbolResolution.TryGetTestName c.Attributes + | QsCustomType t -> SymbolResolution.TryGetTestName t.Attributes + |> asOption + else None let context = {globalContext with fileName = Some dllName.Value} let localElements = findLocalElements isLoadedViaTestName dllName context.allQsElements 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 74cf526a2da..a7d91377dcd 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 @@ - + diff --git a/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj b/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj index d6c929018e1..610567a3181 100644 --- a/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj +++ b/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj @@ -1,4 +1,4 @@ - + diff --git a/src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/HoneywellExe.csproj b/src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/HoneywellExe.csproj index 2556f1ae507..cb464f8c01d 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 4fbf6b19d13..71bd465814e 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 c625e48ab23..a7745b792ef 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 f8f5cffa07f..6cce3506ac6 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 2714be57fcf..426f60111e2 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 2714be57fcf..426f60111e2 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 dce291568b6..3bee22e3534 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 6ac84ace635..d6401020995 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 f70061d4f60..b8f0258e5c2 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 ee89aad55fd..7cc66e81104 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 01ba825325e..ed018f6a6f2 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 794bb15909b..ef8c2bb42b6 100644 --- a/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj +++ b/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj @@ -1,4 +1,4 @@ - +