diff --git a/src/Core/Compiler/CompilerService.cs b/src/Core/Compiler/CompilerService.cs index 2160e399f8..611bbce525 100644 --- a/src/Core/Compiler/CompilerService.cs +++ b/src/Core/Compiler/CompilerService.cs @@ -96,8 +96,7 @@ public IEnumerable IdentifyElements(string source) { var loader = CreateTemporaryLoader(source); if (loader.VerifiedCompilation == null) { return ImmutableArray.Empty; } - var ns = NonNullable.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.Empty; } @@ -154,7 +153,7 @@ public IEnumerable 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} {{ @@ -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: @@ -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 diff --git a/src/Core/Core.csproj b/src/Core/Core.csproj index 662799863e..f8a0b0811c 100644 --- a/src/Core/Core.csproj +++ b/src/Core/Core.csproj @@ -38,8 +38,8 @@ - - + + diff --git a/src/Core/Extensions/Qsharp.cs b/src/Core/Extensions/Qsharp.cs index 38c49c5796..71fca7a934 100644 --- a/src/Core/Extensions/Qsharp.cs +++ b/src/Core/Extensions/Qsharp.cs @@ -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; @@ -16,7 +13,7 @@ namespace Microsoft.Quantum.IQSharp /// public static partial class Extensions { - public static readonly QsQualifiedName UNKNOWN_OPERATION = new QsQualifiedName(NonNullable.New("UNKNOWN"), NonNullable.New("UNKNOWN")); + public static readonly QsQualifiedName UNKNOWN_OPERATION = new QsQualifiedName("UNKNOWN", "UNKNOWN"); /// /// Returns the source of the given QsNamespaceElement (either QsCallable or QsCustomTypes) @@ -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]"; @@ -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}"; } /// /// Formats a qualified name using dotted-name syntax. /// public static string ToFullName(this QsQualifiedName name) => - name?.Namespace.Value + "." + name?.Name.Value; + name?.Namespace + "." + name?.Name; /// /// Removes the given namespace, from the given name, iff name starts with namespace. diff --git a/src/Core/Resolver/OperationResolver.cs b/src/Core/Resolver/OperationResolver.cs index 3e48e5ce4d..393ba6c3bb 100644 --- a/src/Core/Resolver/OperationResolver.cs +++ b/src/Core/Resolver/OperationResolver.cs @@ -62,7 +62,7 @@ public static OperationInfo ResolveFromAssemblies(string name, IEnumerable asm.Operations)) { - if (name == (isQualified ? operation.FullName : operation.Header.QualifiedName.Name.Value)) + if (name == (isQualified ? operation.FullName : operation.Header.QualifiedName.Name)) { return operation; } diff --git a/src/Core/Snippets/Snippets.cs b/src/Core/Snippets/Snippets.cs index 068b2bd008..8bac4c62f3 100644 --- a/src/Core/Snippets/Snippets.cs +++ b/src/Core/Snippets/Snippets.cs @@ -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() }; diff --git a/src/Kernel/Extensions.cs b/src/Kernel/Extensions.cs index 72f2e13ba4..05bf5bc7c6 100644 --- a/src/Kernel/Extensions.cs +++ b/src/Kernel/Extensions.cs @@ -77,15 +77,15 @@ internal static IEnumerable 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.StringLiteral literal) { - value = literal.Item1.Value; + value = literal.Item1; return true; } else diff --git a/src/Kernel/SymbolResolver.cs b/src/Kernel/SymbolResolver.cs index b9ad43e948..3b51d48584 100644 --- a/src/Kernel/SymbolResolver.cs +++ b/src/Kernel/SymbolResolver.cs @@ -46,7 +46,7 @@ public class IQSharpSymbol : ISymbol /// symbol was defined. /// [JsonProperty("source")] - public string Source => Operation.Header.SourceFile.Value; + public string Source => Operation.Header.SourceFile; /// /// The documentation for this symbol, as provided by its API