diff --git a/images/iqsharp-base/Dockerfile b/images/iqsharp-base/Dockerfile index 9c404ccc85..d54c5e8984 100644 --- a/images/iqsharp-base/Dockerfile +++ b/images/iqsharp-base/Dockerfile @@ -109,7 +109,7 @@ ENV PATH=$PATH:${HOME}/dotnet:${HOME}/.dotnet/tools \ # Install IQ# and the project templates, using the NuGet packages from the # build context. ARG IQSHARP_VERSION -RUN dotnet new -i "Microsoft.Quantum.ProjectTemplates::0.12.20082515-beta" && \ +RUN dotnet new -i "Microsoft.Quantum.ProjectTemplates::0.12.20101601-beta" && \ dotnet tool install \ --global \ Microsoft.Quantum.IQSharp \ diff --git a/src/AzureClient/AzureClient.csproj b/src/AzureClient/AzureClient.csproj index 77e65a5e55..87a8793ac0 100644 --- a/src/AzureClient/AzureClient.csproj +++ b/src/AzureClient/AzureClient.csproj @@ -13,7 +13,7 @@ - + diff --git a/src/Core/Compiler/CompilerService.cs b/src/Core/Compiler/CompilerService.cs index d04c059478..606febf1cc 100644 --- a/src/Core/Compiler/CompilerService.cs +++ b/src/Core/Compiler/CompilerService.cs @@ -111,7 +111,7 @@ public IEnumerable IdentifyElements(string source) return loader.VerifiedCompilation.Tokenization.Values .SelectMany(tokens => tokens.SelectMany(fragments => fragments)) .Where(fragment => fragment.Kind != null && fragment.Kind.IsOpenDirective) - .Select(fragment => ((QsFragmentKind.OpenDirective)fragment.Kind)) + .Select(fragment => ((QsFragmentKind.OpenDirective)fragment.Kind!)) .Where(openDirective => !string.IsNullOrEmpty(openDirective.Item1.Symbol?.AsDeclarationName(null))) .ToDictionary( openDirective => openDirective.Item1.Symbol.AsDeclarationName(null), @@ -126,9 +126,9 @@ public IEnumerable IdentifyElements(string source) /// if the keys of the given references differ from the currently loaded ones. /// Returns an enumerable of all namespaces, including the content from both source files and references. /// - private QsCompilation UpdateCompilation( + private QsCompilation? UpdateCompilation( ImmutableDictionary sources, - QsReferences? references = null, + QsReferences references, QSharpLogger? logger = null, bool compileAsExecutable = false, string? executionTarget = null, @@ -186,15 +186,15 @@ string WrapInNamespace(Snippet s) => var sources = snippets.ToImmutableDictionary(s => s.Uri, WrapInNamespace); // Ignore some warnings about already-open namespaces and aliases when compiling snippets. - var errorCodesToIgnore = new List() + var warningCodesToIgnore = new List() { - QsCompiler.Diagnostics.ErrorCode.TypeRedefinition, - QsCompiler.Diagnostics.ErrorCode.TypeConstructorOverlapWithCallable, + QsCompiler.Diagnostics.WarningCode.NamespaceAleadyOpen, + QsCompiler.Diagnostics.WarningCode.NamespaceAliasIsAlreadyDefined, }; - errorCodesToIgnore.ForEach(code => logger.ErrorCodesToIgnore.Add(code)); + warningCodesToIgnore.ForEach(code => logger.WarningCodesToIgnore.Add(code)); var assembly = BuildAssembly(sources, metadatas, logger, dllName, compileAsExecutable: false, executionTarget, runtimeCapabilities); - errorCodesToIgnore.ForEach(code => logger.ErrorCodesToIgnore.Remove(code)); + warningCodesToIgnore.ForEach(code => logger.WarningCodesToIgnore.Remove(code)); return assembly; } @@ -218,11 +218,11 @@ string WrapInNamespace(Snippet s) => logger.LogDebug($"Compiling the following Q# files: {string.Join(",", sources.Keys.Select(f => f.LocalPath))}"); // Ignore any @EntryPoint() attributes found in libraries. - logger.ErrorCodesToIgnore.Add(QsCompiler.Diagnostics.ErrorCode.EntryPointInLibrary); + logger.WarningCodesToIgnore.Add(QsCompiler.Diagnostics.WarningCode.EntryPointInLibrary); var qsCompilation = this.UpdateCompilation(sources, metadata.QsMetadatas, logger, compileAsExecutable, executionTarget, runtimeCapabilities); - logger.ErrorCodesToIgnore.Remove(QsCompiler.Diagnostics.ErrorCode.EntryPointInLibrary); + logger.WarningCodesToIgnore.Remove(QsCompiler.Diagnostics.WarningCode.EntryPointInLibrary); - if (logger.HasErrors) return null; + if (logger.HasErrors || qsCompilation == null) return null; try { diff --git a/src/Core/Core.csproj b/src/Core/Core.csproj index 10d044f83c..59af650833 100644 --- a/src/Core/Core.csproj +++ b/src/Core/Core.csproj @@ -38,9 +38,9 @@ - - - + + + diff --git a/src/Core/Loggers/QsharpLogger.cs b/src/Core/Loggers/QsharpLogger.cs index 0877f7b738..9808080066 100644 --- a/src/Core/Loggers/QsharpLogger.cs +++ b/src/Core/Loggers/QsharpLogger.cs @@ -5,7 +5,7 @@ using System.Linq; using Microsoft.Extensions.Logging; - +using Microsoft.Quantum.QsCompiler.CompilationBuilder; using LSP = Microsoft.VisualStudio.LanguageServer.Protocol; @@ -23,6 +23,7 @@ public class QSharpLogger : QsCompiler.Diagnostics.LogTracker public List Logs { get; } public List ErrorCodesToIgnore { get; } = new List(); + public List WarningCodesToIgnore { get; } = new List(); public QSharpLogger(ILogger logger, int lineNrOffset = 0) : base(lineNrOffset : lineNrOffset) @@ -75,7 +76,8 @@ public static LogLevel MapLevel(LSP.DiagnosticSeverity original) protected override void Print(LSP.Diagnostic m) { - if (ErrorCodesToIgnore.Any(code => m.Code == QsCompiler.CompilationBuilder.Errors.Code(code))) return; + if (m.IsError() && ErrorCodesToIgnore.Any(code => m.Code == QsCompiler.CompilationBuilder.Errors.Code(code))) return; + if (m.IsWarning() && WarningCodesToIgnore.Any(code => m.Code == QsCompiler.CompilationBuilder.Warnings.Code(code))) return; Logger?.Log(MapLevel(m.Severity), $"{m.Code}: {m.Message}"); Logs.Add(m); diff --git a/src/ExecutionPathTracer/ExecutionPathTracer.csproj b/src/ExecutionPathTracer/ExecutionPathTracer.csproj index 3ff0272f04..45dbefe99e 100644 --- a/src/ExecutionPathTracer/ExecutionPathTracer.csproj +++ b/src/ExecutionPathTracer/ExecutionPathTracer.csproj @@ -32,7 +32,7 @@ - + diff --git a/src/MockLibraries/Mock.Chemistry/Mock.Chemistry.csproj b/src/MockLibraries/Mock.Chemistry/Mock.Chemistry.csproj index dc42a75558..e4efa72599 100644 --- a/src/MockLibraries/Mock.Chemistry/Mock.Chemistry.csproj +++ b/src/MockLibraries/Mock.Chemistry/Mock.Chemistry.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -6,6 +6,6 @@ - + diff --git a/src/MockLibraries/Mock.Standard/Mock.Standard.csproj b/src/MockLibraries/Mock.Standard/Mock.Standard.csproj index dc42a75558..e4efa72599 100644 --- a/src/MockLibraries/Mock.Standard/Mock.Standard.csproj +++ b/src/MockLibraries/Mock.Standard/Mock.Standard.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -6,6 +6,6 @@ - + diff --git a/src/Tests/AzureClientEntryPointTests.cs b/src/Tests/AzureClientEntryPointTests.cs index 955938c32d..bb2ca80f39 100644 --- a/src/Tests/AzureClientEntryPointTests.cs +++ b/src/Tests/AzureClientEntryPointTests.cs @@ -6,15 +6,12 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Microsoft.Quantum.IQSharp; using Microsoft.Quantum.IQSharp.AzureClient; using Microsoft.Quantum.IQSharp.Common; -using Microsoft.Quantum.Runtime; using Microsoft.Quantum.Simulation.Common; -using Microsoft.Quantum.Simulation.Core; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Tests.IQSharp diff --git a/src/Tests/IQsharpEngineTests.cs b/src/Tests/IQsharpEngineTests.cs index dff9c36319..fb367f39d0 100644 --- a/src/Tests/IQsharpEngineTests.cs +++ b/src/Tests/IQsharpEngineTests.cs @@ -198,6 +198,18 @@ public async Task OpenAliasedNamespaces() await AssertSimulate(engine, "DependsOnAliasedNamespace", "Hello from DependsOnAliasedNamespace"); } + [TestMethod] + public async Task CompileApplyWithin() + { + var engine = Init(); + + // Compile: + await AssertCompile(engine, SNIPPETS.ApplyWithinBlock, "ApplyWithinBlock"); + + // Run: + await AssertSimulate(engine, "ApplyWithinBlock", "Within", "Apply", "Within"); + } + [TestMethod] public async Task Estimate() { diff --git a/src/Tests/SNIPPETS.cs b/src/Tests/SNIPPETS.cs index 482c65a159..e63d977d40 100644 --- a/src/Tests/SNIPPETS.cs +++ b/src/Tests/SNIPPETS.cs @@ -145,6 +145,28 @@ operation DependsOnAliasedNamespace() : Unit } "; + public static string ApplyWithinBlock = + @" + /// # Summary + /// Checks that within/apply block is properly compiled. + /// See https://github.com/microsoft/iqsharp/issues/266. + @EntryPoint() + operation ApplyWithinBlock() : Unit + { + using (q = Qubit()) + { + within { + H(q); + Message(""Within""); + } + apply { + X(q); + Message(""Apply""); + } + } + } +"; + public static string DependsOnWorkspace = @" /// # Summary diff --git a/src/Tests/Workspace.ProjectReferences.ProjectA/ProjectA.csproj b/src/Tests/Workspace.ProjectReferences.ProjectA/ProjectA.csproj index 7866bb90d1..9bfc09160c 100644 --- a/src/Tests/Workspace.ProjectReferences.ProjectA/ProjectA.csproj +++ b/src/Tests/Workspace.ProjectReferences.ProjectA/ProjectA.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 diff --git a/src/Tests/Workspace.ProjectReferences.ProjectB/ProjectB.csproj b/src/Tests/Workspace.ProjectReferences.ProjectB/ProjectB.csproj index 4520258c27..8acac4e7f0 100644 --- a/src/Tests/Workspace.ProjectReferences.ProjectB/ProjectB.csproj +++ b/src/Tests/Workspace.ProjectReferences.ProjectB/ProjectB.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 diff --git a/src/Tests/Workspace.ProjectReferences/Workspace.ProjectReferences.csproj b/src/Tests/Workspace.ProjectReferences/Workspace.ProjectReferences.csproj index 5c9ddf84e3..40683bb9da 100644 --- a/src/Tests/Workspace.ProjectReferences/Workspace.ProjectReferences.csproj +++ b/src/Tests/Workspace.ProjectReferences/Workspace.ProjectReferences.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -7,7 +7,7 @@ - + diff --git a/src/Tool/appsettings.json b/src/Tool/appsettings.json index 14df0082b2..1cf39c87c7 100644 --- a/src/Tool/appsettings.json +++ b/src/Tool/appsettings.json @@ -6,26 +6,26 @@ }, "AllowedHosts": "*", "DefaultPackageVersions": [ - "Microsoft.Quantum.Compiler::0.12.20082515-beta", + "Microsoft.Quantum.Compiler::0.12.20101601-beta", - "Microsoft.Quantum.CsharpGeneration::0.12.20082515-beta", - "Microsoft.Quantum.Development.Kit::0.12.20082515-beta", - "Microsoft.Quantum.Simulators::0.12.20082515-beta", - "Microsoft.Quantum.Xunit::0.12.20082515-beta", + "Microsoft.Quantum.CsharpGeneration::0.12.20101601-beta", + "Microsoft.Quantum.Development.Kit::0.12.20101601-beta", + "Microsoft.Quantum.Simulators::0.12.20101601-beta", + "Microsoft.Quantum.Xunit::0.12.20101601-beta", - "Microsoft.Quantum.Standard::0.12.20082515-beta", - "Microsoft.Quantum.Standard.Visualization::0.12.20082515-beta", - "Microsoft.Quantum.Chemistry::0.12.20082515-beta", - "Microsoft.Quantum.Chemistry.Jupyter::0.12.20082515-beta", - "Microsoft.Quantum.MachineLearning::0.12.20082515-beta", - "Microsoft.Quantum.Numerics::0.12.20082515-beta", + "Microsoft.Quantum.Standard::0.12.20101601-beta", + "Microsoft.Quantum.Standard.Visualization::0.12.20101601-beta", + "Microsoft.Quantum.Chemistry::0.12.20101601-beta", + "Microsoft.Quantum.Chemistry.Jupyter::0.12.20101601-beta", + "Microsoft.Quantum.MachineLearning::0.12.20101601-beta", + "Microsoft.Quantum.Numerics::0.12.20101601-beta", - "Microsoft.Quantum.Katas::0.12.20082515-beta", + "Microsoft.Quantum.Katas::0.12.20101601-beta", - "Microsoft.Quantum.Research::0.12.20082515-beta", + "Microsoft.Quantum.Research::0.12.20101601-beta", - "Microsoft.Quantum.Providers.IonQ::0.12.20082515-beta", - "Microsoft.Quantum.Providers.Honeywell::0.12.20082515-beta", - "Microsoft.Quantum.Providers.QCI::0.12.20082515-beta" + "Microsoft.Quantum.Providers.IonQ::0.12.20101601-beta", + "Microsoft.Quantum.Providers.Honeywell::0.12.20101601-beta", + "Microsoft.Quantum.Providers.QCI::0.12.20101601-beta" ] }