Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
174 commits
Select commit Hold shift + click to select a range
f2b65d7
Keep track of modifiers for callables and types
Jan 22, 2020
14e89cf
Make Modifiers a struct so serialization works
Jan 22, 2020
99a5731
Remove runtime tests until compiler version is updated
Jan 22, 2020
0bbbba5
Add converter and update serialization test
Jan 23, 2020
0b02a69
Update transformation and walker
Jan 23, 2020
088d7c5
Move modifiers out of the signatures
Jan 24, 2020
5b9a9e5
Fix attribute reader test
Jan 24, 2020
d0a4bd8
Undo superfluous changes
Jan 24, 2020
88a3e83
Update documentation for DefaultAccess
Jan 24, 2020
2bea882
Merge branch 'features/access-modifiers' into marshallsa/access-modif…
bamarsha Jan 24, 2020
4ec6574
Re-enable execution tests
Jan 27, 2020
77acec7
Merge branch 'marshallsa/access-modifiers' of https://github.com/micr…
Jan 27, 2020
122d7e8
Merge pull request #292 from microsoft/marshallsa/access-modifiers
bamarsha Jan 27, 2020
eb43e6d
Add parsing for access modifiers
Jan 28, 2020
0556439
Update syntax highlighting for private and internal
Jan 29, 2020
c5f90db
Add TODOs for parsing the final syntax
Jan 29, 2020
32f6e9b
Fix code style for creating modifiers record
Jan 29, 2020
cd40ab9
Merge pull request #295 from microsoft/marshallsa/access-modifier-par…
bamarsha Jan 29, 2020
3ef2013
Parse modifiers before fragment headers
Jan 30, 2020
09b5f70
Include modifiers in the fragment header parser
Jan 31, 2020
16bc448
Move private/internal to a separate list
Jan 31, 2020
56cbb57
Make getFragments a normal value
Jan 31, 2020
c757cc4
Remove let rec from fragment parsers
Jan 31, 2020
f0ab980
Merge branch 'features/access-modifiers' into marshallsa/access-modif…
bamarsha Jan 31, 2020
5514bb1
Move fragment header consistency check to do-block
Jan 31, 2020
dbc1fe3
Merge branch 'marshallsa/access-modifier-parsing-2' of https://github…
Jan 31, 2020
e697813
Merge pull request #298 from microsoft/marshallsa/access-modifier-par…
bamarsha Jan 31, 2020
4374c13
Add access modifiers to code completion
Feb 3, 2020
c26c93f
Include modifiers in code completion tests
Feb 3, 2020
cef7da9
optR makes more sense this way
Feb 3, 2020
4819127
Merge pull request #305 from microsoft/marshallsa/access-modifiers-co…
bamarsha Feb 4, 2020
9e48013
Fix fragment being created without consuming input
Feb 4, 2020
5d42a27
Merge pull request #306 from microsoft/marshallsa/modifier-empty-frag…
bamarsha Feb 5, 2020
01a5bd6
Check for access when resolving callables
Feb 7, 2020
03ec339
Check access when resolving types
Feb 8, 2020
82a18b1
Add error code for inaccessible type in a qualified symbol
Feb 10, 2020
96d6161
Show specific error message for inaccessible type in open NS
Feb 11, 2020
e1794ec
Add custom error message for inaccessible callable (unqualified) - ne…
Feb 12, 2020
f9f9565
Show specific error message for inaccessible qualified callables
Feb 12, 2020
0ea94f9
Rename ContainsCallable/Type to TryFindCallable/Type
Feb 12, 2020
d948529
Make errors for using less accessible types in more accessible declar…
Feb 14, 2020
3962538
Reword description of Ambiguous
Feb 14, 2020
990c76e
Update comments for NamespacesContaining{Callable, Type}
Feb 14, 2020
2335e06
Merge pull request #313 from microsoft/marshallsa/access-modifier-res…
bamarsha Feb 14, 2020
9bfefb3
Merge branch 'features/access-modifiers' into marshallsa/access-type-…
Feb 14, 2020
df315a4
Clarify checkUdt parameter in doc comment
Feb 14, 2020
1544c38
Update src/QsCompiler/Core/SymbolTable.fs
bamarsha Feb 15, 2020
e234937
NonSupportedException -> NotSupportedException
Feb 15, 2020
e0fe45f
Merge pull request #318 from microsoft/marshallsa/access-type-checking
bamarsha Feb 15, 2020
1507a5e
Add tests for access modifiers
Feb 18, 2020
d985c9b
Add a few more tests
Feb 19, 2020
214e6e8
Add tests for access modifiers in a referenced assembly
Feb 19, 2020
74f456a
Update access modifiers test namespace
Feb 19, 2020
fdd0bff
Skip access modifier tests for now
Feb 19, 2020
1dae005
Add tests for type constructor accessibility
Feb 19, 2020
1dc0f72
Re-enable tests except for redeclarations of references
Feb 20, 2020
43539b6
Replace tabs with spaces
Feb 20, 2020
bf7057c
Use more descriptive names
Feb 20, 2020
6a8a48e
Merge pull request #320 from microsoft/marshallsa/access-modifier-tests
bamarsha Feb 20, 2020
9d544b9
Add access modifiers to hover information
Feb 21, 2020
8fd37f2
Add access modifiers to Q# code output
Feb 21, 2020
9185064
Merge pull request #324 from microsoft/marshallsa/modifiers-in-hover-…
bamarsha Feb 21, 2020
5a3c7b1
Merge branch 'features/access-modifiers' into marshallsa/modifiers-qs…
bamarsha Feb 21, 2020
0287542
Merge pull request #325 from microsoft/marshallsa/modifiers-qs-code-o…
bamarsha Feb 21, 2020
8b09d3c
Add test for skipping inaccessible items in documentation
Feb 22, 2020
001a27e
Merge branch 'features/access-modifiers' into marshallsa/docgen-hide-…
Feb 22, 2020
d4b8949
Skip private and internal items when generating documentation
Feb 22, 2020
7481a69
Add copyright headers
Feb 22, 2020
e13d62c
Add doc comment for new test
Feb 22, 2020
9d02420
Clarify doc comment for WriteToStream
Feb 22, 2020
b386eaf
Merge pull request #326 from microsoft/marshallsa/docgen-hide-inacces…
bamarsha Feb 22, 2020
c7b512f
Hide inaccessible callables and types from code completion
Feb 24, 2020
267413b
Update namespace suggestion code actions for access modifiers
Feb 25, 2020
3c0cdb1
Add QsNullable.Bind
Feb 25, 2020
53f6ca4
Refactor this if statement a little
Feb 25, 2020
c67c34e
Merge pull request #334 from microsoft/marshallsa/code-completion-access
bamarsha Feb 25, 2020
6742ba5
Merge branch 'features/access-modifiers' into marshallsa/code-actions…
bamarsha Feb 25, 2020
9c721d4
Move nsName == null check earlier
Feb 25, 2020
aaf1018
Update doc comments for namespace suggestions
Feb 26, 2020
5929fc2
Merge pull request #337 from microsoft/marshallsa/code-actions-access
bamarsha Feb 26, 2020
84fadb9
Update symbol table documentation for access modifiers
Feb 26, 2020
a4f5b39
Merge pull request #343 from microsoft/marshallsa/symbol-table-docs
bamarsha Feb 27, 2020
1b8768e
Merge branch 'master' into marshallsa/access-modifiers-master-update
Feb 27, 2020
4ba4dbd
Merge branch 'features/access-modifiers' into marshallsa/access-modif…
bamarsha Feb 27, 2020
0cf75fc
Merge pull request #349 from microsoft/marshallsa/access-modifiers-ma…
bamarsha Feb 27, 2020
651c836
first draft for some handles for a package containing target specific…
Mar 3, 2020
390908c
That should properly merge options
Mar 3, 2020
190a8f2
Remove the private access modifier
Mar 9, 2020
ca8f58e
WIP
ScottCarda-MS Mar 4, 2020
113716a
Hoisting logic should be fully separated, need to rename somethings s…
ScottCarda-MS Mar 7, 2020
d034693
Removed the Utils class for transformations.
ScottCarda-MS Mar 9, 2020
62793c6
Renamed things to replace the term 'hoist' with 'lift'.
ScottCarda-MS Mar 10, 2020
1e56427
Added ToDo's for type specialization. Moved the logic that blocks fun…
ScottCarda-MS Mar 10, 2020
5a823a3
Put the function-blocking logic back into base lifting transformation.
ScottCarda-MS Mar 10, 2020
16f5b72
Access modifiers for callable lifting PR (#366)
bettinaheim Mar 10, 2020
cd00b3c
WIP
ScottCarda-MS Mar 10, 2020
6ee6cff
Merge branch 'sccarda/GeneralLifting' of https://github.com/microsoft…
ScottCarda-MS Mar 10, 2020
246f89d
small fixes
ScottCarda-MS Mar 10, 2020
2cf5a35
test
Mar 11, 2020
28d6d78
fixing typo
Mar 11, 2020
5a26e21
going with this test
Mar 11, 2020
26d923d
Merge branch 'master' into beheim/targetPackage
bettinaheim Mar 11, 2020
d4b6293
file structure
Mar 11, 2020
ef8f72c
Merge branch 'beheim/targetPackage' of https://github.com/microsoft/q…
Mar 11, 2020
e973d37
let's stick with that
Mar 11, 2020
d44ecd3
Move internal keyword to operations syntax group
Mar 11, 2020
15ea32e
Move "References" tests to other test groups
Mar 11, 2020
b460208
protected constructor
ScottCarda-MS Mar 11, 2020
0c7441b
WIP
ScottCarda-MS Mar 11, 2020
4c24029
Using named tuple fields
ScottCarda-MS Mar 11, 2020
9ed1e8d
Moved some of the logic for validation into the Lift function.
ScottCarda-MS Mar 11, 2020
9e67854
Merge pull request #361 from microsoft/marshallsa/remove-private
bamarsha Mar 12, 2020
6543bec
allowing custom TransformationState for inheriting transformations
Mar 12, 2020
09f09c5
accidentally committed changes to the TransformationState class
Mar 12, 2020
bf03cda
Merge pull request #369 from microsoft/beheim/GeneralLifting
ScottCarda-MS Mar 12, 2020
fe4b6ea
Nugged the code closer to having the validation logic in the lift fun…
ScottCarda-MS Mar 12, 2020
1f29282
Allow shadowing imported internal callables
Mar 13, 2020
9916982
Mangle names in CompilationUnit.Build
Mar 13, 2020
7d31d30
Add TODO about reversing name mangling
Mar 13, 2020
93190f4
Update comments about accessibility in Namespace class
Mar 13, 2020
5ed2a27
Check partial NS before ref in TryAddCallableSpecialization
Mar 13, 2020
4de466d
Skip calling FromSingleSource in NS.TryFindCallable
Mar 13, 2020
30d3b4f
Updated references to built-in objects.
ScottCarda-MS Mar 13, 2020
f4d6761
Made use of IsSelfAdjoint on built-in operations.
ScottCarda-MS Mar 13, 2020
13f5de8
merged in from sccarda/GeneralLifting
ScottCarda-MS Mar 13, 2020
35b6b56
Merge pull request #368 from microsoft/sccarda/BuiltInChanges
ScottCarda-MS Mar 13, 2020
486ddd6
Allow shadowing imported internal types
Mar 13, 2020
493327b
Enable redeclaration test
Mar 13, 2020
a8dca4b
Took out some commented out code from built-in changes.
ScottCarda-MS Mar 13, 2020
1bfd55f
Fixed issue with test
ScottCarda-MS Mar 13, 2020
c43a078
Remove unused functions
Mar 13, 2020
77c748e
Check source then references in TryGetAttributeDeclaredIn
Mar 13, 2020
b201e7c
Moved the location of the classical control tests. Renamed 'hoist' to…
ScottCarda-MS Mar 13, 2020
877c3fc
Merge branch 'master' into sccarda/GeneralLifting
ScottCarda-MS Mar 13, 2020
3b42eee
Removed unused file.
ScottCarda-MS Mar 13, 2020
db58ff2
Added ToDo for lifting functions.
ScottCarda-MS Mar 14, 2020
4a38476
Fix bug in PossibleQualifications
Mar 14, 2020
9b614ae
Fix bug in resolveInOpenNamespaces
Mar 14, 2020
7c0e5e4
Re-enable exception in SpecializationsDefinedInAllSources
Mar 14, 2020
05b2b2a
Re-enable assertion about external specializations
Mar 14, 2020
f45eb97
Add name mangling tests
Mar 14, 2020
7bbd6aa
Add test for using same internal name in multiple references
Mar 14, 2020
11ecd75
No diagnostics for "conflicting" internal names
Mar 14, 2020
a457839
Merge branch 'master' into sccarda/GeneralLifting
bettinaheim Mar 14, 2020
9c5284c
Move ResolutionResult to SymbolResolution.fs
Mar 14, 2020
d05003f
Add comment about name tagging
Mar 14, 2020
d0162cd
Use Library2 instead of Library1Copy
Mar 14, 2020
665c6f5
Ignore async tasks instead of waiting
Mar 14, 2020
29b80d5
Disable multiple reference test
Mar 14, 2020
f197dc2
Use PascalCase in ResolutionResult module
Mar 15, 2020
eb27b21
Check if source is in references dictionary
Mar 15, 2020
ade77a8
basic outline for sdk - now we need to distinguish the partner package
Mar 15, 2020
6341cb3
splitting out options merging
Mar 15, 2020
0292bd7
whitespace
Mar 15, 2020
ad5efe1
take exclusive sets into account when merging options
Mar 15, 2020
9a74258
Use reversible name mangling
Mar 15, 2020
293b16a
Add missing doc comments
Mar 15, 2020
2c1c994
Add missing underscores
Mar 15, 2020
5e01a0a
Remove unnecessary thunking
Mar 15, 2020
7d5ebfa
Remove unnecessary nullability
Mar 15, 2020
3ccda80
propagating target package info
Mar 15, 2020
c4df957
Merge branch 'master' into beheim/targetPackage
bettinaheim Mar 15, 2020
d87d398
forgot to adapt a test
Mar 15, 2020
a09b489
Merge branch 'beheim/targetPackage' of https://github.com/microsoft/q…
Mar 15, 2020
bcd1b60
minor thing
Mar 15, 2020
6aea16d
getting updates from sccarda/GeneralLifting
Mar 15, 2020
a8c1d58
merging in updates from marshallsa/rename-later
Mar 15, 2020
4b9ee1a
Add test for grouping internal specializations
Mar 15, 2020
e7990a8
Refactor creating references
Mar 15, 2020
5a6cd36
Skip test for now
Mar 15, 2020
07c1e4a
test project solution
Mar 16, 2020
f350f66
threading through the options to specify that references are exposed …
Mar 16, 2020
304e9d7
getting updates from marshallsa/rename-later
Mar 16, 2020
e0fc5cf
that should now actually be fully functional
Mar 16, 2020
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
11 changes: 3 additions & 8 deletions src/ProjectTemplates/Quantum.App1/Driver.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Threading.Tasks;

using Microsoft.Quantum.Simulation.Core;
using System.Threading.Tasks;
using Microsoft.Quantum.Simulation.Simulators;

namespace Quantum.App1
Expand All @@ -10,10 +7,8 @@ class Driver
{
static async Task Main(string[] args)
{
using (var qsim = new QuantumSimulator())
{
await HelloQ.Run(qsim);
}
using var qsim = new QuantumSimulator();
await HelloQ.Run(qsim);
}
}
}
45 changes: 29 additions & 16 deletions src/QsCompiler/CommandLineTool/Commands/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Microsoft.Quantum.QsCompiler.CommandLineCompiler
public static class BuildCompilation
{
[Verb("build", HelpText = "Builds a compilation unit to run on the Q# quantum simulation framework.")]
public class BuildOptions : Options
public class BuildOptions : CompilationOptions
{
[Usage(ApplicationAlias = "qsCompiler")]
public static IEnumerable<Example> UsageExamples
Expand All @@ -35,7 +35,7 @@ public static IEnumerable<Example> UsageExamples
}

[Option("response-files", Required = true, SetName = RESPONSE_FILES,
HelpText = "Response file(s) providing the command arguments. Required only if no other arguments are specified. This option replaces all other arguments.")]
HelpText = "Response file(s) providing command arguments. Required only if no other arguments are specified. Non-default values for options specified via command line take precedence.")]
public IEnumerable<string> ResponseFiles { get; set; }

