Skip to content

Implement GetUsedAssemblyReferences API for VB#40987

Merged
AlekseyTs merged 2 commits intodotnet:features/UsedAssemblyReferencesfrom
AlekseyTs:UsedAssemblies_10
Jan 22, 2020
Merged

Implement GetUsedAssemblyReferences API for VB#40987
AlekseyTs merged 2 commits intodotnet:features/UsedAssemblyReferencesfrom
AlekseyTs:UsedAssemblies_10

Conversation

@AlekseyTs
Copy link
Copy Markdown
Contributor

No description provided.

@AlekseyTs AlekseyTs requested review from a team as code owners January 15, 2020 19:20
@AlekseyTs
Copy link
Copy Markdown
Contributor Author

AlekseyTs commented Jan 15, 2020

@dotnet/roslyn-compiler Please review #Closed

2 similar comments
@AlekseyTs
Copy link
Copy Markdown
Contributor Author

AlekseyTs commented Jan 16, 2020

@dotnet/roslyn-compiler Please review #Closed

@AlekseyTs
Copy link
Copy Markdown
Contributor Author

AlekseyTs commented Jan 16, 2020

@dotnet/roslyn-compiler Please review #Closed

@jcouv
Copy link
Copy Markdown
Member

jcouv commented Jan 17, 2020

Looking #Closed

@jcouv jcouv self-assigned this Jan 17, 2020
[switch][Alias('test')]$testDesktop,
[switch]$testCoreClr,
[switch]$testIOperation,
[switch]$testUsedAssemblies,
Copy link
Copy Markdown
Member

@jcouv jcouv Jan 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

@jcouv jcouv Jan 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// The test hook is blocked by #39970 [](start = 62, length = 76)

The linked issue was closed already (fixed in master) #Closed

@jcouv
Copy link
Copy Markdown
Member

jcouv commented Jan 17, 2020

Done with C# files. Will look at the rest tomorrow. #Closed

End Function


Private Sub AddUsedAssembly(dependency As AssemblySymbol, stack As ArrayBuilder(Of AssemblySymbol))
Copy link
Copy Markdown
Member

@jcouv jcouv Jan 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

@jcouv jcouv Jan 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_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
Copy link
Copy Markdown
Member

@jcouv jcouv Jan 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
Copy link
Copy Markdown
Member

@jcouv jcouv Jan 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

@jcouv jcouv Jan 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: double empty line below #Resolved

AssertUsedAssemblyReferences(comp, expected, new DiagnosticDescription[] { }, new DiagnosticDescription[] { }, specificReferencesToAssert);
}

private Compilation AssertUsedAssemblyReferences(string source, MetadataReference[] references, params MetadataReference[] expected)
Copy link
Copy Markdown
Member

@jcouv jcouv Jan 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thanks (iteration 1). I did only spot checking on the massive test file.

@AlekseyTs
Copy link
Copy Markdown
Contributor Author

AlekseyTs commented Jan 17, 2020

@dotnet/roslyn-compiler Please review, need a second sign-off #Closed

1 similar comment
@AlekseyTs
Copy link
Copy Markdown
Contributor Author

AlekseyTs commented Jan 21, 2020

@dotnet/roslyn-compiler Please review, need a second sign-off #Closed

}

if ($testUsedAssemblies) {
$env:ROSLYN_TEST_USEDASSEMBLIES = "true"
Copy link
Copy Markdown
Member

@333fred 333fred Jan 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider adding a new CI leg to run this check? /cc @jaredpar. #Resolved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

@333fred 333fred Jan 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

@333fred 333fred Jan 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_usedAssemblyReferencesFrozen [](start = 27, length = 29)

Can we do a read of this outside the lock? #Resolved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Copy Markdown
Member

@333fred 333fred Jan 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
Copy link
Copy Markdown
Member

@333fred 333fred Jan 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

333fred commented Jan 21, 2020

interface I1

Nit: interface -> Interface, and more in this file. #WontFix


Refers to: src/Compilers/VisualBasic/Test/Symbol/UsedAssembliesTests.vb:21 in 4609ed6. [](commit_id = 4609ed6, deletion_comment = False)

@333fred
Copy link
Copy Markdown
Member

333fred commented Jan 21, 2020

interface I1

And a bunch more lowercase things (class, public, and a few others) that I've noticed so far.


In reply to: 576913297 [](ancestors = 576913297)


Refers to: src/Compilers/VisualBasic/Test/Symbol/UsedAssembliesTests.vb:21 in 4609ed6. [](commit_id = 4609ed6, deletion_comment = False)

Copy link
Copy Markdown
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (commit 1). Feedback is fine in a followup where appropriate.

@AlekseyTs
Copy link
Copy Markdown
Contributor Author

interface I1

Nit: interface -> Interface, and more in this file.

This is inside string literals.


In reply to: 576915150 [](ancestors = 576915150,576913297)


Refers to: src/Compilers/VisualBasic/Test/Symbol/UsedAssembliesTests.vb:21 in 4609ed6. [](commit_id = 4609ed6, deletion_comment = False)

@AlekseyTs AlekseyTs merged commit f5b4ff0 into dotnet:features/UsedAssemblyReferences Jan 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants