Skip to content
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

Implement control flow graph for Lock object feature #71987

Merged
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/Compilers/CSharp/Portable/Binder/LockBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,31 +78,30 @@ internal override BoundStatement BindLockStatementParts(BindingDiagnosticBag dia
return new BoundLockStatement(_syntax, expr, stmt, hasErrors);
}

// Keep consistent with ISymbolExtensions.TryFindLockTypeInfo.
internal static LockTypeInfo? TryFindLockTypeInfo(TypeSymbol lockType, BindingDiagnosticBag diagnostics, SyntaxNode syntax)
{
const string LockTypeFullName = "System.Threading.Lock";
const string EnterLockScopeMethodName = "EnterLockScope";
const string LockScopeTypeName = "Scope";
const string LockTypeFullName = $"{nameof(System)}.{nameof(System.Threading)}.{WellKnownMemberNames.LockTypeName}";
jjonescz marked this conversation as resolved.
Show resolved Hide resolved

var enterLockScopeMethod = TryFindPublicVoidParameterlessMethod(lockType, EnterLockScopeMethodName);
var enterLockScopeMethod = TryFindPublicVoidParameterlessMethod(lockType, WellKnownMemberNames.EnterLockScopeMethodName);
if (enterLockScopeMethod is not { ReturnsVoid: false, RefKind: RefKind.None })
{
Error(diagnostics, ErrorCode.ERR_MissingPredefinedMember, syntax, LockTypeFullName, EnterLockScopeMethodName);
Error(diagnostics, ErrorCode.ERR_MissingPredefinedMember, syntax, LockTypeFullName, WellKnownMemberNames.EnterLockScopeMethodName);
return null;
}

var scopeType = enterLockScopeMethod.ReturnType;
if (!(scopeType is NamedTypeSymbol { Name: LockScopeTypeName, Arity: 0, IsValueType: true, IsRefLikeType: true, DeclaredAccessibility: Accessibility.Public } &&
if (!(scopeType is NamedTypeSymbol { Name: WellKnownMemberNames.LockScopeTypeName, Arity: 0, IsValueType: true, IsRefLikeType: true, DeclaredAccessibility: Accessibility.Public } &&
TypeSymbol.Equals(scopeType.ContainingType, lockType, TypeCompareKind.ConsiderEverything)))
{
Error(diagnostics, ErrorCode.ERR_MissingPredefinedMember, syntax, LockTypeFullName, EnterLockScopeMethodName);
Error(diagnostics, ErrorCode.ERR_MissingPredefinedMember, syntax, LockTypeFullName, WellKnownMemberNames.EnterLockScopeMethodName);
return null;
}

var disposeMethod = TryFindPublicVoidParameterlessMethod(scopeType, WellKnownMemberNames.DisposeMethodName);
if (disposeMethod is not { ReturnsVoid: true })
{
Error(diagnostics, ErrorCode.ERR_MissingPredefinedMember, syntax, $"{LockTypeFullName}+{LockScopeTypeName}", WellKnownMemberNames.DisposeMethodName);
Error(diagnostics, ErrorCode.ERR_MissingPredefinedMember, syntax, $"{LockTypeFullName}+{WellKnownMemberNames.LockScopeTypeName}", WellKnownMemberNames.DisposeMethodName);
return null;
}

Expand All @@ -114,6 +113,7 @@ internal override BoundStatement BindLockStatementParts(BindingDiagnosticBag dia
};
}

// Keep consistent with ISymbolExtensions.TryFindPublicVoidParameterlessMethod.
private static MethodSymbol? TryFindPublicVoidParameterlessMethod(TypeSymbol type, string name)
{
var members = type.GetMembers(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2078,10 +2078,11 @@ internal static bool IsWellKnownTypeIsExternalInit(this TypeSymbol typeSymbol)

internal static bool IsWellKnownTypeOutAttribute(this TypeSymbol typeSymbol) => typeSymbol.IsWellKnownInteropServicesTopLevelType("OutAttribute");

// Keep consistent with ISymbolExtensions.IsWellKnownTypeLock and VB equivalent.
internal static bool IsWellKnownTypeLock(this TypeSymbol typeSymbol)
{
return typeSymbol is NamedTypeSymbol { Name: "Lock", Arity: 0, ContainingType: null } &&
typeSymbol.IsContainedInNamespace("System", "Threading");
return typeSymbol is NamedTypeSymbol { Name: WellKnownMemberNames.LockTypeName, Arity: 0, ContainingType: null } &&
jjonescz marked this conversation as resolved.
Show resolved Hide resolved
typeSymbol.IsContainedInNamespace(nameof(System), nameof(System.Threading));
}

private static bool IsWellKnownInteropServicesTopLevelType(this TypeSymbol typeSymbol, string name)
Expand Down
Loading