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
31 changes: 0 additions & 31 deletions .github/workflows/automerge.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,4 @@ src/ProjectTemplates/Quantum.Test1/.template.config/template.json
/src/VisualStudioExtension/QsharpHoneywellAppTemplate/HoneywellAppProjectTemplate.xml
/src/VisualStudioExtension/QsharpIonQAppTemplate/IonQAppProjectTemplate.xml
/examples/QIR/Emission/qir/*
src/QsCompiler/QirGeneration/QirGeneration.nuspec
3 changes: 3 additions & 0 deletions bootstrap.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,6 @@ Write-Host "##[info]Finding NuSpec references..."
Push-Location (Join-Path $PSScriptRoot 'src/QsCompiler/Compiler')
.\FindNuspecReferences.ps1;
Pop-Location
Push-Location (Join-Path $PSScriptRoot 'src/QsCompiler/QirGeneration')
.\FindNuspecReferences.ps1;
Pop-Location
5 changes: 4 additions & 1 deletion build/manifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ else {
$artifacts = @{
Packages = @(
"Microsoft.Quantum.Compiler",
"Microsoft.Quantum.DocumentationGenerator"
"Microsoft.Quantum.QirGeneration",
"Microsoft.Quantum.DocumentationGenerator",
"Microsoft.Quantum.ProjectTemplates",
"Microsoft.Quantum.Sdk"
) | ForEach-Object { Join-Path $Env:NUGET_OUTDIR "$_.$Env:NUGET_VERSION.nupkg" };
Expand All @@ -48,6 +49,8 @@ $artifacts = @{
".\src\QsCompiler\Optimizations\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.QsOptimizations.dll",
".\src\QsCompiler\SyntaxProcessor\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.QsSyntaxProcessor.dll",
".\src\QsCompiler\TextProcessor\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.QsTextProcessor.dll",
".\src\QsCompiler\QirGeneration\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.QirGeneration.dll",
".\src\QsCompiler\LlvmBindings\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.LlvmBindings.dll",
".\src\QsCompiler\Transformations\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.QsTransformations.dll",
".\src\QsCompiler\CommandLineTool\bin\$Env:BUILD_CONFIGURATION\netcoreapp3.1\qsc.dll",
".\src\QuantumSdk\Tools\BuildConfiguration\bin\$Env:BUILD_CONFIGURATION\netcoreapp3.1\Microsoft.Quantum.Sdk.BuildConfiguration.dll",
Expand Down
2 changes: 2 additions & 0 deletions build/pack.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ function Pack-Dotnet() {
$all_ok = $True

Publish-One '../src/QsCompiler/CommandLineTool/CommandLineTool.csproj'
Publish-One '../src/QsCompiler/LlvmBindings/LlvmBindings.csproj'
Publish-One '../src/QuantumSdk/Tools/BuildConfiguration/BuildConfiguration.csproj'
Publish-One '../src/QuantumSdk/Tools/DefaultEntryPoint/DefaultEntryPoint.csproj'

Pack-One '../src/QsCompiler/Compiler/Compiler.csproj' '-IncludeReferencedProjects'
Pack-One '../src/QsCompiler/QirGeneration/QirGeneration.csproj'
Pack-Dotnet '../src/Documentation/DocumentationGenerator/DocumentationGenerator.csproj'
Pack-One '../src/ProjectTemplates/Microsoft.Quantum.ProjectTemplates.nuspec'
Pack-One '../src/QuantumSdk/QuantumSdk.nuspec'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Quantum.Compiler" Version="0.14.2011120240" />
<PackageReference Include="Microsoft.Quantum.Compiler" Version="0.15.2103133969" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ internal NamespaceTransformation(ListIdentifiers parent)

private static QsCallable AddComments(QsCallable c, params string[] comments) =>
new QsCallable(
c.Kind, c.FullName, c.Attributes, c.Modifiers,
c.SourceFile, c.Location,
c.Kind, c.FullName, c.Attributes, c.Access,
c.Source, c.Location,
c.Signature, c.ArgumentTuple, c.Specializations,
c.Documentation, new QsComments(c.Comments.OpeningComments.AddRange(comments), c.Comments.ClosingComments));

Expand Down
2 changes: 1 addition & 1 deletion examples/CompilerExtensions/Demo/Demo.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.Quantum.Sdk/0.14.2011120240">
<Project Sdk="Microsoft.Quantum.Sdk/0.15.2103133969">

<PropertyGroup>
<QscVerbosity>Detailed</QscVerbosity>
Expand Down
2 changes: 1 addition & 1 deletion examples/QIR/Emission/Emission.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.Quantum.Sdk/0.15.210324373-alpha">
<Project Sdk="Microsoft.Quantum.Sdk/0.15.2103133969">

<PropertyGroup>
<QscVerbosity>Detailed</QscVerbosity>
Expand Down
19 changes: 10 additions & 9 deletions src/Documentation/DocumentationGenerator/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,16 @@ internal static Dictionary<string, ResolvedType> ToDictionaryOfDeclarations(this
$"'{typeParam.Item.TypeName}",
_ => type.Resolution.Tag switch
{
ResolvedTypeKind.Tags.BigInt => "[BigInt](xref:microsoft.quantum.lang-ref.bigint)",
ResolvedTypeKind.Tags.Bool => "[Bool](xref:microsoft.quantum.lang-ref.bool)",
ResolvedTypeKind.Tags.Double => "[Double](xref:microsoft.quantum.lang-ref.double)",
ResolvedTypeKind.Tags.Int => "[Int](xref:microsoft.quantum.lang-ref.int)",
ResolvedTypeKind.Tags.Pauli => "[Pauli](xref:microsoft.quantum.lang-ref.pauli)",
ResolvedTypeKind.Tags.Qubit => "[Qubit](xref:microsoft.quantum.lang-ref.qubit)",
ResolvedTypeKind.Tags.Range => "[Range](xref:microsoft.quantum.lang-ref.range)",
ResolvedTypeKind.Tags.String => "[String](xref:microsoft.quantum.lang-ref.string)",
ResolvedTypeKind.Tags.UnitType => "[Unit](xref:microsoft.quantum.lang-ref.unit)",
ResolvedTypeKind.Tags.BigInt => "[BigInt](xref:microsoft.quantum.qsharp.valueliterals#bigint-literals)",
ResolvedTypeKind.Tags.Bool => "[Bool](xref:microsoft.quantum.qsharp.valueliterals#bool-literals)",
ResolvedTypeKind.Tags.Double => "[Double](xref:microsoft.quantum.qsharp.valueliterals#double-literals)",
ResolvedTypeKind.Tags.Int => "[Int](xref:microsoft.quantum.qsharp.valueliterals#int-literals)",
ResolvedTypeKind.Tags.Pauli => "[Pauli](xref:microsoft.quantum.qsharp.valueliterals#pauli-literals)",
ResolvedTypeKind.Tags.Qubit => "[Qubit](xref:microsoft.quantum.qsharp.valueliterals#qubit-literals)",
ResolvedTypeKind.Tags.Range => "[Range](xref:microsoft.quantum.qsharp.valueliterals#range-literals)",
ResolvedTypeKind.Tags.String => "[String](xref:microsoft.quantum.qsharp.valueliterals#string-literals)",
ResolvedTypeKind.Tags.UnitType => "[Unit](xref:microsoft.quantum.qsharp.valueliterals#unit-literal)",
ResolvedTypeKind.Tags.Result => "[Result](xref:microsoft.quantum.qsharp.valueliterals#result-literal)",
ResolvedTypeKind.Tags.InvalidType => "__invalid__",
_ => $"__invalid<{type.Resolution.ToString()}>__",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<license type="expression">MIT</license>
<projectUrl>https://docs.microsoft.com/azure/quantum</projectUrl>
<icon>images\qdk-nuget-icon.png</icon>
<iconUrl>https://secure.gravatar.com/avatar/bd1f02955b2853ba0a3b1cdc2434e8ec.png</iconUrl>

<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>.NET Core templates pack for Q#, part of the Microsoft Quantum Development Kit.</description>
Expand All @@ -26,7 +26,6 @@

<files>
<file src="**" target="content" exclude="**\bin\**;**\obj\**;**\*.v.template;*.nuspec;*.png" />
<file src="..\..\build\assets\qdk-nuget-icon.png" target="images" />
</files>

</package>
4 changes: 4 additions & 0 deletions src/QsCompiler/CommandLineTool/CommandLineTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.6.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.6.0" />
<PackageReference Include="libLLVM.runtime.win-x64" Version="11.0.0" />
<PackageReference Include="libLLVM.runtime.osx-x64" Version="11.0.0" />
<PackageReference Include="libLLVM.runtime.ubuntu.20.04-x64" Version="11.0.0" />
<PackageReference Include="libLLVM.runtime.ubuntu.18.04-x64" Version="11.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
12 changes: 3 additions & 9 deletions src/QsCompiler/CommandLineTool/Commands/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,6 @@ public static IEnumerable<Example> UsageExamples
HelpText = "Specifies whether the compiler should emit a .NET Core dll containing the compiled Q# code.")]
public bool EmitDll { get; set; }

[Option(
"qir",
Required = false,
SetName = CodeMode,
HelpText = "Destination folder for the emitted QIR; only executable projects can be compiled into QIR.")]
public string QirOutputFolder { get; set; }

[Option(
"perf",
Required = false,
Expand Down Expand Up @@ -225,19 +218,20 @@ public static int Run(BuildOptions options, ConsoleLogger logger)
{
ProjectName = options.ProjectName,
AssemblyConstants = assemblyConstants,
ForceRewriteStepExecution = options.ForceRewriteStepExecution,
TargetPackageAssemblies = options.TargetSpecificDecompositions ?? Enumerable.Empty<string>(),
RuntimeCapability = options.RuntimeCapability,
SkipMonomorphization = options.RuntimeCapability == RuntimeCapability.FullComputation && options.QirOutputFolder == null,
SkipMonomorphization = options.SkipMonomorphization,
GenerateFunctorSupport = true,
SkipSyntaxTreeTrimming = options.TrimLevel == 0,
SkipConjugationInlining = options.TrimLevel == 0,
AttemptFullPreEvaluation = options.TrimLevel > 2,
BuildOutputFolder = options.OutputFolder ?? (usesPlugins ? "." : null),
DllOutputPath = options.EmitDll ? " " : null, // set to e.g. an empty space to generate the dll in the same location as the .bson file
IsExecutable = options.MakeExecutable,
RewriteStepAssemblies = options.Plugins?.Select(step => (step, (string?)null)) ?? ImmutableArray<(string, string)>.Empty,
EnableAdditionalChecks = false, // todo: enable debug mode?
ExposeReferencesViaTestNames = options.ExposeReferencesViaTestNames,
QirOutputFolder = options.QirOutputFolder
};

if (options.PerfOutputFolder != null)
Expand Down
4 changes: 3 additions & 1 deletion src/QsCompiler/CommandLineTool/Commands/Diagnose.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,13 @@ public static int Run(DiagnoseOptions options, ConsoleLogger logger)
var loadOptions = new CompilationLoader.Configuration
{
AssemblyConstants = assemblyConstants,
ForceRewriteStepExecution = options.ForceRewriteStepExecution,
TargetPackageAssemblies = options.TargetSpecificDecompositions ?? Enumerable.Empty<string>(),
RuntimeCapability = options.RuntimeCapability,
SkipMonomorphization = options.RuntimeCapability == RuntimeCapability.FullComputation,
SkipMonomorphization = options.SkipMonomorphization,
GenerateFunctorSupport = true,
SkipSyntaxTreeTrimming = options.TrimLevel == 0,
SkipConjugationInlining = options.TrimLevel == 0,
AttemptFullPreEvaluation = options.TrimLevel > 2,
IsExecutable = options.MakeExecutable,
RewriteStepAssemblies = options.Plugins?.Select(step => (step, (string?)null)) ?? ImmutableArray<(string, string)>.Empty,
Expand Down
60 changes: 53 additions & 7 deletions src/QsCompiler/CommandLineTool/LoadContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Loader;

namespace Microsoft.Quantum.QsCompiler
Expand Down Expand Up @@ -46,22 +47,66 @@ private LoadContext(string parentAssembly)
}

/// <inheritdoc/>
protected override Assembly? Load(AssemblyName name)
protected override IntPtr LoadUnmanagedDll(string name)
{
var path = this.resolver.ResolveAssemblyToPath(name);
return path == null ? null : this.LoadFromAssemblyPath(path);
var path = this.resolver.ResolveUnmanagedDllToPath(name);
path ??= this.ResolveFromFallbackPaths(name);
return path == null ? IntPtr.Zero : this.LoadUnmanagedDllFromPath(path);
}

/// <summary>
/// Search all fallback paths for a suitable .dll, .dylib, or .so file, ignoring all exceptions.
/// Returns the full path to the file if such a file was found.
/// </summary>
private string? ResolveFromFallbackPaths(string name)
{
bool MatchByName(string file) =>
Path.GetFileNameWithoutExtension(file)
.Equals(name, StringComparison.InvariantCultureIgnoreCase);

var found = new List<string>();
foreach (var dir in this.fallbackPaths)
{
try
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
found.AddRange(Directory.GetFiles(dir, "*.dylib", SearchOption.AllDirectories).Where(MatchByName));
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
found.AddRange(Directory.GetFiles(dir, "*.so", SearchOption.AllDirectories).Where(MatchByName));
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
found.AddRange(Directory.GetFiles(dir, "*.dll", SearchOption.AllDirectories).Where(MatchByName));
}
else
{
found.AddRange(Directory.GetFiles(dir, "*.dll", SearchOption.AllDirectories).Where(MatchByName));
found.AddRange(Directory.GetFiles(dir, "*.dylib", SearchOption.AllDirectories).Where(MatchByName));
found.AddRange(Directory.GetFiles(dir, "*.so", SearchOption.AllDirectories).Where(MatchByName));
}
}
catch
{
continue;
}
}

return found.FirstOrDefault();
}

/// <inheritdoc/>
protected override IntPtr LoadUnmanagedDll(string name)
protected override Assembly? Load(AssemblyName name)
{
var path = this.resolver.ResolveUnmanagedDllToPath(name);
return path == null ? IntPtr.Zero : this.LoadUnmanagedDllFromPath(path);
var path = this.resolver.ResolveAssemblyToPath(name);
return path == null ? null : this.LoadFromAssemblyPath(path);
}

/// <summary>
/// Search all fallback paths for a suitable .dll ignoring all exceptions.
/// Returns the full path to the dll if a suitable assembly could was found.
/// Returns the full path to the dll if a suitable assembly was found.
/// </summary>
private string? ResolveFromFallbackPaths(AssemblyName name)
{
Expand All @@ -81,6 +126,7 @@ bool MatchByName(string file) =>
continue;
}
}

if (found.Count <= 1 || name.Version == null)
{
return found.FirstOrDefault();
Expand Down
14 changes: 14 additions & 0 deletions src/QsCompiler/CommandLineTool/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ public class CompilationOptions : Options
HelpText = "Additional properties to populate the AssemblyConstants dictionary with. Each item is expected to be of the form \"key:value\".")]
public IEnumerable<string>? AdditionalAssemblyProperties { get; set; }

[Option(
"skip-monomorphization",
Required = false,
Default = false,
HelpText = "Specifies whether to omit monomorphizing the AST for executables.")]
public bool SkipMonomorphization { get; set; }

[Option(
"force-rewrite-step-execution",
Required = false,
Default = false,
HelpText = "Specifies whether to execute rewrite steps even if their precondition is not satisfied. If the parameter is set to true and the precondition is not satisfied, the transformation will be executed, its output will be ignored and the compilation fails.")]
public bool ForceRewriteStepExecution { get; set; }

[Option(
"runtime",
Required = false,
Expand Down
14 changes: 5 additions & 9 deletions src/QsCompiler/CommandLineTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// Licensed under the MIT License.

using System;
using System.IO;
using System.Linq;
using System.Reflection;
using CommandLine;
using Microsoft.Quantum.QsCompiler.Diagnostics;
using Microsoft.VisualStudio.LanguageServer.Protocol;
Expand Down Expand Up @@ -76,11 +78,6 @@ public static class ReturnCode
/// </summary>
public const int MonomorphizationErrors = -12;

/// <summary>
/// Return code indicating that generating QIR for the built compilation failed.
/// </summary>
public const int QirGenerationErrors = -13;

/// <summary>
/// Return code indicating that an unexpected exception was thrown when executing the invoked command to the Q# command line compiler.
/// </summary>
Expand All @@ -96,8 +93,6 @@ public static int Status(CompilationLoader loaded) =>
loaded.Monomorphization == CompilationLoader.Status.Failed ? MonomorphizationErrors :
loaded.TargetSpecificReplacements == CompilationLoader.Status.Failed ? TargetingErrors :
loaded.TargetSpecificCompilation == CompilationLoader.Status.Failed ? TargetingErrors :
loaded.TargetInstructionInference == CompilationLoader.Status.Failed ? TargetingErrors :
loaded.QirGeneration == CompilationLoader.Status.Failed ? QirGenerationErrors :
loaded.Documentation == CompilationLoader.Status.Failed ? DocGenerationErrors :
loaded.BinaryFormat == CompilationLoader.Status.Failed ? BinaryGenerationErrors :
loaded.DllGeneration == CompilationLoader.Status.Failed ? DllGenerationErrors :
Expand All @@ -112,16 +107,17 @@ private static int Run<T>(Func<T, ConsoleLogger, int> compile, T options)
var logger = options.GetLogger();
try
{
var current = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!;
var fallbackFolders = options.PackageLoadFallbackFolders.Prepend(current);
CompilationLoader.LoadAssembly = path =>
LoadContext.LoadAssembly(path, options.PackageLoadFallbackFolders?.ToArray());
LoadContext.LoadAssembly(path, fallbackFolders.ToArray());

var result = compile(options, logger);
logger.ReportSummary(result);
return result;
}
catch (Exception ex)
{
logger.Verbosity = DiagnosticSeverity.Hint;
logger.Log(ErrorCode.UnexpectedCommandLineCompilerException, Enumerable.Empty<string>());
logger.Log(ex);
return ReturnCode.UnexpectedError;
Expand Down
Loading