New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EE should ignore ValueTuple from mscorlib type when duplicate found in app #17192
Conversation
@@ -798,6 +822,11 @@ private NamedTypeSymbol ApplyGenericArguments(NamedTypeSymbol symbol, Type[] typ | |||
return result; | |||
} | |||
|
|||
private bool IsInCorLib(NamedTypeSymbol type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static
@@ -75,7 +75,7 @@ internal Symbol GetWellKnownTypeMember(WellKnownMember member) | |||
return _lazyWellKnownTypeMembers[(int)member]; | |||
} | |||
|
|||
internal NamedTypeSymbol GetWellKnownType(WellKnownType type) | |||
internal NamedTypeSymbol GetWellKnownType(WellKnownType type, bool ignoreCorLibraryDuplicatedTypes = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aleksey pointed out that we are in a Compilation here, so no need to thread this through. We can just grab this option from the compilation.
fbdc730
to
cf8b1fd
Compare
cf8b1fd
to
75a0a5c
Compare
… in mscorlib (C#)
75a0a5c
to
955002d
Compare
FYI @tmat |
' ignore candidate | ||
Continue For | ||
End If | ||
If (IsInCorLib(result)) Then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parentheses are not needed.
@@ -89,6 +91,27 @@ internal DkmClrType GetType(string typeName, params System.Type[] typeArguments) | |||
return null; | |||
} | |||
|
|||
private IEnumerable<DkmClrModuleInstance> WithMscorlibLast(DkmClrModuleInstance[] list) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static
DkmClrModuleInstance mscorlib = null; | ||
foreach (var module in list) | ||
{ | ||
if (module.Assembly.GetReferencedAssemblies().Length == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypeHelpers.IsMscorlib(module.Assembly)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had tried that, but they are actually different Assembly
types.
One is System.Reflection.Assembly
and the other is Microsoft.VisualStudio.Debugger.Metadata.Assembly
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. In that case, can TypeHelpers.IsMscorlib
be private
again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. Thanks. Fixed now
609d211
to
28abce3
Compare
28abce3
to
57b4858
Compare
@cston @dotnet/roslyn-compiler This is ready for review when you have time. Thanks |
@@ -11,6 +11,8 @@ | |||
using System.Linq; | |||
using System.Reflection; | |||
using Type = Microsoft.VisualStudio.Debugger.Metadata.Type; | |||
using System.Collections.Generic; | |||
using System.Diagnostics; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sort usings.
app.AssertTheseDiagnostics() | ||
|
||
Dim runtime = CreateRuntimeInstance({app.ToModuleInstance(), corlibWithVT.ToModuleInstance()}) | ||
' Create EE context with app assembly (including ValueTuple) And a more recent corlib (also including ValueTuple) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: and
rather than And
.
@@ -86,7 +86,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Scripting | |||
xmlReferenceResolver:=Nothing, ' don't support XML file references in interactive (permissions & doc comment includes) | |||
sourceReferenceResolver:=SourceFileResolver.Default, | |||
metadataReferenceResolver:=script.Options.MetadataResolver, | |||
assemblyIdentityComparer:=DesktopAssemblyIdentityComparer.Default), | |||
assemblyIdentityComparer:=DesktopAssemblyIdentityComparer.Default). | |||
WithIgnoreCorLibraryDuplicatedTypes(True), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was LookupOptions.IgnoreCorLibraryDuplicatedTypes
used before in scripting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VB scripting didn't use that option previously (only the expression compiler). I was a bug.
In C#, both scripting and EE use BinderFlags.IgnoreCorLibraryDuplicatedTypes
.
@tmat may want to comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, both VB and C# should use it.
LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -778,6 +787,21 @@ private NamedTypeSymbol ApplyGenericArguments(NamedTypeSymbol symbol, Type[] typ | |||
if ((object)result != null) | |||
{ | |||
// duplicate | |||
if (ignoreCorLibraryDuplicatedTypes) | |||
{ | |||
if (IsInCorLib(candidate)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (IsInCorLib(candidate)) [](start = 24, length = 26)
Are tests cover bodies of both if
statements (this one and the next)? #Closed
@@ -798,6 +822,11 @@ private NamedTypeSymbol ApplyGenericArguments(NamedTypeSymbol symbol, Type[] typ | |||
return result; | |||
} | |||
|
|||
private static bool IsInCorLib(NamedTypeSymbol type) | |||
{ | |||
return type.ContainingAssembly == type.ContainingAssembly.CorLibrary; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type.ContainingAssembly == type.ContainingAssembly.CorLibrary [](start = 19, length = 61)
(object)type.ContainingAssembly ==CorLibrary
? #Closed
At this point it feels like we can benefit from a comment describing how exactly ambiguity is handled by this method #Closed Refers to: src/Compilers/CSharp/Portable/Symbols/Compilation_WellKnownMembers.cs:78 in f33c1bc. [](commit_id = f33c1bc, deletion_comment = False) |
@@ -527,6 +541,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols | |||
Return result | |||
End Function | |||
|
|||
Private Shared Function IsInCorLib(type As NamedTypeSymbol) As Boolean | |||
Return type.ContainingAssembly = type.ContainingAssembly.CorLibrary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type.ContainingAssembly = type.ContainingAssembly.CorLibrary [](start = 19, length = 60)
type.ContainingAssembly Is CorLibrary
? #Closed
Consider adding a comment what effect does IgnoreCorLibraryDuplicatedTypes option have. #Closed Refers to: src/Compilers/VisualBasic/Portable/Symbols/WellKnownMembers.vb:348 in f33c1bc. [](commit_id = f33c1bc, deletion_comment = False) |
It feels like an implementation of this function should be adjusted and relevant tests added. #Closed Refers to: src/Compilers/VisualBasic/Portable/VisualBasicCompilationOptions.vb:964 in f33c1bc. [](commit_id = f33c1bc, deletion_comment = False) |
DkmClrModuleInstance mscorlib = null; | ||
foreach (var module in list) | ||
{ | ||
if (module.Assembly.GetReferencedAssemblies().Length == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (module.Assembly.GetReferencedAssemblies().Length == 0) [](start = 16, length = 58)
This check is not accurate. I think it is possible to have an assembly without references that is not Core Library. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should at least check whether it defines the object type. #Closed
It looks like we are missing direct tests for GetWellknownType API. #Closed |
Mitigates https://github.com/dotnet/corefx/issues/16195
Repro:
This will give an error CS8179, because the compiler found two instances of the well-known type (that is ambiguity).
Fix:
The basic approach is to leverage the existing
BinderFlags.IgnoreCorLibraryDuplicatedTypes
flag from theCompilation
and affect how ValueTuple types are loaded byGetWellKnownType
.I verified the fix in unittest and manually in VS.
VB has the same bug, so I will work on a fix for VB too.