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
9 changes: 4 additions & 5 deletions src/Core/Compiler/CompilerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ public IEnumerable<QsNamespaceElement> IdentifyElements(string source)
{
var loader = CreateTemporaryLoader(source);
if (loader.VerifiedCompilation == null) { return ImmutableArray<QsNamespaceElement>.Empty; }
var ns = NonNullable<string>.New(Snippets.SNIPPETS_NAMESPACE);
return loader.VerifiedCompilation.SyntaxTree.TryGetValue(ns, out var tree)
return loader.VerifiedCompilation.SyntaxTree.TryGetValue(Snippets.SNIPPETS_NAMESPACE, out var tree)
? tree.Elements
: ImmutableArray<QsNamespaceElement>.Empty;
}
Expand Down Expand Up @@ -154,7 +153,7 @@ public IEnumerable<QsNamespaceElement> IdentifyElements(string source)
var entryPointUri = new Uri(Path.GetFullPath(Path.Combine("/", $"entrypoint.qs")));
var entryPointSnippet = @$"namespace ENTRYPOINT
{{
open {operation.Header.QualifiedName.Namespace.Value};
open {operation.Header.QualifiedName.Namespace};
@{BuiltIn.EntryPoint.FullName}()
operation {signature}
{{
Expand Down Expand Up @@ -236,7 +235,7 @@ string WrapInNamespace(Snippet s) =>
var code = SimulationCode.generate(sourceFile, codegenContext);
var tree = CSharpSyntaxTree.ParseText(code, encoding: UTF8Encoding.UTF8);
trees.Add(tree);
logger.LogDebug($"Generated the following C# code for {sourceFile.Value}:\n=============\n{code}\n=============\n");
logger.LogDebug($"Generated the following C# code for {sourceFile}:\n=============\n{code}\n=============\n");
}

// Compile the C# syntax trees:
Expand All @@ -253,7 +252,7 @@ string WrapInNamespace(Snippet s) =>
using (var bsonStream = new MemoryStream())
{
using var writer = new BsonDataWriter(bsonStream) { CloseOutput = false };
var fromSources = qsCompilation.Namespaces.Select(ns => FilterBySourceFile.Apply(ns, s => s.Value.EndsWith(".qs")));
var fromSources = qsCompilation.Namespaces.Select(ns => FilterBySourceFile.Apply(ns, s => s.EndsWith(".qs")));
Json.Serializer.Serialize(writer, new QsCompilation(fromSources.ToImmutableArray(), qsCompilation.EntryPoints));

var resourceDescription = new ResourceDescription
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.0.0" />
<PackageReference Include="Microsoft.Quantum.Compiler" Version="0.13.201118141-beta" />
<PackageReference Include="Microsoft.Quantum.CsharpGeneration" Version="0.13.201118141-beta" />
<PackageReference Include="Microsoft.Quantum.Compiler" Version="0.13.2011.802-alpha" />
<PackageReference Include="Microsoft.Quantum.CsharpGeneration" Version="0.13.2011.801-alpha" />
<PackageReference Include="Microsoft.Quantum.Simulators" Version="0.13.201118141-beta" />
<PackageReference Include="NuGet.Resolver" Version="5.1.0" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
Expand Down
13 changes: 5 additions & 8 deletions src/Core/Extensions/Qsharp.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using Microsoft.Quantum.QsCompiler.DataTypes;
using Microsoft.Quantum.QsCompiler.SyntaxTree;
using Microsoft.Quantum.Simulation.Simulators;

Expand All @@ -16,7 +13,7 @@ namespace Microsoft.Quantum.IQSharp
/// </summary>
public static partial class Extensions
{
public static readonly QsQualifiedName UNKNOWN_OPERATION = new QsQualifiedName(NonNullable<string>.New("UNKNOWN"), NonNullable<string>.New("UNKNOWN"));
public static readonly QsQualifiedName UNKNOWN_OPERATION = new QsQualifiedName("UNKNOWN", "UNKNOWN");

/// <summary>
/// Returns the source of the given QsNamespaceElement (either QsCallable or QsCustomTypes)
Expand All @@ -25,11 +22,11 @@ public static string SourceFile(this QsNamespaceElement e)
{
if (e is QsNamespaceElement.QsCallable c)
{
return c.Item.SourceFile.Value;
return c.Item.SourceFile;
}
else if (e is QsNamespaceElement.QsCustomType t)
{
return t.Item.SourceFile.Value;
return t.Item.SourceFile;
}

return "[Unknown]";
Expand All @@ -51,14 +48,14 @@ public static string ToFullName(this QsNamespaceElement e)
name = t.Item.FullName;
}

return $"{name.Namespace.Value}.{name.Name.Value}";
return $"{name.Namespace}.{name.Name}";
}

/// <summary>
/// Formats a qualified name using dotted-name syntax.
/// <summary>
public static string ToFullName(this QsQualifiedName name) =>
name?.Namespace.Value + "." + name?.Name.Value;
name?.Namespace + "." + name?.Name;

/// <summary>
/// Removes the given namespace, from the given name, iff name starts with namespace.
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Resolver/OperationResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static OperationInfo ResolveFromAssemblies(string name, IEnumerable<Assem
var isQualified = name.Contains('.');
foreach (var operation in assemblies.SelectMany(asm => asm.Operations))
{
if (name == (isQualified ? operation.FullName : operation.Header.QualifiedName.Name.Value))
if (name == (isQualified ? operation.FullName : operation.Header.QualifiedName.Name))
{
return operation;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Snippets/Snippets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ Snippet populate(Snippet s) =>
id = string.IsNullOrWhiteSpace(s.id) ? Guid.NewGuid().ToString() : s.id,
code = s.code,
warnings = logger.Logs
.Where(m => m.Source == CompilationUnitManager.GetFileId(s.Uri).Value)
.Where(m => m.Source == CompilationUnitManager.GetFileId(s.Uri))
.Select(logger.Format)
.ToArray(),
Elements = assembly?.SyntaxTree?
.SelectMany(ns => ns.Elements)
.Where(c => c.SourceFile() == CompilationUnitManager.GetFileId(s.Uri).Value)
.Where(c => c.SourceFile() == CompilationUnitManager.GetFileId(s.Uri))
.ToArray()
};

Expand Down
6 changes: 3 additions & 3 deletions src/Kernel/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ internal static IEnumerable<QsDeclarationAttribute> GetAttributesByName(
// we use a pattern match here to make sure that we have
// an actual UDT to compare against.
attribute.TypeId.Item is UserDefinedType udt &&
udt.Namespace.Value == namespaceName &&
udt.Name.Value == attributeName
udt.Namespace == namespaceName &&
udt.Name == attributeName
);

internal static bool TryAsStringLiteral(this TypedExpression expression, [NotNullWhen(true)] out string? value)
{
if (expression.Expression is QsExpressionKind<TypedExpression, Identifier, ResolvedType>.StringLiteral literal)
{
value = literal.Item1.Value;
value = literal.Item1;
return true;
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/SymbolResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class IQSharpSymbol : ISymbol
/// symbol was defined.
/// </summary>
[JsonProperty("source")]
public string Source => Operation.Header.SourceFile.Value;
public string Source => Operation.Header.SourceFile;

/// <summary>
/// The documentation for this symbol, as provided by its API
Expand Down