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
4 changes: 2 additions & 2 deletions src/QsCompiler/CommandLineTool/Commands/Diagnose.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,13 @@ private static void PrintGeneratedQs(IEnumerable<QsNamespace> evaluatedTree, Com
if (Options.IsCodeSnippet(file))
{
var subtree = evaluatedTree.Select(ns => FilterBySourceFile.Apply(ns, file)).Where(ns => ns.Elements.Any());
var code = new string[] { "" }.Concat(StripSnippetWrapping(subtree).Select(FormatCompilation.FormatStatement));
var code = new string[] { "" }.Concat(StripSnippetWrapping(subtree).Select(SyntaxTreeToQsharp.Default.ToCode));
logger.Log(InformationCode.FormattedQsCode, Enumerable.Empty<string>(), messageParam: code.ToArray());
}
else
{
var imports = evaluatedTree.ToImmutableDictionary(ns => ns.Name, ns => compilation.OpenDirectives(file, ns.Name).ToImmutableArray());
SyntaxTreeToQs.Apply(out List<ImmutableDictionary<NonNullable<string>, string>> generated, evaluatedTree, (file, imports));
SyntaxTreeToQsharp.Apply(out List<ImmutableDictionary<NonNullable<string>, string>> generated, evaluatedTree, (file, imports));
var code = new string[] { "" }.Concat(generated.Single().Values.Select(nsCode => $"{nsCode}{Environment.NewLine}"));
logger.Log(InformationCode.FormattedQsCode, Enumerable.Empty<string>(), file.Value, messageParam: code.ToArray());
};
Expand Down
16 changes: 2 additions & 14 deletions src/QsCompiler/CommandLineTool/Commands/Format.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,6 @@ public static string UpdateArrayLiterals(string fileContent)
}


/// <summary>
/// Returns formatted Q# code for the given statement.
/// Throws an ArgumentNullException if the given statement is null.
/// </summary>
internal static string FormatStatement(QsStatement statement)
{
if (statement == null) throw new ArgumentNullException(nameof(statement));
var ToCode = new ScopeToQs();
ToCode.onStatement(statement);
return ToCode.Output;
}

