Skip to content

Commit

Permalink
Responded to PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Omar Tawfik committed Jun 7, 2017
1 parent 42a8f4c commit b32dc89
Show file tree
Hide file tree
Showing 8 changed files with 1,613 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1002,22 +1002,26 @@ public override ImmutableArray<MethodSymbol> ExplicitInterfaceImplementations

internal override DiagnosticInfo GetUseSiteDiagnostic()
{
DiagnosticInfo result = null;

if (!_packedFlags.IsUseSiteDiagnosticPopulated)
{
DiagnosticInfo result = null;
CalculateUseSiteDiagnostic(ref result);
EnsureTypeParametersAreLoaded(ref result);
result = InitializeUseSiteDiagnostic(result);
return InitializeUseSiteDiagnostic(result);
}

var uncommonFields = _uncommonFields;
if (uncommonFields == null)
{
return null;
}
else
{
result = _uncommonFields?._lazyUseSiteDiagnostic;
var result = uncommonFields._lazyUseSiteDiagnostic;
return CSDiagnosticInfo.IsEmpty(result)
? InterlockedOperations.Initialize(ref uncommonFields._lazyUseSiteDiagnostic, null, CSDiagnosticInfo.EmptyErrorInfo)
: result;
}

return CSDiagnosticInfo.IsEmpty(result)
? InterlockedOperations.Initialize(ref AccessUncommonFields()._lazyUseSiteDiagnostic, null, CSDiagnosticInfo.EmptyErrorInfo)
: result;
}

private DiagnosticInfo InitializeUseSiteDiagnostic(DiagnosticInfo diagnostic)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal static void CopyMethodCustomModifiers(

customModifiers = CustomModifiersTuple.Create(
constructedSourceMethod.ReturnTypeCustomModifiers,
destinationMethod.ReturnsByRef || destinationMethod.ReturnsByRefReadonly ? constructedSourceMethod.RefCustomModifiers : ImmutableArray<CustomModifier>.Empty);
destinationMethod.RefKind != RefKind.None ? constructedSourceMethod.RefCustomModifiers : ImmutableArray<CustomModifier>.Empty);

parameters = CopyParameterCustomModifiers(constructedSourceMethod.Parameters, destinationMethod.Parameters, alsoCopyParamsModifier);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ internal static void AddDelegateMembers(
symbols.Add(new BeginInvokeMethod(invoke, iAsyncResultType, objectType, asyncCallbackType, syntax));

// and (4) EndInvoke methods
symbols.Add(new EndInvokeMethod(invoke, iAsyncResultType, syntax));
symbols.Add(new EndInvokeMethod(invoke, iAsyncResultType, syntax, binder, diagnostics));
}

if (delegateType.DeclaredAccessibility <= Accessibility.Private)
Expand Down Expand Up @@ -356,15 +356,18 @@ internal override OneOrMany<SyntaxList<AttributeListSyntax>> GetReturnTypeAttrib

private sealed class EndInvokeMethod : SourceDelegateMethodSymbol
{
private readonly RefKind refKind;
private readonly RefKind _refKind;
private readonly ImmutableArray<CustomModifier> _refCustomModifiers;

internal EndInvokeMethod(
InvokeMethod invoke,
TypeSymbol iAsyncResultType,
DelegateDeclarationSyntax syntax)
DelegateDeclarationSyntax syntax,
Binder binder,
DiagnosticBag diagnostics)
: base((SourceNamedTypeSymbol)invoke.ContainingType, invoke.ReturnType, syntax, MethodKind.Ordinary, DeclarationModifiers.Virtual | DeclarationModifiers.Public)
{
this.refKind = invoke.RefKind;
this._refKind = invoke.RefKind;

var parameters = ArrayBuilder<ParameterSymbol>.GetInstance();
int ordinal = 0;
Expand All @@ -380,6 +383,16 @@ internal EndInvokeMethod(

parameters.Add(SynthesizedParameterSymbol.Create(this, iAsyncResultType, ordinal++, RefKind.None, GetUniqueParameterName(parameters, "result")));
InitializeParameters(parameters.ToImmutableAndFree());

if (_refKind == RefKind.RefReadOnly)
{
var isConstType = binder.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_IsConst, diagnostics, syntax.ReturnType);
_refCustomModifiers = ImmutableArray.Create(CSharpCustomModifier.CreateRequired(isConstType));
}
else
{
_refCustomModifiers = ImmutableArray<CustomModifier>.Empty;
}
}

protected override SourceMethodSymbol BoundAttributesSource
Expand All @@ -398,8 +411,10 @@ public override string Name

internal override RefKind RefKind
{
get { return refKind; }
get { return _refKind; }
}

public override ImmutableArray<CustomModifier> RefCustomModifiers => _refCustomModifiers;
}

private static string GetUniqueParameterName(ArrayBuilder<ParameterSymbol> currentParameters, string name)
Expand Down
35 changes: 0 additions & 35 deletions src/Compilers/CSharp/Portable/Symbols/SymbolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,40 +406,5 @@ internal static void GetTypeOrReturnType(this Symbol symbol, out RefKind refKind
throw ExceptionUtilities.UnexpectedValue(symbol.Kind);
}
}

internal static bool IsWellKnownTypeIsConst(this ISymbol symbol)
{
if (symbol is NamedTypeSymbol typeSymbol)
{
if (typeSymbol.Name != "IsConst" || typeSymbol.ContainingType != null)
{
return false;
}

var compilerServicesNamespace = typeSymbol.ContainingNamespace;
if (compilerServicesNamespace?.Name != "CompilerServices")
{
return false;
}

var runtimeNamespace = compilerServicesNamespace.ContainingNamespace;
if (runtimeNamespace?.Name != "Runtime")
{
return false;
}

var systemNamespace = runtimeNamespace.ContainingNamespace;
if (systemNamespace?.Name != "System")
{
return false;
}

var globalNamespace = systemNamespace.ContainingNamespace;

return globalNamespace != null && globalNamespace.IsGlobalNamespace;
}

return false;
}
}
}
30 changes: 30 additions & 0 deletions src/Compilers/CSharp/Portable/Symbols/TypeSymbolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1502,5 +1502,35 @@ internal static Cci.TypeReferenceWithAttributes GetTypeRefWithAttributes(

return new Cci.TypeReferenceWithAttributes(typeRef);
}

internal static bool IsWellKnownTypeIsConst(this ITypeSymbol typeSymbol)
{
if (typeSymbol.Name != "IsConst" || typeSymbol.ContainingType != null)
{
return false;
}

var compilerServicesNamespace = typeSymbol.ContainingNamespace;
if (compilerServicesNamespace?.Name != "CompilerServices")
{
return false;
}

var runtimeNamespace = compilerServicesNamespace.ContainingNamespace;
if (runtimeNamespace?.Name != "Runtime")
{
return false;
}

var systemNamespace = runtimeNamespace.ContainingNamespace;
if (systemNamespace?.Name != "System")
{
return false;
}

var globalNamespace = systemNamespace.ContainingNamespace;

return globalNamespace != null && globalNamespace.IsGlobalNamespace;
}
}
}
Loading

0 comments on commit b32dc89

Please sign in to comment.