Skip to content

Commit b32dc89

Browse files
author
Omar Tawfik
committed
Responded to PR feedback
1 parent 42a8f4c commit b32dc89

8 files changed

Lines changed: 1613 additions & 176 deletions

File tree

src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEMethodSymbol.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,22 +1002,26 @@ public override ImmutableArray<MethodSymbol> ExplicitInterfaceImplementations
10021002

10031003
internal override DiagnosticInfo GetUseSiteDiagnostic()
10041004
{
1005-
DiagnosticInfo result = null;
1006-
10071005
if (!_packedFlags.IsUseSiteDiagnosticPopulated)
10081006
{
1007+
DiagnosticInfo result = null;
10091008
CalculateUseSiteDiagnostic(ref result);
10101009
EnsureTypeParametersAreLoaded(ref result);
1011-
result = InitializeUseSiteDiagnostic(result);
1010+
return InitializeUseSiteDiagnostic(result);
1011+
}
1012+
1013+
var uncommonFields = _uncommonFields;
1014+
if (uncommonFields == null)
1015+
{
1016+
return null;
10121017
}
10131018
else
10141019
{
1015-
result = _uncommonFields?._lazyUseSiteDiagnostic;
1020+
var result = uncommonFields._lazyUseSiteDiagnostic;
1021+
return CSDiagnosticInfo.IsEmpty(result)
1022+
? InterlockedOperations.Initialize(ref uncommonFields._lazyUseSiteDiagnostic, null, CSDiagnosticInfo.EmptyErrorInfo)
1023+
: result;
10161024
}
1017-
1018-
return CSDiagnosticInfo.IsEmpty(result)
1019-
? InterlockedOperations.Initialize(ref AccessUncommonFields()._lazyUseSiteDiagnostic, null, CSDiagnosticInfo.EmptyErrorInfo)
1020-
: result;
10211025
}
10221026

10231027
private DiagnosticInfo InitializeUseSiteDiagnostic(DiagnosticInfo diagnostic)

src/Compilers/CSharp/Portable/Symbols/Source/CustomModifierUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ internal static void CopyMethodCustomModifiers(
3737

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

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

src/Compilers/CSharp/Portable/Symbols/Source/SourceDelegateMethodSymbol.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ internal static void AddDelegateMembers(
7878
symbols.Add(new BeginInvokeMethod(invoke, iAsyncResultType, objectType, asyncCallbackType, syntax));
7979

8080
// and (4) EndInvoke methods
81-
symbols.Add(new EndInvokeMethod(invoke, iAsyncResultType, syntax));
81+
symbols.Add(new EndInvokeMethod(invoke, iAsyncResultType, syntax, binder, diagnostics));
8282
}
8383

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

357357
private sealed class EndInvokeMethod : SourceDelegateMethodSymbol
358358
{
359-
private readonly RefKind refKind;
359+
private readonly RefKind _refKind;
360+
private readonly ImmutableArray<CustomModifier> _refCustomModifiers;
360361

361362
internal EndInvokeMethod(
362363
InvokeMethod invoke,
363364
TypeSymbol iAsyncResultType,
364-
DelegateDeclarationSyntax syntax)
365+
DelegateDeclarationSyntax syntax,
366+
Binder binder,
367+
DiagnosticBag diagnostics)
365368
: base((SourceNamedTypeSymbol)invoke.ContainingType, invoke.ReturnType, syntax, MethodKind.Ordinary, DeclarationModifiers.Virtual | DeclarationModifiers.Public)
366369
{
367-
this.refKind = invoke.RefKind;
370+
this._refKind = invoke.RefKind;
368371

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

381384
parameters.Add(SynthesizedParameterSymbol.Create(this, iAsyncResultType, ordinal++, RefKind.None, GetUniqueParameterName(parameters, "result")));
382385
InitializeParameters(parameters.ToImmutableAndFree());
386+
387+
if (_refKind == RefKind.RefReadOnly)
388+
{
389+
var isConstType = binder.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_IsConst, diagnostics, syntax.ReturnType);
390+
_refCustomModifiers = ImmutableArray.Create(CSharpCustomModifier.CreateRequired(isConstType));
391+
}
392+
else
393+
{
394+
_refCustomModifiers = ImmutableArray<CustomModifier>.Empty;
395+
}
383396
}
384397

385398
protected override SourceMethodSymbol BoundAttributesSource
@@ -398,8 +411,10 @@ public override string Name
398411

399412
internal override RefKind RefKind
400413
{
401-
get { return refKind; }
414+
get { return _refKind; }
402415
}
416+
417+
public override ImmutableArray<CustomModifier> RefCustomModifiers => _refCustomModifiers;
403418
}
404419

405420
private static string GetUniqueParameterName(ArrayBuilder<ParameterSymbol> currentParameters, string name)

src/Compilers/CSharp/Portable/Symbols/SymbolExtensions.cs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -406,40 +406,5 @@ internal static void GetTypeOrReturnType(this Symbol symbol, out RefKind refKind
406406
throw ExceptionUtilities.UnexpectedValue(symbol.Kind);
407407
}
408408
}
409-
410-
internal static bool IsWellKnownTypeIsConst(this ISymbol symbol)
411-
{
412-
if (symbol is NamedTypeSymbol typeSymbol)
413-
{
414-
if (typeSymbol.Name != "IsConst" || typeSymbol.ContainingType != null)
415-
{
416-
return false;
417-
}
418-
419-
var compilerServicesNamespace = typeSymbol.ContainingNamespace;
420-
if (compilerServicesNamespace?.Name != "CompilerServices")
421-
{
422-
return false;
423-
}
424-
425-
var runtimeNamespace = compilerServicesNamespace.ContainingNamespace;
426-
if (runtimeNamespace?.Name != "Runtime")
427-
{
428-
return false;
429-
}
430-
431-
var systemNamespace = runtimeNamespace.ContainingNamespace;
432-
if (systemNamespace?.Name != "System")
433-
{
434-
return false;
435-
}
436-
437-
var globalNamespace = systemNamespace.ContainingNamespace;
438-
439-
return globalNamespace != null && globalNamespace.IsGlobalNamespace;
440-
}
441-
442-
return false;
443-
}
444409
}
445410
}

src/Compilers/CSharp/Portable/Symbols/TypeSymbolExtensions.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,5 +1502,35 @@ internal static Cci.TypeReferenceWithAttributes GetTypeRefWithAttributes(
15021502

15031503
return new Cci.TypeReferenceWithAttributes(typeRef);
15041504
}
1505+
1506+
internal static bool IsWellKnownTypeIsConst(this ITypeSymbol typeSymbol)
1507+
{
1508+
if (typeSymbol.Name != "IsConst" || typeSymbol.ContainingType != null)
1509+
{
1510+
return false;
1511+
}
1512+
1513+
var compilerServicesNamespace = typeSymbol.ContainingNamespace;
1514+
if (compilerServicesNamespace?.Name != "CompilerServices")
1515+
{
1516+
return false;
1517+
}
1518+
1519+
var runtimeNamespace = compilerServicesNamespace.ContainingNamespace;
1520+
if (runtimeNamespace?.Name != "Runtime")
1521+
{
1522+
return false;
1523+
}
1524+
1525+
var systemNamespace = runtimeNamespace.ContainingNamespace;
1526+
if (systemNamespace?.Name != "System")
1527+
{
1528+
return false;
1529+
}
1530+
1531+
var globalNamespace = systemNamespace.ContainingNamespace;
1532+
1533+
return globalNamespace != null && globalNamespace.IsGlobalNamespace;
1534+
}
15051535
}
15061536
}

0 commit comments

Comments
 (0)