/// <summary>
/// Generates formatted Q# code based on the part of the syntax tree that corresponds to each file in the given compilation.
/// If the id of a file is consistent with the one assigned to a code snippet,
Expand All @@ -85,13 +73,13 @@ private static IEnumerable<string> GenerateQsCode(Compilation compilation, NonNu
if (Options.IsCodeSnippet(file))
{
var subtree = compilation.SyntaxTree.Values.Select(ns => FilterBySourceFile.Apply(ns, file)).Where(ns => ns.Elements.Any());
return DiagnoseCompilation.StripSnippetWrapping(subtree).Select(FormatStatement);
return DiagnoseCompilation.StripSnippetWrapping(subtree).Select(SyntaxTreeToQsharp.Default.ToCode);
}
else
{
var imports = compilation.SyntaxTree.Values
.ToImmutableDictionary(ns => ns.Name, ns => compilation.OpenDirectives(file, ns.Name).ToImmutableArray());
var success = SyntaxTreeToQs.Apply(out List<ImmutableDictionary<NonNullable<string>, string>> generated, compilation.SyntaxTree.Values, (file, imports));
var success = SyntaxTreeToQsharp.Apply(out List<ImmutableDictionary<NonNullable<string>, string>> generated, compilation.SyntaxTree.Values, (file, imports));
if (!success) logger?.Log(WarningCode.UnresolvedItemsInGeneratedQs, Enumerable.Empty<string>(), file.Value);

return generated.Single().Select(entry =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,10 @@ private static IEnumerable<TextEdit> OpenDirectiveSuggestions(this FileContentMa

// update deprecated operation characteristics syntax

var typeToQs = new ExpressionTypeToQs(new ExpressionToQs());
string CharacteristicsAnnotation(Characteristics c)
{
typeToQs.onCharacteristicsExpression(SymbolResolution.ResolveCharacteristics(c));
return $"{Keywords.qsCharacteristics.id} {typeToQs.Output}";
var charEx = SyntaxTreeToQsharp.CharacteristicsExpression(SymbolResolution.ResolveCharacteristics(c));
return charEx == null ? "" : $"{Keywords.qsCharacteristics.id} {charEx}";
}

var suggestionsForOpCharacteristics = deprecatedOpCharacteristics.SelectMany(d =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ internal static bool TryGetReferences(
.Where(spec => spec.SourceFile.Value == file.FileName.Value)
.SelectMany(spec =>
spec.Implementation is SpecializationImplementation.Provided impl && spec.Location.IsValue
? IdentifierLocation.Find(definition.Item.Item1, impl.Item2, file.FileName, spec.Location.Item.Offset)
? IdentifierReferences.Find(definition.Item.Item1, impl.Item2, file.FileName, spec.Location.Item.Offset)
: ImmutableArray<IdentifierReferences.Location>.Empty)
.Distinct().Select(AsLocation);
}
Expand All @@ -223,7 +223,7 @@ spec.Implementation is SpecializationImplementation.Provided impl && spec.Locati
var statements = implementation.StatementsAfterDeclaration(defStart.Subtract(specPos));
var scope = new QsScope(statements.ToImmutableArray(), locals);
var rootOffset = DiagnosticTools.AsTuple(specPos);
referenceLocations = IdentifierLocation.Find(definition.Item.Item1, scope, file.FileName, rootOffset).Distinct().Select(AsLocation);
referenceLocations = IdentifierReferences.Find(definition.Item.Item1, scope, file.FileName, rootOffset).Distinct().Select(AsLocation);
}
declarationLocation = AsLocation(file.FileName, definition.Item.Item2, defRange);
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/QsCompiler/Compiler/RewriteSteps/ClassicallyControlled.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Linq;
using Microsoft.Quantum.QsCompiler.DataTypes;
using Microsoft.Quantum.QsCompiler.SyntaxTree;
using Microsoft.Quantum.QsCompiler.Transformations.ClassicallyControlledTransformation;
using Microsoft.Quantum.QsCompiler.Transformations.ClassicallyControlled;


namespace Microsoft.Quantum.QsCompiler.BuiltInRewriteSteps
Expand All @@ -28,7 +28,7 @@ public ClassicallyControlled()

public bool Transformation(QsCompilation compilation, out QsCompilation transformed)
{
transformed = ClassicallyControlledTransformation.Apply(compilation);
transformed = ReplaceClassicalControl.Apply(compilation);
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/QsCompiler/Compiler/RewriteSteps/IntrinsicResolution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System.Collections.Generic;
using Microsoft.Quantum.QsCompiler.SyntaxTree;
using Microsoft.Quantum.QsCompiler.Transformations.IntrinsicResolutionTransformation;
using Microsoft.Quantum.QsCompiler.Transformations.IntrinsicResolution;


namespace Microsoft.Quantum.QsCompiler.BuiltInRewriteSteps
Expand Down Expand Up @@ -35,7 +35,7 @@ public IntrinsicResolution(QsCompilation environment)

public bool Transformation(QsCompilation compilation, out QsCompilation transformed)
{
transformed = IntrinsicResolutionTransformation.Apply(this.Environment, compilation);
transformed = ReplaceWithTargetIntrinsics.Apply(this.Environment, compilation);
return true;
}

Expand Down
6 changes: 3 additions & 3 deletions src/QsCompiler/Compiler/RewriteSteps/Monomorphization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Linq;
using Microsoft.Quantum.QsCompiler.SyntaxTree;
using Microsoft.Quantum.QsCompiler.Transformations.Monomorphization;
using Microsoft.Quantum.QsCompiler.Transformations.MonomorphizationValidation;
using Microsoft.Quantum.QsCompiler.Transformations.Monomorphization.Validation;


namespace Microsoft.Quantum.QsCompiler.BuiltInRewriteSteps
Expand Down Expand Up @@ -33,7 +33,7 @@ public Monomorphization()

public bool Transformation(QsCompilation compilation, out QsCompilation transformed)
{
transformed = MonomorphizationTransformation.Apply(compilation);
transformed = Monomorphize.Apply(compilation);
return true;
}

Expand All @@ -42,7 +42,7 @@ public bool PreconditionVerification(QsCompilation compilation) =>

public bool PostconditionVerification(QsCompilation compilation)
{
try { MonomorphizationValidationTransformation.Apply(compilation); }
try { ValidateMonomorphization.Apply(compilation); }
catch { return false; }
return true;
}
Expand Down
10 changes: 5 additions & 5 deletions src/QsCompiler/Core/Core.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
<Link>DelaySign.fs</Link>
</Compile>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="ConstructorExtensions.fs" />
<Compile Include="ConstructorExtensions.fs" />
<Compile Include="TransformationOptions.fs" />
<Compile Include="TypeTransformation.fs" />
<Compile Include="ExpressionTransformation.fs" />
<Compile Include="StatementTransformation.fs" />
<Compile Include="TreeTransformation.fs" />
<Compile Include="ExpressionWalker.fs" />
<Compile Include="StatementWalker.fs" />
<Compile Include="TreeWalker.fs" />
<Compile Include="NamespaceTransformation.fs" />
<Compile Include="SyntaxTreeTransformation.fs" />
<Compile Include="Dependencies.fs" />
<Compile Include="SyntaxGenerator.fs" />
<Compile Include="DeclarationHeaders.fs" />
Expand Down
2 changes: 1 addition & 1 deletion src/QsCompiler/Core/DeclarationHeaders.fs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ type CallableDeclarationHeader = {
static member FromJson json =
let info = {IsMutable = false; HasLocalQuantumDependency = false}
let rec setInferredInfo = function // no need to raise an error if anything needs to be set - the info above is always correct
| QsTuple ts -> (ts |> Seq.map setInferredInfo).ToImmutableArray() |> QsTuple
| QsTuple ts -> ts |> Seq.map setInferredInfo |> ImmutableArray.CreateRange |> QsTuple
| QsTupleItem (decl : LocalVariableDeclaration<_>) -> QsTupleItem {decl with InferredInformation = info}
// we need to make sure that all fields that could possibly be null after deserializing
// due to changes of fields over time are initialized to a proper value
Expand Down
Loading