Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit 0fe402c

Browse files
Prevent result equality comparisons for QPRGen0 runtime capabilities (#449)
* Prevent result equality with QPRGen0 * Move more fields from SymbolTracker to ResolutionContext * Undo some changes to TypeChecking.cs * Move ResolutionContext up a bit * Better error message * Add basic tests * Add more tests (but not working right now...) * Fix tests * Add tests for not equals * Use static member for Create * Move ResolutionContext to SymbolTracker.fs * Update doc comment to ArgumentException Co-authored-by: bettinaheim <34236215+bettinaheim@users.noreply.github.com> * Replace failwith with ArgumentException * Mention SymbolTracker versioning in ResolutionContext * Restore supportsEqualityComparison and use VerifyIsOneOf * Undo changes to VerificationTools.fs * Rename ResolutionContext to ScopeContext * Include execution target in error message * Make ScopeContext.ExecutionTarget non-nullable * Update error message Co-authored-by: bettinaheim <34236215+bettinaheim@users.noreply.github.com>
1 parent 8dc8e16 commit 0fe402c

22 files changed

+704
-401
lines changed

src/QsCompiler/CompilationManager/CompilationUnit.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ public class CompilationUnit : IReaderWriterLock, IDisposable
234234

235235
internal readonly RuntimeCapabilities RuntimeCapabilities;
236236
internal readonly bool IsExecutable;
237+
internal readonly NonNullable<string> ExecutionTarget;
237238

238239
public void Dispose()
239240
{ this.SyncRoot.Dispose(); }
@@ -243,8 +244,12 @@ public void Dispose()
243244
/// with the given sequence of locks registered as dependent locks if the sequence is not null.
244245
/// Throws an ArgumentNullException if any of the given locks is.
245246
/// </summary>
246-
internal CompilationUnit(RuntimeCapabilities capabilities, bool isExecutable,
247-
References externals = null, IEnumerable<ReaderWriterLockSlim> dependentLocks = null)
247+
internal CompilationUnit(
248+
RuntimeCapabilities capabilities,
249+
bool isExecutable,
250+
NonNullable<string> executionTarget,
251+
References externals = null,
252+
IEnumerable<ReaderWriterLockSlim> dependentLocks = null)
248253
{
249254
this.SyncRoot = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
250255
this.DependentLocks = dependentLocks == null
@@ -254,6 +259,7 @@ internal CompilationUnit(RuntimeCapabilities capabilities, bool isExecutable,
254259

255260
this.RuntimeCapabilities = capabilities;
256261
this.IsExecutable = isExecutable;
262+
this.ExecutionTarget = executionTarget;
257263

258264
this.CompiledCallables = new Dictionary<QsQualifiedName, QsCallable>();
259265
this.CompiledTypes = new Dictionary<QsQualifiedName, QsCustomType>();

src/QsCompiler/CompilationManager/CompilationUnitManager.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,15 @@ public class CompilationUnitManager : IDisposable
6464
/// that action is called whenever diagnostics within a file have changed and are ready for publishing.
6565
/// </summary>
6666
public CompilationUnitManager(
67-
Action<Exception> exceptionLogger = null, Action<PublishDiagnosticParams> publishDiagnostics = null, bool syntaxCheckOnly = false,
68-
AssemblyConstants.RuntimeCapabilities capabilities = AssemblyConstants.RuntimeCapabilities.Unknown, bool isExecutable = false)
67+
Action<Exception> exceptionLogger = null,
68+
Action<PublishDiagnosticParams> publishDiagnostics = null,
69+
bool syntaxCheckOnly = false,
70+
AssemblyConstants.RuntimeCapabilities capabilities = AssemblyConstants.RuntimeCapabilities.Unknown,
71+
bool isExecutable = false,
72+
NonNullable<string> executionTarget = default)
6973
{
7074
this.EnableVerification = !syntaxCheckOnly;
71-
this.CompilationUnit = new CompilationUnit(capabilities, isExecutable);
75+
this.CompilationUnit = new CompilationUnit(capabilities, isExecutable, executionTarget);
7276
this.FileContentManagers = new ConcurrentDictionary<NonNullable<string>, FileContentManager>();
7377
this.ChangedFiles = new ManagedHashSet<NonNullable<string>>(new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion));
7478
this.PublishDiagnostics = publishDiagnostics ?? (_ => { });
@@ -440,7 +444,12 @@ private Task SpawnGlobalTypeCheckingAsync(bool runSynchronously = false)
440444
// work with a separate compilation unit instance such that processing of all further edits can go on in parallel
441445
var sourceFiles = this.FileContentManagers.Values.OrderBy(m => m.FileName);
442446
this.ChangedFiles.RemoveAll(f => sourceFiles.Any(m => m.FileName.Value == f.Value));
443-
var compilation = new CompilationUnit(this.CompilationUnit.RuntimeCapabilities, this.CompilationUnit.IsExecutable, this.CompilationUnit.Externals, sourceFiles.Select(file => file.SyncRoot));
447+
var compilation = new CompilationUnit(
448+
this.CompilationUnit.RuntimeCapabilities,
449+
this.CompilationUnit.IsExecutable,
450+
this.CompilationUnit.ExecutionTarget,
451+
this.CompilationUnit.Externals,
452+
sourceFiles.Select(file => file.SyncRoot));
444453
var content = compilation.UpdateGlobalSymbolsFor(sourceFiles);
445454
foreach (var file in sourceFiles) this.PublishDiagnostics(file.Diagnostics());
446455

src/QsCompiler/CompilationManager/ProjectManager.cs

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,22 @@ internal class ProjectProperties
2323
public readonly string OutputPath;
2424
public readonly AssemblyConstants.RuntimeCapabilities RuntimeCapabilities;
2525
public readonly bool IsExecutable;
26+
public readonly NonNullable<string> ExecutionTarget;
2627
public readonly bool ExposeReferencesViaTestNames;
2728

28-
internal static ProjectProperties Default =>
29-
new ProjectProperties("Latest", "", AssemblyConstants.RuntimeCapabilities.Unknown, false, false);
30-
31-
public ProjectProperties(string version, string outputPath, AssemblyConstants.RuntimeCapabilities runtimeCapabilities, bool isExecutable, bool loadTestNames)
29+
public ProjectProperties(
30+
string version,
31+
string outputPath,
32+
AssemblyConstants.RuntimeCapabilities runtimeCapabilities,
33+
bool isExecutable,
34+
NonNullable<string> executionTarget,
35+
bool loadTestNames)
3236
{
3337
this.Version = version ?? "";
3438
this.OutputPath = outputPath ?? throw new ArgumentNullException(nameof(outputPath));
3539
this.RuntimeCapabilities = runtimeCapabilities;
3640
this.IsExecutable = isExecutable;
41+
this.ExecutionTarget = executionTarget;
3742
this.ExposeReferencesViaTestNames = loadTestNames;
3843
}
3944
}
@@ -47,13 +52,34 @@ public class ProjectInformation
4752
public readonly ImmutableArray<string> ProjectReferences;
4853
public readonly ImmutableArray<string> References;
4954

50-
internal static ProjectInformation Empty(string version, string outputPath, AssemblyConstants.RuntimeCapabilities runtimeCapabilities) =>
51-
new ProjectInformation(version, outputPath, runtimeCapabilities, false, false, Enumerable.Empty<string>(), Enumerable.Empty<string>(), Enumerable.Empty<string>());
52-
53-
public ProjectInformation(string version, string outputPath, AssemblyConstants.RuntimeCapabilities runtimeCapabilities, bool isExecutable, bool loadTestNames,
54-
IEnumerable<string> sourceFiles, IEnumerable<string> projectReferences, IEnumerable<string> references)
55+
internal static ProjectInformation Empty(
56+
string version,
57+
string outputPath,
58+
AssemblyConstants.RuntimeCapabilities runtimeCapabilities) =>
59+
new ProjectInformation(
60+
version,
61+
outputPath,
62+
runtimeCapabilities,
63+
false,
64+
NonNullable<string>.New("Unspecified"),
65+
false,
66+
Enumerable.Empty<string>(),
67+
Enumerable.Empty<string>(),
68+
Enumerable.Empty<string>());
69+
70+
public ProjectInformation(
71+
string version,
72+
string outputPath,
73+
AssemblyConstants.RuntimeCapabilities runtimeCapabilities,
74+
bool isExecutable,
75+
NonNullable<string> executionTarget,
76+
bool loadTestNames,
77+
IEnumerable<string> sourceFiles,
78+
IEnumerable<string> projectReferences,
79+
IEnumerable<string> references)
5580
{
56-
this.Properties = new ProjectProperties(version, outputPath, runtimeCapabilities, isExecutable, loadTestNames);
81+
this.Properties = new ProjectProperties(
82+
version, outputPath, runtimeCapabilities, isExecutable, executionTarget, loadTestNames);
5783
this.SourceFiles = sourceFiles?.ToImmutableArray() ?? throw new ArgumentNullException(nameof(sourceFiles));
5884
this.ProjectReferences = projectReferences?.ToImmutableArray() ?? throw new ArgumentNullException(nameof(projectReferences));
5985
this.References = references?.ToImmutableArray() ?? throw new ArgumentNullException(nameof(references));
@@ -146,8 +172,12 @@ internal Project(Uri projectFile, ProjectInformation projectInfo,
146172
// but we don't do any semantic verification, and we don't publish diagnostics for them.
147173
this.Processing = new ProcessingQueue(onException);
148174
this.Manager = new CompilationUnitManager(
149-
onException, ignore ? null : publishDiagnostics, syntaxCheckOnly: ignore,
150-
this.Properties.RuntimeCapabilities, this.Properties.IsExecutable);
175+
onException,
176+
ignore ? null : publishDiagnostics,
177+
syntaxCheckOnly: ignore,
178+
this.Properties.RuntimeCapabilities,
179+
this.Properties.IsExecutable,
180+
this.Properties.ExecutionTarget);
151181
this.Log = log ?? ((msg, severity) => Console.WriteLine($"{severity}: {msg}"));
152182

153183
this.LoadedSourceFiles = ImmutableHashSet<Uri>.Empty;

0 commit comments

Comments
 (0)