[Option('o', "output", Required = false, SetName = CODE_MODE,
Expand All @@ -50,23 +50,37 @@ public static IEnumerable<Example> UsageExamples
HelpText = "Name of the project (needs to be usable as file name).")]
public string ProjectName { get; set; }

[Option("load", Required = false, SetName = CODE_MODE,
HelpText = "[Experimental feature] Path to the .NET Core dll(s) defining additional transformations to include in the compilation process.")]
public IEnumerable<string> Plugins { get; set; }

[Option("trim", Required = false, Default = 1,
HelpText = "[Experimental feature] Integer indicating how much to simplify the syntax tree by eliminating selective abstractions.")]
public int TrimLevel { get; set; }

[Option("emit-dll", Required = false, Default = false, SetName = CODE_MODE,
HelpText = "Specifies whether the compiler should emit a .NET Core dll containing the compiled Q# code.")]
public bool EmitDll { get; set; }

[Option('p', "perf", Required = false, SetName = CODE_MODE,
HelpText = "Destination folder where the output of the performance assessment will be generated.")]
public string PerfFolder { get; set; }


/// <summary>
/// Reads the content of all specified response files and processes it using FromResponseFiles.
/// Updates the settings accordingly, prioritizing already specified non-default values over the values from response-files.
/// Returns true and a new BuildOptions object as out parameter with all the settings from response files incorporated.
/// Returns false if the content of the specified response-files could not be processed.
/// </summary>
internal static bool IncorporateResponseFiles(BuildOptions options, out BuildOptions incorporated)
{
incorporated = null;
while (options.ResponseFiles != null && options.ResponseFiles.Any())
{
var fromResponseFiles = FromResponseFiles(options.ResponseFiles);
if (fromResponseFiles == null) return false;
fromResponseFiles.UpdateSetIndependentSettings(options);
options = fromResponseFiles;
}
incorporated = options;
return true;
}
}


