6 instantiations of SafeContext
Microsoft.CodeAnalysis.CSharp (6)
Binder\SafeContext.cs (6)
41
public static readonly SafeContext CallingMethod = new
SafeContext
(CallingMethodRaw);
47
public static readonly SafeContext ReturnOnly = new
SafeContext
(ReturnOnlyRaw);
53
public static readonly SafeContext CurrentMethod = new
SafeContext
(CurrentMethodRaw);
58
public static readonly SafeContext Empty = new
SafeContext
(uint.MaxValue);
67
return new
SafeContext
(_value + 1);
77
return new
SafeContext
(_value - 1);
211 references to SafeContext
Microsoft.CodeAnalysis.CSharp (211)
Binder\Binder_Operators.cs (2)
6056
SafeContext
whenTrueEscape = GetValEscape(trueExpr);
6057
SafeContext
whenFalseEscape = GetValEscape(falseExpr);
Binder\Binder_Statements.cs (3)
1570
var
leftEscape = GetRefEscape(op1);
1571
var
rightEscape = GetRefEscape(op2);
1629
var
leftEscape = GetValEscape(op1);
Binder\Binder.ValueChecks.cs (126)
1342
private bool CheckLocalRefEscape(SyntaxNode node, BoundLocal local,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
1499
private static EscapeLevel? EscapeLevelFromScope(
SafeContext
lifetime) => lifetime switch
1506
private static
SafeContext
GetParameterValEscape(ParameterSymbol parameter)
1510
{ EffectiveScope: ScopedKind.ScopedValue } =>
SafeContext
.CurrentMethod,
1511
{ RefKind: RefKind.Out, UseUpdatedEscapeRules: true } =>
SafeContext
.ReturnOnly,
1512
_ =>
SafeContext
.CallingMethod
1519
private static
SafeContext
GetParameterRefEscape(ParameterSymbol parameter)
1523
{ RefKind: RefKind.None } =>
SafeContext
.CurrentMethod,
1524
{ EffectiveScope: ScopedKind.ScopedRef } =>
SafeContext
.CurrentMethod,
1525
{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, RefKind: RefKind.Out } =>
SafeContext
.ReturnOnly,
1526
{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, IsThis: false } =>
SafeContext
.CallingMethod,
1527
_ =>
SafeContext
.ReturnOnly
1534
private bool CheckParameterValEscape(SyntaxNode node, ParameterSymbol parameter,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
1552
private bool CheckParameterRefEscape(SyntaxNode node, BoundExpression parameter, ParameterSymbol parameterSymbol,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
1554
var
refSafeToEscape = GetParameterRefEscape(parameterSymbol);
1758
private
SafeContext
GetFieldRefEscape(BoundFieldAccess fieldAccess)
1765
return
SafeContext
.CallingMethod;
1781
private bool CheckFieldRefEscape(SyntaxNode node, BoundFieldAccess fieldAccess,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
1805
private bool CheckFieldLikeEventRefEscape(SyntaxNode node, BoundEventAccess eventAccess,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
2214
internal
SafeContext
GetInterpolatedStringHandlerConversionEscapeScope(
2225
SafeContext
escapeScope = GetValEscape(data.Construction);
2246
private
SafeContext
GetInvocationEscapeScope(
2264
SafeContext
getInvocationEscapeWithOldRules(ref readonly MethodInvocationInfo methodInvocationInfo, bool isRefEscape)
2278
SafeContext
escapeScope =
SafeContext
.CallingMethod;
2298
SafeContext
argumentEscape = (isRefEscape, argumentIsRefEscape) switch
2328
private
SafeContext
GetInvocationEscapeWithUpdatedRules(
2333
SafeContext
escapeScope =
SafeContext
.CallingMethod;
2354
SafeContext
argEscape = isArgumentRefEscape ?
2371
private
SafeContext
GetInvocationEscapeToReceiver(
2375
SafeContext
escapeScope =
SafeContext
.CallingMethod;
2382
SafeContext
argEscape = isArgumentRefEscape
2460
SafeContext
escapeTo,
2479
bool checkingReceiver,
SafeContext
escapeTo,
2556
SafeContext
escapeTo,
2609
SafeContext
escapeTo,
3168
SafeContext
escapeTo = _localScopeDepth;
3202
var
inferredDestinationValEscape =
SafeContext
.CallingMethod;
3250
var
toArgEscape = GetValEscape(mixableArg.Argument);
3289
var
inferredDestinationValEscape =
SafeContext
.CallingMethod;
3568
private static ErrorCode GetStandardRValueRefEscapeError(
SafeContext
escapeTo)
3652
internal void ValidateEscape(BoundExpression expr,
SafeContext
escapeTo, bool isByRef, BindingDiagnosticBag diagnostics)
3675
internal
SafeContext
GetRefEscape(BoundExpression expr)
3684
return
SafeContext
.CallingMethod;
3690
return
SafeContext
.CallingMethod;
3707
return
SafeContext
.CallingMethod;
3713
return
SafeContext
.CurrentMethod;
3774
return
SafeContext
.CallingMethod;
3786
return
SafeContext
.CallingMethod;
3841
return
SafeContext
.CallingMethod;
3846
return
SafeContext
.CallingMethod;
3956
internal bool CheckRefEscape(SyntaxNode node, BoundExpression expr,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
4297
internal
SafeContext
GetBroadestValEscape(BoundTupleExpression expr)
4299
SafeContext
broadest = _localScopeDepth;
4302
SafeContext
valEscape;
4323
internal
SafeContext
GetValEscape(BoundExpression expr)
4332
return
SafeContext
.CallingMethod;
4338
return
SafeContext
.CallingMethod;
4344
return
SafeContext
.CallingMethod;
4359
return
SafeContext
.CallingMethod;
4367
return
SafeContext
.CallingMethod;
4379
return
SafeContext
.CallingMethod;
4382
return
SafeContext
.CallingMethod;
4406
return
SafeContext
.CurrentMethod;
4411
var
consEscape = GetValEscape(conditional.Consequence);
4436
return
SafeContext
.CallingMethod;
4448
return
SafeContext
.CallingMethod;
4495
return
SafeContext
.CallingMethod;
4532
var
escape = GetInvocationEscapeScope(
4549
var
escape =
SafeContext
.CallingMethod;
4682
return (range.LeftOperandOpt is { } left ? GetValEscape(left) :
SafeContext
.CallingMethod)
4683
.Intersect(range.RightOperandOpt is { } right ? GetValEscape(right) :
SafeContext
.CallingMethod);
4728
return
SafeContext
.CallingMethod;
4757
private
SafeContext
GetCollectionExpressionSafeContext(BoundCollectionExpression expr)
4761
return
SafeContext
.CallingMethod;
4767
return
SafeContext
.CallingMethod;
4780
?
SafeContext
.CallingMethod
4799
var
receiverScope = expr.CollectionCreation is { } collectionCreation
4802
var
scope = receiverScope;
4805
if (TryGetCollectionExpressionElementValEscape(element, out
var
elementSafeContext))
4817
private bool TryGetCollectionExpressionElementValEscape(BoundNode element, out
SafeContext
safeContext)
4853
private
SafeContext
GetTupleValEscape(ImmutableArray<BoundExpression> elements)
4855
SafeContext
narrowestScope = _localScopeDepth;
4864
private
SafeContext
GetValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr)
4866
var
result =
SafeContext
.CallingMethod;
4883
private
SafeContext
GetValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr)
4885
var
result =
SafeContext
.CallingMethod;
4888
var
exprResult = GetValEscapeOfObjectMemberInitializer(expr);
4895
private
SafeContext
GetValEscapeOfObjectMemberInitializer(BoundExpression expr)
4897
SafeContext
result;
4901
var
rightEscape = assignment.IsRef
4926
SafeContext
getIndexerEscape(
4929
SafeContext
rightEscapeScope)
4935
return
SafeContext
.CallingMethod;
4942
return
SafeContext
.CallingMethod;
4963
SafeContext
receiverEscapeScope =
SafeContext
.CallingMethod;
4973
SafeContext
escapeScope = escapeValue.IsRefEscape
4983
SafeContext
getPropertyEscape(
4985
SafeContext
rightEscapeScope)
4991
return
SafeContext
.CallingMethod;
5000
private
SafeContext
GetValEscape(ImmutableArray<BoundExpression> expressions)
5002
var
result =
SafeContext
.CallingMethod;
5016
internal bool CheckValEscape(SyntaxNode node, BoundExpression expr,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
5109
if (!
SafeContext
.CurrentMethod.IsConvertibleTo(escapeTo))
5367
var
safeContext = GetCollectionExpressionSafeContext((BoundCollectionExpression)conversion.Operand);
5788
private bool CheckTupleValEscape(ImmutableArray<BoundExpression> elements,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5803
private bool CheckValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5828
private bool CheckValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5844
private bool CheckInterpolatedStringHandlerConversionEscape(BoundExpression expression,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5871
private
SafeContext
GetValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression)
5873
SafeContext
scope =
SafeContext
.CallingMethod;
5892
SafeContext
getPartsScope(BoundInterpolatedString interpolatedString)
5894
SafeContext
scope =
SafeContext
.CallingMethod;
5912
private bool CheckValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5935
bool checkParts(BoundInterpolatedString interpolatedString,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
Binder\RefSafetyAnalysis.cs (63)
70
private
SafeContext
_localScopeDepth;
71
private Dictionary<LocalSymbol, (
SafeContext
RefEscapeScope,
SafeContext
ValEscapeScope)>? _localEscapeScopes;
73
private
SafeContext
_patternInputValEscape;
93
_localScopeDepth =
SafeContext
.CurrentMethod;
113
_analysis.AddLocalScopes(local, refEscapeScope: _analysis._localScopeDepth, valEscapeScope:
SafeContext
.CallingMethod);
150
private readonly
SafeContext
_previousInputValEscape;
152
public PatternInput(RefSafetyAnalysis analysis,
SafeContext
patternInputValEscape)
192
public static SafeContextAndLocation Create(
SafeContext
context
205
public readonly
SafeContext
Context;
211
private SafeContextAndLocation(
SafeContext
context
225
private (
SafeContext
RefEscapeScope,
SafeContext
ValEscapeScope) GetLocalScopes(LocalSymbol local)
231
: (
SafeContext
.CurrentMethod,
SafeContext
.CallingMethod);
234
private void SetLocalScopes(LocalSymbol local,
SafeContext
refEscapeScope,
SafeContext
valEscapeScope)
268
private
SafeContext
GetPlaceholderScope(BoundValuePlaceholderBase placeholder)
274
:
SafeContext
.CallingMethod;
401
var
originalDepth = _localScopeDepth;
409
var
originalDepth = _localScopeDepth;
452
SafeContext
valEscapeScope = node.ExpressionOpt is { } expr
551
private void AddLocalScopes(LocalSymbol local,
SafeContext
refEscapeScope,
SafeContext
valEscapeScope)
567
SafeContext
.CurrentMethod;
570
SafeContext
.CallingMethod;
578
private void AddOrSetLocalScopes(LocalSymbol local,
SafeContext
refEscapeScope,
SafeContext
valEscapeScope)
580
_localEscapeScopes ??= new Dictionary<LocalSymbol, (
SafeContext
RefEscapeScope,
SafeContext
ValEscapeScope)>();
601
(
SafeContext
refEscapeScope,
SafeContext
valEscapeScope) = GetLocalScopes(localSymbol);
639
ValidateEscape(expr,
SafeContext
.ReturnOnly, node.RefKind != RefKind.None, _diagnostics);
649
ValidateEscape(expr,
SafeContext
.ReturnOnly, isByRef: false, _diagnostics);
718
static
SafeContext
getDeclarationValEscape(BoundTypeExpression typeExpression,
SafeContext
valEscape)
723
return typeExpression.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape :
SafeContext
.CallingMethod;
773
static
SafeContext
getPositionalValEscape(Symbol? symbol,
SafeContext
valEscape)
777
: symbol.GetTypeOrReturnType().IsRefLikeOrAllowsRefLikeType() ? valEscape :
SafeContext
.CallingMethod;
786
static
SafeContext
getMemberValEscape(BoundPropertySubpatternMember? member,
SafeContext
valEscape)
790
return member.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape :
SafeContext
.CallingMethod;
953
SafeContext
valEscapeScope;
964
valEscapeScope =
SafeContext
.CallingMethod;
991
SafeContext
getArgumentEscapeScope(int nArgumentsVisited, ImmutableArray<BoundExpression> arguments, int argIndex)
993
SafeContext
valEscapeScope;
1001
valEscapeScope =
SafeContext
.CallingMethod; // Consider skipping this placeholder entirely since SafeContext.CallingMethod is the fallback in GetPlaceholderScope().
1058
var
escapeFrom = GetValEscape(node.InitializerExpressionOpt);
1063
private void VisitObjectCreationWithInitializer(BoundObjectCreationExpressionBase node, in MethodInvocationInfo methodInvocationInfo,
SafeContext
initializerEscape)
1177
private void GetAwaitableInstancePlaceholders(ArrayBuilder<(BoundValuePlaceholderBase, SafeContextAndLocation)> placeholders, BoundAwaitableInfo awaitableInfo,
SafeContext
valEscapeScope)
1251
SafeContext
valEscape = nestedVariables is null
1292
internal readonly
SafeContext
ValEscape;
1295
internal DeconstructionVariable(BoundExpression expression,
SafeContext
valEscape, ArrayBuilder<DeconstructionVariable>? nestedVariables)
1316
? new DeconstructionVariable(expr, valEscape:
SafeContext
.Empty, GetDeconstructionAssignmentVariables(tuple))
1343
SafeContext
collectionEscape;
1404
SafeContext
receiverScope;
1415
var
safeContext = node.Elements.Length == 0 || LocalRewriter.ShouldUseRuntimeHelpersCreateSpan(node, elementType.Type)
1416
?
SafeContext
.CallingMethod
1439
var
elementsScope =
SafeContext
.CallingMethod;
1464
if (TryGetCollectionExpressionElementValEscape(element, out
var
spreadEscape))
1494
if (TryGetCollectionExpressionElementValEscape(element, out
var
elementSafeContext))
Binder\SafeContext.cs (17)
41
public static readonly
SafeContext
CallingMethod = new SafeContext(CallingMethodRaw);
47
public static readonly
SafeContext
ReturnOnly = new SafeContext(ReturnOnlyRaw);
53
public static readonly
SafeContext
CurrentMethod = new SafeContext(CurrentMethodRaw);
58
public static readonly
SafeContext
Empty = new SafeContext(uint.MaxValue);
64
public
SafeContext
Narrower()
74
public
SafeContext
Wider()
86
public bool IsConvertibleTo(
SafeContext
other)
97
public
SafeContext
Intersect(
SafeContext
other)
104
public
SafeContext
Union(
SafeContext
other)
108
public bool Equals(
SafeContext
other)
112
=> obj is
SafeContext
other && this.Equals(other);
117
public static bool operator ==(
SafeContext
lhs,
SafeContext
rhs)
120
public static bool operator !=(
SafeContext
lhs,
SafeContext
rhs)