Implement GetUsedAssemblyReferences API for VB#40987
Implement GetUsedAssemblyReferences API for VB#40987AlekseyTs merged 2 commits intodotnet:features/UsedAssemblyReferencesfrom
Conversation
|
@dotnet/roslyn-compiler Please review #Closed |
2 similar comments
|
@dotnet/roslyn-compiler Please review #Closed |
|
@dotnet/roslyn-compiler Please review #Closed |
|
Looking #Closed |
| [switch][Alias('test')]$testDesktop, | ||
| [switch]$testCoreClr, | ||
| [switch]$testIOperation, | ||
| [switch]$testUsedAssemblies, |
There was a problem hiding this comment.
$testUsedAssemblies [](start = 10, length = 19)
Should we pass this flag in one of the CI legs, or is this intended for local testing only at this point? #Resolved
There was a problem hiding this comment.
Should we pass this flag in one of the CI legs, or is this intended for local testing only at this point?
Once the feature is moved to master, I think.
In reply to: 367718165 [](ancestors = 367718165)
| } | ||
|
|
||
| [Fact(Skip = "PROTOTYPE(UsedAssemblyReferences): The test hook is blocked by https://github.com/dotnet/roslyn/issues/39970")] | ||
| [ConditionalFact(typeof(NoUsedAssembliesValidation))] // The test hook is blocked by https://github.com/dotnet/roslyn/issues/39970 |
There was a problem hiding this comment.
// The test hook is blocked by #39970 [](start = 62, length = 76)
The linked issue was closed already (fixed in master) #Closed
|
Done with C# files. Will look at the rest tomorrow. #Closed |
| End Function | ||
|
|
||
|
|
||
| Private Sub AddUsedAssembly(dependency As AssemblySymbol, stack As ArrayBuilder(Of AssemblySymbol)) |
There was a problem hiding this comment.
Private [](start = 8, length = 7)
nit: formatting above #Resolved
| ' It normally happens during actual compile, but also happens when getting emit diagnostics for | ||
| ' testing purposes. | ||
| Private ReadOnly _doEmitPhase As Boolean | ||
| Private ReadOnly _doLoweringPhase As Boolean |
There was a problem hiding this comment.
_doLoweringPhase [](start = 25, length = 16)
nit: I'd consider leaving a comment why/when this is useful. To get used assemblies we need to run lowering phase, but for regular diagnostic information we don't. #Resolved
| isBodySynthesized:=True) | ||
|
|
||
| If Not diagnosticsThisMethod.HasAnyErrors Then | ||
| If Not diagnosticsThisMethod.HasAnyErrors AndAlso DoEmitPhase Then |
There was a problem hiding this comment.
DoEmitPhase [](start = 74, length = 11)
nit: consider swapping checks (I assume diagnosticsThisMethod.HasAnyErrors is more expensive). Possibly also below #Resolved
| diagnostics As BindingDiagnosticBag) | ||
| ' TODO: Dev10 reports error on specific type parts rather than the import | ||
| ' (reporting error on Object rather than C in C = A(Of Object) for instance). | ||
| Dim clauseDiagnostics = BindingDiagnosticBag.GetInstance() |
There was a problem hiding this comment.
clauseDiagnostics [](start = 16, length = 17)
nit: Is there a gain from re-using instance this way, rather than simply getting a new instance on every iteration (from within ValidateImportsClause)? May be marginally simpler to read.
I was thrown off initially, wondering what this bag was for and why it was discarded... #WontFix
There was a problem hiding this comment.
Is there a gain from re-using instance this way, rather than simply getting a new instance on every iteration
Avoiding allocating within a loop on every iteration is always a good thing.
In reply to: 368147783 [](ancestors = 368147783)
| Dim diagBag = New BindingDiagnosticBag(diagnostics, dependenciesBag) | ||
| #Else | ||
| Dim diagBag = New BindingDiagnosticBag(diagnostics) | ||
| #End If |
There was a problem hiding this comment.
nit: double empty line below #Resolved
| AssertUsedAssemblyReferences(comp, expected, new DiagnosticDescription[] { }, new DiagnosticDescription[] { }, specificReferencesToAssert); | ||
| } | ||
|
|
||
| private Compilation AssertUsedAssemblyReferences(string source, MetadataReference[] references, params MetadataReference[] expected) |
There was a problem hiding this comment.
AssertUsedAssemblyReferences [](start = 28, length = 28)
nit: it's odd to have an Assert method return a result. Consider renaming. Also, I was generally a bit confused about the many overloads, especially with use of params. It's probably okay within IDE, but harder as text review. #WontFix
jcouv
left a comment
There was a problem hiding this comment.
LGTM Thanks (iteration 1). I did only spot checking on the massive test file.
|
@dotnet/roslyn-compiler Please review, need a second sign-off #Closed |
1 similar comment
|
@dotnet/roslyn-compiler Please review, need a second sign-off #Closed |
| } | ||
|
|
||
| if ($testUsedAssemblies) { | ||
| $env:ROSLYN_TEST_USEDASSEMBLIES = "true" |
There was a problem hiding this comment.
Should we consider adding a new CI leg to run this check? /cc @jaredpar. #Resolved
There was a problem hiding this comment.
Should we consider adding a new CI leg to run this check?
I think we should do this once the feature is moved to master.
In reply to: 369228944 [](ancestors = 369228944)
| _diagnostics.AddRange(diagnosticsThisMethod) | ||
| diagnosticsThisMethod.Free() | ||
| Else | ||
| If Not diagnosticsThisMethod.HasAnyErrors AndAlso DoEmitPhase Then |
There was a problem hiding this comment.
Not sure if you did the swap up here as well, just making sure that Julien's below comment is seen here too.
nit: consider swapping checks (I assume diagnosticsThisMethod.HasAnyErrors is more expensive). Possibly also below #Resolved
| ' This, for example, takes care of including facade assemblies that forward types around. | ||
| If _lazyUsedAssemblyReferences IsNot Nothing Then | ||
| SyncLock _lazyUsedAssemblyReferences | ||
| If _usedAssemblyReferencesFrozen OrElse Volatile.Read(_usedAssemblyReferencesFrozen) Then |
There was a problem hiding this comment.
_usedAssemblyReferencesFrozen [](start = 27, length = 29)
Can we do a read of this outside the lock? #Resolved
There was a problem hiding this comment.
Can we do a read of this outside the lock?
We do this at the beginning of the function and I think it make sense to check after the lock is acquired too in order to avoid doing the work if it was done while we were waiting for the lock.
In reply to: 369262446 [](ancestors = 369262446)
| #If DEBUG Then | ||
| Dim wasFrozen As Boolean = _usedAssemblyReferencesFrozen | ||
| #End If | ||
| Dim result As Boolean = _lazyUsedAssemblyReferences.Add(assembly) |
There was a problem hiding this comment.
result [](start = 16, length = 6)
Nit: a better name would be added, would make the assertion below easier to read at a glance. #Resolved
| ) | ||
| Dim type = TryCast(namespaceOrType, TypeSymbol) | ||
| If type IsNot Nothing Then | ||
| clauseDiagnostics.Clear() |
There was a problem hiding this comment.
I think it would be better to clear these on every loop in the calling method, rather than splitting the semantics of how this particular BindingDiagnosticsBag is supposed to be used across multiple methods. #Resolved
There was a problem hiding this comment.
I think it would be better to clear these on every loop in the calling method, rather than splitting the semantics of how this particular BindingDiagnosticsBag is supposed to be used across multiple methods.
I don't think I agree. The caller is only responsible for providing an instance, it doesn't use this bag at all. Usage in this method depends on starting with an empty bag, therefore, I believe it is more appropriate to do this here, rather than adding an extra contract for the caller. That, in fact would split usage semantics across multiple methods, I think.
In reply to: 369268016 [](ancestors = 369268016)
333fred
left a comment
There was a problem hiding this comment.
LGTM (commit 1). Feedback is fine in a followup where appropriate.
No description provided.