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);
209 references to SafeContext
Microsoft.CodeAnalysis.CSharp (209)
Binder\Binder_Operators.cs (2)
6053
SafeContext
whenTrueEscape = GetValEscape(trueExpr);
6054
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)
1358
private bool CheckLocalRefEscape(SyntaxNode node, BoundLocal local,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
1515
private static EscapeLevel? EscapeLevelFromScope(
SafeContext
lifetime) => lifetime switch
1522
private static
SafeContext
GetParameterValEscape(ParameterSymbol parameter)
1526
{ EffectiveScope: ScopedKind.ScopedValue } =>
SafeContext
.CurrentMethod,
1527
{ RefKind: RefKind.Out, UseUpdatedEscapeRules: true } =>
SafeContext
.ReturnOnly,
1528
_ =>
SafeContext
.CallingMethod
1535
private static
SafeContext
GetParameterRefEscape(ParameterSymbol parameter)
1539
{ RefKind: RefKind.None } =>
SafeContext
.CurrentMethod,
1540
{ EffectiveScope: ScopedKind.ScopedRef } =>
SafeContext
.CurrentMethod,
1541
{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, RefKind: RefKind.Out } =>
SafeContext
.ReturnOnly,
1542
{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, IsThis: false } =>
SafeContext
.CallingMethod,
1543
_ =>
SafeContext
.ReturnOnly
1550
private bool CheckParameterValEscape(SyntaxNode node, ParameterSymbol parameter,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
1568
private bool CheckParameterRefEscape(SyntaxNode node, BoundExpression parameter, ParameterSymbol parameterSymbol,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
1570
var
refSafeToEscape = GetParameterRefEscape(parameterSymbol);
1774
private
SafeContext
GetFieldRefEscape(BoundFieldAccess fieldAccess)
1781
return
SafeContext
.CallingMethod;
1797
private bool CheckFieldRefEscape(SyntaxNode node, BoundFieldAccess fieldAccess,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
1821
private bool CheckFieldLikeEventRefEscape(SyntaxNode node, BoundEventAccess eventAccess,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
2230
internal
SafeContext
GetInterpolatedStringHandlerConversionEscapeScope(
2241
SafeContext
escapeScope = GetValEscape(data.Construction);
2262
private
SafeContext
GetInvocationEscapeScope(
2280
SafeContext
getInvocationEscapeWithOldRules(ref readonly MethodInvocationInfo methodInvocationInfo, bool isRefEscape)
2294
SafeContext
escapeScope =
SafeContext
.CallingMethod;
2314
SafeContext
argumentEscape = (isRefEscape, argumentIsRefEscape) switch
2344
private
SafeContext
GetInvocationEscapeWithUpdatedRules(
2349
SafeContext
escapeScope =
SafeContext
.CallingMethod;
2370
SafeContext
argEscape = isArgumentRefEscape ?
2387
private
SafeContext
GetInvocationEscapeToReceiver(
2391
SafeContext
escapeScope =
SafeContext
.CallingMethod;
2398
SafeContext
argEscape = isArgumentRefEscape
2476
SafeContext
escapeTo,
2495
bool checkingReceiver,
SafeContext
escapeTo,
2572
SafeContext
escapeTo,
2625
SafeContext
escapeTo,
3184
SafeContext
escapeTo = _localScopeDepth;
3218
var
inferredDestinationValEscape =
SafeContext
.CallingMethod;
3266
var
toArgEscape = GetValEscape(mixableArg.Argument);
3305
var
inferredDestinationValEscape =
SafeContext
.CallingMethod;
3584
private static ErrorCode GetStandardRValueRefEscapeError(
SafeContext
escapeTo)
3668
internal void ValidateEscape(BoundExpression expr,
SafeContext
escapeTo, bool isByRef, BindingDiagnosticBag diagnostics)
3691
internal
SafeContext
GetRefEscape(BoundExpression expr)
3700
return
SafeContext
.CallingMethod;
3706
return
SafeContext
.CallingMethod;
3723
return
SafeContext
.CallingMethod;
3729
return
SafeContext
.CurrentMethod;
3790
return
SafeContext
.CallingMethod;
3802
return
SafeContext
.CallingMethod;
3857
return
SafeContext
.CallingMethod;
3862
return
SafeContext
.CallingMethod;
3972
internal bool CheckRefEscape(SyntaxNode node, BoundExpression expr,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
4313
internal
SafeContext
GetBroadestValEscape(BoundTupleExpression expr)
4315
SafeContext
broadest = _localScopeDepth;
4318
SafeContext
valEscape;
4339
internal
SafeContext
GetValEscape(BoundExpression expr)
4348
return
SafeContext
.CallingMethod;
4354
return
SafeContext
.CallingMethod;
4360
return
SafeContext
.CallingMethod;
4375
return
SafeContext
.CallingMethod;
4383
return
SafeContext
.CallingMethod;
4395
return
SafeContext
.CallingMethod;
4398
return
SafeContext
.CallingMethod;
4422
return
SafeContext
.CurrentMethod;
4427
var
consEscape = GetValEscape(conditional.Consequence);
4452
return
SafeContext
.CallingMethod;
4464
return
SafeContext
.CallingMethod;
4511
return
SafeContext
.CallingMethod;
4548
var
escape = GetInvocationEscapeScope(
4565
var
escape =
SafeContext
.CallingMethod;
4698
return (range.LeftOperandOpt is { } left ? GetValEscape(left) :
SafeContext
.CallingMethod)
4699
.Intersect(range.RightOperandOpt is { } right ? GetValEscape(right) :
SafeContext
.CallingMethod);
4744
return
SafeContext
.CallingMethod;
4773
private
SafeContext
GetCollectionExpressionSafeContext(BoundCollectionExpression expr)
4777
return
SafeContext
.CallingMethod;
4783
return
SafeContext
.CallingMethod;
4796
?
SafeContext
.CallingMethod
4815
var
receiverScope = expr.CollectionCreation is { } collectionCreation
4818
var
scope = receiverScope;
4821
if (TryGetCollectionExpressionElementValEscape(element, out
var
elementSafeContext))
4833
private bool TryGetCollectionExpressionElementValEscape(BoundNode element, out
SafeContext
safeContext)
4869
private
SafeContext
GetTupleValEscape(ImmutableArray<BoundExpression> elements)
4871
SafeContext
narrowestScope = _localScopeDepth;
4880
private
SafeContext
GetValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr)
4882
var
result =
SafeContext
.CallingMethod;
4899
private
SafeContext
GetValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr)
4901
var
result =
SafeContext
.CallingMethod;
4904
var
exprResult = GetValEscapeOfObjectMemberInitializer(expr);
4911
private
SafeContext
GetValEscapeOfObjectMemberInitializer(BoundExpression expr)
4913
SafeContext
result;
4917
var
rightEscape = assignment.IsRef
4942
SafeContext
getIndexerEscape(
4945
SafeContext
rightEscapeScope)
4951
return
SafeContext
.CallingMethod;
4958
return
SafeContext
.CallingMethod;
4979
SafeContext
receiverEscapeScope =
SafeContext
.CallingMethod;
4989
SafeContext
escapeScope = escapeValue.IsRefEscape
4999
SafeContext
getPropertyEscape(
5001
SafeContext
rightEscapeScope)
5007
return
SafeContext
.CallingMethod;
5016
private
SafeContext
GetValEscape(ImmutableArray<BoundExpression> expressions)
5018
var
result =
SafeContext
.CallingMethod;
5032
internal bool CheckValEscape(SyntaxNode node, BoundExpression expr,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
5125
if (!
SafeContext
.CurrentMethod.IsConvertibleTo(escapeTo))
5383
var
safeContext = GetCollectionExpressionSafeContext((BoundCollectionExpression)conversion.Operand);
5804
private bool CheckTupleValEscape(ImmutableArray<BoundExpression> elements,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5819
private bool CheckValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5844
private bool CheckValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5860
private bool CheckInterpolatedStringHandlerConversionEscape(BoundExpression expression,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5887
private
SafeContext
GetValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression)
5889
SafeContext
scope =
SafeContext
.CallingMethod;
5908
SafeContext
getPartsScope(BoundInterpolatedString interpolatedString)
5910
SafeContext
scope =
SafeContext
.CallingMethod;
5928
private bool CheckValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5951
bool checkParts(BoundInterpolatedString interpolatedString,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
Binder\RefSafetyAnalysis.cs (61)
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;
416
SafeContext
valEscapeScope = node.ExpressionOpt is { } expr
502
private void AddLocalScopes(LocalSymbol local,
SafeContext
refEscapeScope,
SafeContext
valEscapeScope)
518
SafeContext
.CurrentMethod;
521
SafeContext
.CallingMethod;
529
private void AddOrSetLocalScopes(LocalSymbol local,
SafeContext
refEscapeScope,
SafeContext
valEscapeScope)
531
_localEscapeScopes ??= new Dictionary<LocalSymbol, (
SafeContext
RefEscapeScope,
SafeContext
ValEscapeScope)>();
552
(
SafeContext
refEscapeScope,
SafeContext
valEscapeScope) = GetLocalScopes(localSymbol);
590
ValidateEscape(expr,
SafeContext
.ReturnOnly, node.RefKind != RefKind.None, _diagnostics);
600
ValidateEscape(expr,
SafeContext
.ReturnOnly, isByRef: false, _diagnostics);
669
static
SafeContext
getDeclarationValEscape(BoundTypeExpression typeExpression,
SafeContext
valEscape)
674
return typeExpression.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape :
SafeContext
.CallingMethod;
724
static
SafeContext
getPositionalValEscape(Symbol? symbol,
SafeContext
valEscape)
728
: symbol.GetTypeOrReturnType().IsRefLikeOrAllowsRefLikeType() ? valEscape :
SafeContext
.CallingMethod;
737
static
SafeContext
getMemberValEscape(BoundPropertySubpatternMember? member,
SafeContext
valEscape)
741
return member.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape :
SafeContext
.CallingMethod;
904
SafeContext
valEscapeScope;
915
valEscapeScope =
SafeContext
.CallingMethod;
942
SafeContext
getArgumentEscapeScope(int nArgumentsVisited, ImmutableArray<BoundExpression> arguments, int argIndex)
944
SafeContext
valEscapeScope;
952
valEscapeScope =
SafeContext
.CallingMethod; // Consider skipping this placeholder entirely since SafeContext.CallingMethod is the fallback in GetPlaceholderScope().
1009
var
escapeFrom = GetValEscape(node.InitializerExpressionOpt);
1014
private void VisitObjectCreationWithInitializer(BoundObjectCreationExpressionBase node, in MethodInvocationInfo methodInvocationInfo,
SafeContext
initializerEscape)
1128
private void GetAwaitableInstancePlaceholders(ArrayBuilder<(BoundValuePlaceholderBase, SafeContextAndLocation)> placeholders, BoundAwaitableInfo awaitableInfo,
SafeContext
valEscapeScope)
1202
SafeContext
valEscape = nestedVariables is null
1243
internal readonly
SafeContext
ValEscape;
1246
internal DeconstructionVariable(BoundExpression expression,
SafeContext
valEscape, ArrayBuilder<DeconstructionVariable>? nestedVariables)
1267
? new DeconstructionVariable(expr, valEscape:
SafeContext
.Empty, GetDeconstructionAssignmentVariables(tuple))
1294
SafeContext
collectionEscape;
1355
SafeContext
receiverScope;
1366
var
safeContext = node.Elements.Length == 0 || LocalRewriter.ShouldUseRuntimeHelpersCreateSpan(node, elementType.Type)
1367
?
SafeContext
.CallingMethod
1390
var
elementsScope =
SafeContext
.CallingMethod;
1415
if (TryGetCollectionExpressionElementValEscape(element, out
var
spreadEscape))
1445
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)