/// <summary>
/// Given a string representing the command line arguments, splits them into a suitable string array.
/// </summary>
Expand Down Expand Up @@ -120,15 +134,13 @@ public static int Run(BuildOptions options, ConsoleLogger logger)
{
if (options == null) throw new ArgumentNullException(nameof(options));
if (logger == null) throw new ArgumentNullException(nameof(logger));

if (options?.ResponseFiles != null && options.ResponseFiles.Any())
{ options = FromResponseFiles(options.ResponseFiles); }
if (options == null) return ReturnCode.INVALID_ARGUMENTS;
if (!BuildOptions.IncorporateResponseFiles(options, out options)) return ReturnCode.INVALID_ARGUMENTS;

var usesPlugins = options.Plugins != null && options.Plugins.Any();
var loadOptions = new CompilationLoader.Configuration
{
ProjectName = options.ProjectName,
TargetPackageAssembly = options.GetTargetPackageAssemblyPath(logger),
GenerateFunctorSupport = true,
SkipSyntaxTreeTrimming = options.TrimLevel == 0,
ConvertClassicalControl = options.TrimLevel >= 2,
Expand All @@ -137,7 +149,8 @@ public static int Run(BuildOptions options, ConsoleLogger logger)
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
RewriteSteps = options.Plugins?.Select(step => (step, (string)null)) ?? ImmutableArray<(string, string)>.Empty,
EnableAdditionalChecks = false // todo: enable debug mode?
EnableAdditionalChecks = false, // todo: enable debug mode?
ExposeReferencesViaTestNames = options.ExposeReferencesViaTestNames
};

if (options.PerfFolder != null)
Expand All @@ -154,7 +167,7 @@ public static int Run(BuildOptions options, ConsoleLogger logger)
}
catch (Exception ex)
{
logger.Log(ErrorCode.PublishingPerfResultsFailed, new string[]{options.PerfFolder});
logger.Log(ErrorCode.PublishingPerfResultsFailed, new string[]{ options.PerfFolder });
logger.Log(ex);
}
}
Expand Down
18 changes: 6 additions & 12 deletions src/QsCompiler/CommandLineTool/Commands/Diagnose.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Microsoft.Quantum.QsCompiler.CommandLineCompiler
public static class DiagnoseCompilation
{
[Verb("diagnose", HelpText = "Generates intermediate representations of the code to help diagnose issues.")]
public class DiagnoseOptions : Options
public class DiagnoseOptions : CompilationOptions
{
[Usage(ApplicationAlias = "qsCompiler")]
public static IEnumerable<Example> UsageExamples
Expand Down Expand Up @@ -56,14 +56,6 @@ public static IEnumerable<Example> UsageExamples
[Option("code", Required = false, Default = false,
HelpText = "Specifies whether to print the Q# code generated based on the built syntax tree.")]
public bool PrintCompiledCode { get; set; }

[Option("trim", Required = false, Default = 1,
HelpText = "[Experimental feature] Integer indicating how much to simplify the syntax tree by eliminating selective abstractions.")]
public int TrimLevel { get; set; }

[Option("load", Required = false, SetName = CODE_MODE,
HelpText = "[Experimental feature] Path to the .NET Core dll(s) defining additional transformations to include in the compilation process.")]
public IEnumerable<string> Plugins { get; set; }
}

/// <summary>
Expand Down Expand Up @@ -136,7 +128,7 @@ private static void PrintContentTokenization(Compilation compilation, ILogger lo
private static void PrintSyntaxTree(IEnumerable<QsNamespace> evaluatedTree, Compilation compilation, ILogger logger)
{
if (compilation == null) throw new ArgumentNullException(nameof(compilation));
evaluatedTree = evaluatedTree ?? compilation.SyntaxTree.Values;
evaluatedTree ??= compilation.SyntaxTree.Values;

foreach (var file in compilation.SourceFiles)
{
Expand Down Expand Up @@ -166,7 +158,7 @@ void PrintTree(string serialization) => logger.Log(
private static void PrintGeneratedQs(IEnumerable<QsNamespace> evaluatedTree, Compilation compilation, ILogger logger)
{
if (compilation == null) throw new ArgumentNullException(nameof(compilation));
evaluatedTree = evaluatedTree ?? compilation.SyntaxTree.Values;
evaluatedTree ??= compilation.SyntaxTree.Values;

foreach (var file in compilation.SourceFiles)
{
Expand Down Expand Up @@ -219,12 +211,14 @@ public static int Run(DiagnoseOptions options, ConsoleLogger logger)

var loadOptions = new CompilationLoader.Configuration
{
TargetPackageAssembly = options.GetTargetPackageAssemblyPath(logger),
GenerateFunctorSupport = true,
SkipSyntaxTreeTrimming = options.TrimLevel == 0,
ConvertClassicalControl = options.TrimLevel >= 2,
AttemptFullPreEvaluation = options.TrimLevel > 2,
RewriteSteps = options.Plugins?.Select(step => (step, (string)null)) ?? ImmutableArray<(string, string)>.Empty,
EnableAdditionalChecks = true
EnableAdditionalChecks = true,
ExposeReferencesViaTestNames = options.ExposeReferencesViaTestNames
};
var loaded = new CompilationLoader(options.LoadSourcesOrSnippet(logger), options.References, loadOptions, logger);
if (loaded.VerifiedCompilation == null) return ReturnCode.Status(loaded);
Expand Down
99 changes: 85 additions & 14 deletions src/QsCompiler/CommandLineTool/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,65 @@

namespace Microsoft.Quantum.QsCompiler.CommandLineCompiler
{
/// <summary>
/// Default values for command line options if nothing is specified.
/// </summary>
internal static class DefaultOptions
{
public const string Verbosity = "normal";
public const Options.LogFormat OutputFormat = Options.LogFormat.Default;
public const int TrimLevel = 1;
}


public class CompilationOptions : Options
{
[Option("trim", Required = false, Default = DefaultOptions.TrimLevel, SetName = CODE_MODE,
HelpText = "[Experimental feature] Integer indicating how much to simplify the syntax tree by eliminating selective abstractions.")]
public int TrimLevel { get; set; }

[Option("load", Required = false, SetName = CODE_MODE,
HelpText = "[Experimental feature] Path to the .NET Core dll(s) defining additional transformations to include in the compilation process.")]
public IEnumerable<string> Plugins { get; set; }

[Option("target-package", Required = false, SetName = CODE_MODE,
HelpText = "Path to the NuGet package containing target specific information and implementations.")]
public string TargetPackage { get; set; }

[Option("load-test-names", Required = false, Default = false, SetName = CODE_MODE,
HelpText = "Specifies whether public types and callables declared in referenced assemblies are exposed via their test name defined by the corresponding attribute.")]
public bool ExposeReferencesViaTestNames { get; set; }


/// <summary>
/// Returns null if TargetPackage is not null or empty, and
/// returns the path to the assembly containing target specific implementations otherwise.
/// If a logger is specified, logs suitable diagnostics if a TargetPackages is not null or empty,
/// but no path to the target package assembly could be determined.
/// This may be the case if no directory at the TargetPackage location exists, or if its files can't be accessed,
/// or more than one dll matches the pattern by which the target package assembly is identified.
/// </summary>
public string GetTargetPackageAssemblyPath(ILogger logger = null)
{
if (String.IsNullOrEmpty(this.TargetPackage)) return null;
try
{
// Disclaimer: we may revise that in the future.
var targetPackageAssembly = Directory.GetFiles(this.TargetPackage, "*Intrinsics.dll", SearchOption.AllDirectories).SingleOrDefault();
if (targetPackageAssembly != null) return targetPackageAssembly;
}
catch (Exception ex)
{
if (Directory.Exists(this.TargetPackage)) logger?.Log(ex);
else logger?.Log(ErrorCode.CouldNotFineTargetPackage, new[] { this.TargetPackage });
}

logger?.Log(ErrorCode.CouldNotFindTargetPackageAssembly, new[] { this.TargetPackage });
return null;
}
}


public class Options
{
public enum LogFormat
Expand All @@ -30,10 +89,14 @@ public enum LogFormat
protected const string SNIPPET_MODE = "snippetMode";
protected const string RESPONSE_FILES = "responseFiles";

[Option('v', "verbosity", Required = false, Default = "normal",
[Option('v', "verbosity", Required = false, Default = DefaultOptions.Verbosity,
HelpText = "Specifies the verbosity of the logged output. Valid values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic].")]
public string Verbosity { get; set; }

[Option("format", Required = false, Default = DefaultOptions.OutputFormat,
HelpText = "Specifies the output format of the command line compiler.")]
public LogFormat OutputFormat { get; set; }

[Option('i', "input", Required = true, SetName = CODE_MODE,
HelpText = "Q# code or name of the Q# file to compile.")]
public IEnumerable<string> Input { get; set; }
Expand All @@ -54,15 +117,25 @@ public enum LogFormat
HelpText = "Warnings with the given code(s) will be ignored.")]
public IEnumerable<int> NoWarn { get; set; }

[Option("format", Required = false, Default = LogFormat.Default,
HelpText = "Specifies the output format of the command line compiler.")]
public LogFormat OutputFormat { get; set; }

[Option("package-load-fallback-folders", Required = false, SetName = CODE_MODE,
HelpText = "Specifies the directories the compiler will search when a rewrite step dependency could not be found.")]
HelpText = "Specifies the directories the compiler will search when a compiler dependency could not be found.")]
public IEnumerable<string> PackageLoadFallbackFolders { get; set; }


/// <summary>
/// Updates the settings that can be used independent on the other arguments according to the setting in the given options.
/// Already specified non-default values are prioritized over the values in the given options,
/// unless overwriteNonDefaultValues is set to true. Sequences are merged.
/// </summary>
internal void UpdateSetIndependentSettings(Options updates, bool overwriteNonDefaultValues = false)
{
this.Verbosity = overwriteNonDefaultValues || this.Verbosity == DefaultOptions.Verbosity ? updates.Verbosity : this.Verbosity;
this.OutputFormat = overwriteNonDefaultValues || this.OutputFormat == DefaultOptions.OutputFormat ? updates.OutputFormat : this.OutputFormat;
this.NoWarn = (this.NoWarn ?? new int[0]).Concat(updates.NoWarn ?? new int[0]);
this.References = (this.References ?? new string[0]).Concat(updates.References ?? new string[0]);
}


// routines related to logging

/// <summary>
Expand All @@ -87,15 +160,13 @@ string value(PropertyInfo p)
/// <summary>
/// Given a LogFormat, returns a suitable routing for formatting diagnostics.
/// </summary>
internal static Func<Diagnostic, string> LoggingFormat(LogFormat format)
{
switch (format)
internal static Func<Diagnostic, string> LoggingFormat(LogFormat format) =>
format switch
{
case LogFormat.MsBuild: return Formatting.MsBuildFormat;
case LogFormat.Default: return Formatting.HumanReadableFormat;
default: throw new NotImplementedException("unknown output format for logger");
}
}
LogFormat.MsBuild => Formatting.MsBuildFormat,
LogFormat.Default => Formatting.HumanReadableFormat,
_ => throw new NotImplementedException("unknown output format for logger"),
};

/// <summary>
/// Creates a suitable logger for the given command line options,
Expand Down
Loading