提交 fbad195c 编写于 作者: C Charles Stoner

Merge remote-tracking branch 'upstream/master' into 1618

......@@ -581,6 +581,7 @@ private void CompileSynthesizedMethods(ImmutableArray<NamedTypeSymbol> additiona
private void CompileSynthesizedMethods(TypeCompilationState compilationState)
{
Debug.Assert(_moduleBeingBuiltOpt != null);
Debug.Assert(compilationState.ModuleBuilderOpt == _moduleBeingBuiltOpt);
if (!compilationState.HasSynthesizedMethods)
{
......
......@@ -324,6 +324,16 @@ private Location GetSmallestSourceLocationOrNull(Symbol symbol)
return result;
}
/// <summary>
/// Ignore accessibility when resolving well-known type
/// members, in particular for generic type arguments
/// (e.g.: binding to internal types in the EE).
/// </summary>
internal virtual bool IgnoreAccessibility
{
get { return false; }
}
internal virtual VariableSlotAllocator TryCreateVariableSlotAllocator(MethodSymbol method)
{
return null;
......
......@@ -13,6 +13,7 @@ internal partial class AsyncRewriter : StateMachineRewriter
private readonly AsyncMethodBuilderMemberCollection _asyncMethodBuilderMemberCollection;
private readonly bool _constructedSuccessfully;
private readonly int _methodOrdinal;
private readonly bool _ignoreAccessibility;
private FieldSymbol _builderField;
......@@ -37,6 +38,7 @@ internal partial class AsyncRewriter : StateMachineRewriter
}
_methodOrdinal = methodOrdinal;
_ignoreAccessibility = compilationState.ModuleBuilderOpt.IgnoreAccessibility;
}
/// <summary>
......@@ -166,7 +168,7 @@ protected override BoundStatement GenerateStateMachineCreation(LocalSymbol state
bodyBuilder.Add(
F.Assignment(
F.Field(F.Local(stateMachineVariable), _builderField.AsMember(frameType)),
F.StaticCall(BinderFlags.IgnoreAccessibility, methodScopeAsyncMethodBuilderMemberCollection.BuilderType, "Create", ImmutableArray<TypeSymbol>.Empty)));
F.StaticCall(_ignoreAccessibility ? BinderFlags.IgnoreAccessibility : BinderFlags.None, methodScopeAsyncMethodBuilderMemberCollection.BuilderType, "Create", ImmutableArray<TypeSymbol>.Empty)));
// local.$stateField = NotStartedStateMachine
bodyBuilder.Add(
......
......@@ -97,8 +97,9 @@ public void CheckSum_SHA256()
public void Decode_NonUtf8()
{
var utf8 = new UTF8Encoding(false, true);
var text = "abc def baz aeiouy " + Encoding.Default.GetString(new byte[] { 0x80, 0x92, 0xA4, 0xB6, 0xC9, 0xDB, 0xED, 0xFF });
var bytes = Encoding.Default.GetBytesWithPreamble(text);
var encoding = Encoding.GetEncoding(name: "Latin1");
var text = "abc def baz aeiouy " + encoding.GetString(new byte[] { 0x80, 0x92, 0xA4, 0xB6, 0xC9, 0xDB, 0xED, 0xFF });
var bytes = encoding.GetBytesWithPreamble(text);
// Encoding.Default should not decode to UTF-8
using (var stream = new MemoryStream(bytes))
......@@ -116,7 +117,7 @@ public void Decode_NonUtf8()
{
var sourceText = EncodedStringText.Create(stream);
Assert.Equal(text, sourceText.ToString());
Assert.Equal(Encoding.Default, sourceText.Encoding);
Assert.Equal(encoding, sourceText.Encoding);
Assert.True(stream.CanRead);
}
}
......
......@@ -23,7 +23,7 @@ internal static class EncodedStringText
/// from <see cref="SourceText.From(Stream, Encoding, SourceHashAlgorithm, bool)"/> in two ways:
/// 1. It attempts to minimize allocations by trying to read the stream into a byte array.
/// 2. If <paramref name="defaultEncoding"/> is null, it will first try UTF8 and, if that fails, it will
/// try extended ASCII (code page 1252).
/// try extended ASCII (code page Latin1).
/// </summary>
/// <param name="stream">The stream containing encoded text.</param>
/// <param name="defaultEncoding">
......@@ -57,7 +57,7 @@ internal static SourceText Create(Stream stream, Encoding defaultEncoding = null
try
{
return Decode(stream, defaultEncoding ?? Encoding.GetEncoding(codepage: 1252), checksumAlgorithm, throwIfBinaryDetected: detectEncoding);
return Decode(stream, defaultEncoding ?? Encoding.GetEncoding(name: "Latin1"), checksumAlgorithm, throwIfBinaryDetected: detectEncoding);
}
catch (DecoderFallbackException e)
{
......
......@@ -1051,12 +1051,12 @@ lVbRuntimePlus:
End If
' Locate default 'mscorlib.dll' or 'System.Runtime.dll', if any.
Dim defaultCoreLibraryReference As CommandLineReference? = LoadCoreLibraryReference(sdkPaths, baseDirectory)
Dim defaultCoreLibraryReference As CommandLineReference? = LoadCoreLibraryReference(sdkPaths, baseDirectory, sdkDirectory)
' If /nostdlib is not specified, load System.dll
' Dev12 does it through combination of CompilerHost::InitStandardLibraryList and CompilerProject::AddStandardLibraries.
If Not noStdLib Then
Dim systemDllPath As String = FindFileInSdkPath(sdkPaths, "System.dll", baseDirectory)
Dim systemDllPath As String = FindFileInSdkPath(sdkPaths, "System.dll", baseDirectory, sdkDirectory)
If systemDllPath Is Nothing Then
AddDiagnostic(diagnostics, ERRID.WRN_CannotFindStandardLibrary1, "System.dll")
Else
......@@ -1069,7 +1069,7 @@ lVbRuntimePlus:
' Add reference to 'Microsoft.VisualBasic.dll' if needed
If includeVbRuntimeReference Then
If vbRuntimePath Is Nothing Then
Dim msVbDllPath As String = FindFileInSdkPath(sdkPaths, "Microsoft.VisualBasic.dll", baseDirectory)
Dim msVbDllPath As String = FindFileInSdkPath(sdkPaths, "Microsoft.VisualBasic.dll", baseDirectory, sdkDirectory)
If msVbDllPath Is Nothing Then
AddDiagnostic(diagnostics, ERRID.ERR_LibNotFound, "Microsoft.VisualBasic.dll")
Else
......@@ -1209,7 +1209,7 @@ lVbRuntimePlus:
}
End Function
Private Function LoadCoreLibraryReference(sdkPaths As List(Of String), baseDirectory As String) As CommandLineReference?
Private Function LoadCoreLibraryReference(sdkPaths As List(Of String), baseDirectory As String, sdkDirectory As String) As CommandLineReference?
' Load Core library in Dev11:
' Traditionally VB compiler has hard-coded the name of mscorlib.dll. In the Immersive profile the
' library is called System.Runtime.dll. Ideally we should get rid of the dependency on the name and
......@@ -1219,8 +1219,8 @@ lVbRuntimePlus:
' There is an extra check to only pick an assembly with no other assembly refs. This is so that is an
' user drops a user-defined binary called System.runtime.dll into the fx directory we still want to pick
' mscorlib.
Dim msCorLibPath As String = FindFileInSdkPath(sdkPaths, "mscorlib.dll", baseDirectory)
Dim systemRuntimePath As String = FindFileInSdkPath(sdkPaths, "System.Runtime.dll", baseDirectory)
Dim msCorLibPath As String = FindFileInSdkPath(sdkPaths, "mscorlib.dll", baseDirectory, sdkDirectory)
Dim systemRuntimePath As String = FindFileInSdkPath(sdkPaths, "System.Runtime.dll", baseDirectory, sdkDirectory)
If systemRuntimePath IsNot Nothing Then
If msCorLibPath Is Nothing Then
......@@ -1252,9 +1252,9 @@ lVbRuntimePlus:
Return Nothing
End Function
Private Function FindFileInSdkPath(sdkPaths As List(Of String), fileName As String, baseDirectory As String) As String
Private Function FindFileInSdkPath(sdkPaths As List(Of String), fileName As String, baseDirectory As String, sdkDirectory As String) As String
For Each path In sdkPaths
Dim absolutePath = FileUtilities.ResolveRelativePath(If(path, RuntimeEnvironment.GetRuntimeDirectory()), baseDirectory)
Dim absolutePath = FileUtilities.ResolveRelativePath(If(path, sdkDirectory), baseDirectory)
If absolutePath IsNot Nothing Then
Dim filePath = PathUtilities.CombineAbsoluteAndRelativePaths(absolutePath, fileName)
If File.Exists(filePath) Then
......
......@@ -181,6 +181,7 @@
<Compile Include="Binding\ForOrForEachBlockBinder.vb" />
<Compile Include="Binding\ForEachEnumeratorInfo.vb" />
<Compile Include="Binding\GetTypeBinder.vb" />
<Compile Include="Binding\IgnoreAccessibilityBinder.vb" />
<Compile Include="Binding\IgnoreBaseClassesBinder.vb" />
<Compile Include="Binding\ImplicitVariableBinder.vb" />
<Compile Include="Binding\ImportAliasesBinder.vb" />
......
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Namespace Microsoft.CodeAnalysis.VisualBasic.ExpressionEvaluator
Imports System.Runtime.InteropServices
Imports Microsoft.CodeAnalysis.VisualBasic.Symbols
Namespace Microsoft.CodeAnalysis.VisualBasic
Friend NotInheritable Class IgnoreAccessibilityBinder
Inherits Binder
......@@ -11,5 +14,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExpressionEvaluator
Friend Overrides Function BinderSpecificLookupOptions(options As LookupOptions) As LookupOptions
Return ContainingBinder.BinderSpecificLookupOptions(options) Or LookupOptions.IgnoreAccessibility
End Function
Public Overrides Function CheckAccessibility(sym As Symbol, <[In]> <Out> ByRef useSiteDiagnostics As HashSet(Of DiagnosticInfo), Optional accessThroughType As TypeSymbol = Nothing, Optional basesBeingResolved As ConsList(Of Symbol) = Nothing) As AccessCheckResult
Return AccessCheckResult.Accessible
End Function
End Class
End Namespace
......@@ -300,6 +300,17 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
Return result
End Function
''' <summary>
''' Ignore accessibility when resolving well-known type
''' members, in particular for generic type arguments
''' (e.g.: binding to internal types in the EE).
''' </summary>
Friend Overridable ReadOnly Property IgnoreAccessibility As Boolean
Get
Return False
End Get
End Property
Friend Overridable Function TryCreateVariableSlotAllocator(method As MethodSymbol) As VariableSlotAllocator
Return Nothing
End Function
......
......@@ -2,14 +2,9 @@
Imports System.Collections.Generic
Imports System.Collections.Immutable
Imports System.Runtime.CompilerServices
Imports System.Runtime.InteropServices
Imports System.Threading
Imports Microsoft.Cci
Imports Microsoft.CodeAnalysis
Imports Microsoft.CodeAnalysis.CodeGen
Imports Microsoft.CodeAnalysis.Collections
Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.CodeAnalysis.VisualBasic.Symbols
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
......@@ -19,6 +14,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Inherits StateMachineRewriter(Of CapturedSymbolOrExpression)
Private ReadOnly _binder As Binder
Private ReadOnly _lookupOptions As LookupOptions
Private ReadOnly _asyncMethodKind As AsyncMethodKind
Private ReadOnly _builderType As NamedTypeSymbol
Private ReadOnly _resultType As TypeSymbol
......@@ -37,6 +33,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
MyBase.New(body, method, stateMachineType, slotAllocatorOpt, compilationState, diagnostics)
Me._binder = CreateMethodBinder(method)
Me._lookupOptions = LookupOptions.AllMethodsOfAnyArity Or LookupOptions.IgnoreExtensionMethods Or LookupOptions.NoBaseClassLookup
If compilationState.ModuleBuilderOpt.IgnoreAccessibility Then
Me._binder = New IgnoreAccessibilityBinder(Me._binder)
Me._lookupOptions = Me._lookupOptions Or LookupOptions.IgnoreAccessibility
End If
Debug.Assert(asyncKind <> AsyncMethodKind.None)
Debug.Assert(asyncKind = GetAsyncMethodKind(method))
......@@ -498,19 +500,12 @@ lCaptureRValue:
typeArgs As ImmutableArray(Of TypeSymbol),
ParamArray arguments As BoundExpression()) As BoundExpression
Dim anyArgumentsWithErrors = False
' Check if we have any bad arguments.
For Each a In arguments
If a.HasErrors Then
anyArgumentsWithErrors = True
End If
Next
' Get the method group
Dim methodGroup = FindMethodAndReturnMethodGroup(receiver, type, methodName, typeArgs)
If methodGroup Is Nothing OrElse anyArgumentsWithErrors OrElse (receiver IsNot Nothing AndAlso receiver.HasErrors) Then
If methodGroup Is Nothing OrElse
arguments.Any(Function(a) a.HasErrors) OrElse
(receiver IsNot Nothing AndAlso receiver.HasErrors) Then
Return Me.F.BadExpression(arguments)
End If
......@@ -534,9 +529,8 @@ lCaptureRValue:
Dim group As BoundMethodGroup = Nothing
Dim result = LookupResult.GetInstance()
Dim options As LookupOptions = LookupOptions.AllMethodsOfAnyArity Or LookupOptions.IgnoreExtensionMethods Or LookupOptions.NoBaseClassLookup
Dim useSiteDiagnostics As HashSet(Of DiagnosticInfo) = Nothing
Me._binder.LookupMember(result, type, methodName, arity:=0, options:=options, useSiteDiagnostics:=useSiteDiagnostics)
Me._binder.LookupMember(result, type, methodName, arity:=0, options:=_lookupOptions, useSiteDiagnostics:=useSiteDiagnostics)
Me.Diagnostics.Add(Me.F.Syntax, useSiteDiagnostics)
If result.IsGood Then
......@@ -594,9 +588,8 @@ lCaptureRValue:
Dim group As BoundPropertyGroup = Nothing
Dim result = LookupResult.GetInstance()
Dim options As LookupOptions = LookupOptions.AllMethodsOfAnyArity Or LookupOptions.IgnoreExtensionMethods Or LookupOptions.NoBaseClassLookup
Dim useSiteDiagnostics As HashSet(Of DiagnosticInfo) = Nothing
Me._binder.LookupMember(result, type, propertyName, arity:=0, options:=options, useSiteDiagnostics:=useSiteDiagnostics)
Me._binder.LookupMember(result, type, propertyName, arity:=0, options:=_lookupOptions, useSiteDiagnostics:=useSiteDiagnostics)
Me.Diagnostics.Add(Me.F.Syntax, useSiteDiagnostics)
If result.IsGood Then
......
......@@ -24,6 +24,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
isBodySynthesized As Boolean) As BoundBlock
Debug.Assert(Not body.HasErrors)
Debug.Assert(compilationState.ModuleBuilderOpt IsNot Nothing)
' performs node-specific lowering.
Dim sawLambdas As Boolean
......@@ -89,6 +90,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
slotAllocatorOpt As VariableSlotAllocator,
<Out> ByRef stateMachineTypeOpt As StateMachineTypeSymbol) As BoundBlock
Debug.Assert(compilationState.ModuleBuilderOpt IsNot Nothing)
Dim iteratorStateMachine As IteratorStateMachine = Nothing
Dim bodyWithoutIterators = IteratorRewriter.Rewrite(bodyWithoutLambdas,
method,
......
......@@ -61,6 +61,11 @@ protected override IModuleReference TranslateModule(ModuleSymbol symbol, Diagnos
return base.TranslateModule(symbol, diagnostics);
}
internal override bool IgnoreAccessibility
{
get { return true; }
}
public override int CurrentGenerationOrdinal => 0;
internal override VariableSlotAllocator TryCreateVariableSlotAllocator(MethodSymbol symbol)
......
......@@ -66,7 +66,6 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Binders\EENamedTypeBinder.vb" />
<Compile Include="Binders\IgnoreAccessibilityBinder.vb" />
<Compile Include="Binders\ParametersAndLocalsBinder.vb" />
<Compile Include="Binders\SuppressObsoleteDiagnosticsBinder.vb" />
<Compile Include="CompilationContext.vb" />
......
......@@ -60,6 +60,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExpressionEvaluator
Return MyBase.TranslateModule(symbol, diagnostics)
End Function
Friend Overrides ReadOnly Property IgnoreAccessibility As Boolean
Get
Return True
End Get
End Property
Public Overrides ReadOnly Property CurrentGenerationOrdinal As Integer
Get
Return 0
......
......@@ -4154,7 +4154,7 @@ End Class"
''' Ignore accessibility in async rewriter.
''' </summary>
<WorkItem(1813, "https://github.com/dotnet/roslyn/issues/1813")>
<Fact(Skip:="1813")>
<Fact>
Public Sub AsyncRewriterIgnoreAccessibility()
Const source =
"Imports System
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册