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.ValueChecks.cs (126)
1361
private bool CheckLocalRefEscape(SyntaxNode node, BoundLocal local,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
1518
private static EscapeLevel? EscapeLevelFromScope(
SafeContext
lifetime) => lifetime switch
1525
private static
SafeContext
GetParameterValEscape(ParameterSymbol parameter)
1529
{ EffectiveScope: ScopedKind.ScopedValue } =>
SafeContext
.CurrentMethod,
1530
{ RefKind: RefKind.Out, UseUpdatedEscapeRules: true } =>
SafeContext
.ReturnOnly,
1531
_ =>
SafeContext
.CallingMethod
1538
private static
SafeContext
GetParameterRefEscape(ParameterSymbol parameter)
1542
{ RefKind: RefKind.None } =>
SafeContext
.CurrentMethod,
1543
{ EffectiveScope: ScopedKind.ScopedRef } =>
SafeContext
.CurrentMethod,
1544
{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, RefKind: RefKind.Out } =>
SafeContext
.ReturnOnly,
1545
{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, IsThis: false } =>
SafeContext
.CallingMethod,
1546
_ =>
SafeContext
.ReturnOnly
1553
private bool CheckParameterValEscape(SyntaxNode node, ParameterSymbol parameter,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
1571
private bool CheckParameterRefEscape(SyntaxNode node, BoundExpression parameter, ParameterSymbol parameterSymbol,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
1573
var
refSafeToEscape = GetParameterRefEscape(parameterSymbol);
1777
private
SafeContext
GetFieldRefEscape(BoundFieldAccess fieldAccess)
1784
return
SafeContext
.CallingMethod;
1800
private bool CheckFieldRefEscape(SyntaxNode node, BoundFieldAccess fieldAccess,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
1824
private bool CheckFieldLikeEventRefEscape(SyntaxNode node, BoundEventAccess eventAccess,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
2232
internal
SafeContext
GetInterpolatedStringHandlerConversionEscapeScope(
2243
SafeContext
escapeScope = GetValEscape(data.Construction);
2264
private
SafeContext
GetInvocationEscapeScope(
2282
SafeContext
getInvocationEscapeWithOldRules(ref readonly MethodInvocationInfo methodInvocationInfo, bool isRefEscape)
2296
SafeContext
escapeScope =
SafeContext
.CallingMethod;
2316
SafeContext
argumentEscape = (isRefEscape, argumentIsRefEscape) switch
2346
private
SafeContext
GetInvocationEscapeWithUpdatedRules(
2351
SafeContext
escapeScope =
SafeContext
.CallingMethod;
2372
SafeContext
argEscape = isArgumentRefEscape ?
2389
private
SafeContext
GetInvocationEscapeToReceiver(
2393
SafeContext
escapeScope =
SafeContext
.CallingMethod;
2400
SafeContext
argEscape = isArgumentRefEscape
2478
SafeContext
escapeTo,
2497
bool checkingReceiver,
SafeContext
escapeTo,
2574
SafeContext
escapeTo,
2627
SafeContext
escapeTo,
3211
SafeContext
escapeTo = _localScopeDepth;
3245
var
inferredDestinationValEscape =
SafeContext
.CallingMethod;
3293
var
toArgEscape = GetValEscape(mixableArg.Argument);
3332
var
inferredDestinationValEscape =
SafeContext
.CallingMethod;
3608
private static ErrorCode GetStandardRValueRefEscapeError(
SafeContext
escapeTo)
3692
internal void ValidateEscape(BoundExpression expr,
SafeContext
escapeTo, bool isByRef, BindingDiagnosticBag diagnostics)
3715
internal
SafeContext
GetRefEscape(BoundExpression expr)
3724
return
SafeContext
.CallingMethod;
3730
return
SafeContext
.CallingMethod;
3747
return
SafeContext
.CallingMethod;
3753
return
SafeContext
.CurrentMethod;
3810
return
SafeContext
.CallingMethod;
3822
return
SafeContext
.CallingMethod;
3877
return
SafeContext
.CallingMethod;
3882
return
SafeContext
.CallingMethod;
3992
internal bool CheckRefEscape(SyntaxNode node, BoundExpression expr,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
4329
internal
SafeContext
GetBroadestValEscape(BoundTupleExpression expr)
4331
SafeContext
broadest = _localScopeDepth;
4334
SafeContext
valEscape;
4355
internal
SafeContext
GetValEscape(BoundExpression expr)
4364
return
SafeContext
.CallingMethod;
4370
return
SafeContext
.CallingMethod;
4376
return
SafeContext
.CallingMethod;
4391
return
SafeContext
.CallingMethod;
4399
return
SafeContext
.CallingMethod;
4411
return
SafeContext
.CallingMethod;
4414
return
SafeContext
.CallingMethod;
4434
return
SafeContext
.CurrentMethod;
4439
var
consEscape = GetValEscape(conditional.Consequence);
4464
return
SafeContext
.CallingMethod;
4476
return
SafeContext
.CallingMethod;
4523
return
SafeContext
.CallingMethod;
4560
var
escape = GetInvocationEscapeScope(
4577
var
escape =
SafeContext
.CallingMethod;
4710
return (range.LeftOperandOpt is { } left ? GetValEscape(left) :
SafeContext
.CallingMethod)
4711
.Intersect(range.RightOperandOpt is { } right ? GetValEscape(right) :
SafeContext
.CallingMethod);
4756
return
SafeContext
.CallingMethod;
4785
private
SafeContext
GetCollectionExpressionSafeContext(BoundCollectionExpression expr)
4789
return
SafeContext
.CallingMethod;
4795
return
SafeContext
.CallingMethod;
4808
?
SafeContext
.CallingMethod
4827
var
receiverScope = expr.CollectionCreation is { } collectionCreation
4830
var
scope = receiverScope;
4833
if (TryGetCollectionExpressionElementValEscape(element, out
var
elementSafeContext))
4845
private bool TryGetCollectionExpressionElementValEscape(BoundNode element, out
SafeContext
safeContext)
4881
private
SafeContext
GetTupleValEscape(ImmutableArray<BoundExpression> elements)
4883
SafeContext
narrowestScope = _localScopeDepth;
4892
private
SafeContext
GetValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr)
4894
var
result =
SafeContext
.CallingMethod;
4911
private
SafeContext
GetValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr)
4913
var
result =
SafeContext
.CallingMethod;
4916
var
exprResult = GetValEscapeOfObjectMemberInitializer(expr);
4923
private
SafeContext
GetValEscapeOfObjectMemberInitializer(BoundExpression expr)
4925
SafeContext
result;
4929
var
rightEscape = assignment.IsRef
4954
SafeContext
getIndexerEscape(
4957
SafeContext
rightEscapeScope)
4963
return
SafeContext
.CallingMethod;
4970
return
SafeContext
.CallingMethod;
4991
SafeContext
receiverEscapeScope =
SafeContext
.CallingMethod;
5001
SafeContext
escapeScope = escapeValue.IsRefEscape
5011
SafeContext
getPropertyEscape(
5013
SafeContext
rightEscapeScope)
5019
return
SafeContext
.CallingMethod;
5028
private
SafeContext
GetValEscape(ImmutableArray<BoundExpression> expressions)
5030
var
result =
SafeContext
.CallingMethod;
5044
internal bool CheckValEscape(SyntaxNode node, BoundExpression expr,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
5137
if (!
SafeContext
.CurrentMethod.IsConvertibleTo(escapeTo))
5391
var
safeContext = GetCollectionExpressionSafeContext((BoundCollectionExpression)conversion.Operand);
5812
private bool CheckTupleValEscape(ImmutableArray<BoundExpression> elements,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5827
private bool CheckValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5852
private bool CheckValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5868
private bool CheckInterpolatedStringHandlerConversionEscape(BoundExpression expression,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5895
private
SafeContext
GetValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression)
5897
SafeContext
scope =
SafeContext
.CallingMethod;
5916
SafeContext
getPartsScope(BoundInterpolatedString interpolatedString)
5918
SafeContext
scope =
SafeContext
.CallingMethod;
5936
private bool CheckValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5959
bool checkParts(BoundInterpolatedString interpolatedString,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
Binder\Binder_Operators.cs (2)
6029
SafeContext
whenTrueEscape = GetValEscape(trueExpr);
6030
SafeContext
whenFalseEscape = GetValEscape(falseExpr);
Binder\Binder_Statements.cs (3)
1570
var
leftEscape = GetRefEscape(op1);
1571
var
rightEscape = GetRefEscape(op2);
1630
var
leftEscape = GetValEscape(op1);
Binder\RefSafetyAnalysis.cs (61)
65
private
SafeContext
_localScopeDepth;
66
private Dictionary<LocalSymbol, (
SafeContext
RefEscapeScope,
SafeContext
ValEscapeScope)>? _localEscapeScopes;
68
private
SafeContext
_patternInputValEscape;
88
_localScopeDepth =
SafeContext
.CurrentMethod;
108
_analysis.AddLocalScopes(local, refEscapeScope: _analysis._localScopeDepth, valEscapeScope:
SafeContext
.CallingMethod);
145
private readonly
SafeContext
_previousInputValEscape;
147
public PatternInput(RefSafetyAnalysis analysis,
SafeContext
patternInputValEscape)
187
public static SafeContextAndLocation Create(
SafeContext
context
200
public readonly
SafeContext
Context;
206
private SafeContextAndLocation(
SafeContext
context
220
private (
SafeContext
RefEscapeScope,
SafeContext
ValEscapeScope) GetLocalScopes(LocalSymbol local)
226
: (
SafeContext
.CurrentMethod,
SafeContext
.CallingMethod);
229
private void SetLocalScopes(LocalSymbol local,
SafeContext
refEscapeScope,
SafeContext
valEscapeScope)
263
private
SafeContext
GetPlaceholderScope(BoundValuePlaceholderBase placeholder)
269
:
SafeContext
.CallingMethod;
410
SafeContext
valEscapeScope = node.ExpressionOpt is { } expr
496
private void AddLocalScopes(LocalSymbol local,
SafeContext
refEscapeScope,
SafeContext
valEscapeScope)
512
SafeContext
.CurrentMethod;
515
SafeContext
.CallingMethod;
523
private void AddOrSetLocalScopes(LocalSymbol local,
SafeContext
refEscapeScope,
SafeContext
valEscapeScope)
525
_localEscapeScopes ??= new Dictionary<LocalSymbol, (
SafeContext
RefEscapeScope,
SafeContext
ValEscapeScope)>();
546
(
SafeContext
refEscapeScope,
SafeContext
valEscapeScope) = GetLocalScopes(localSymbol);
584
ValidateEscape(expr,
SafeContext
.ReturnOnly, node.RefKind != RefKind.None, _diagnostics);
594
ValidateEscape(expr,
SafeContext
.ReturnOnly, isByRef: false, _diagnostics);
648
static
SafeContext
getDeclarationValEscape(BoundTypeExpression typeExpression,
SafeContext
valEscape)
653
return typeExpression.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape :
SafeContext
.CallingMethod;
703
static
SafeContext
getPositionalValEscape(Symbol? symbol,
SafeContext
valEscape)
707
: symbol.GetTypeOrReturnType().IsRefLikeOrAllowsRefLikeType() ? valEscape :
SafeContext
.CallingMethod;
716
static
SafeContext
getMemberValEscape(BoundPropertySubpatternMember? member,
SafeContext
valEscape)
720
return member.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape :
SafeContext
.CallingMethod;
882
SafeContext
valEscapeScope;
893
valEscapeScope =
SafeContext
.CallingMethod;
920
SafeContext
getArgumentEscapeScope(int nArgumentsVisited, ImmutableArray<BoundExpression> arguments, int argIndex)
922
SafeContext
valEscapeScope;
930
valEscapeScope =
SafeContext
.CallingMethod; // Consider skipping this placeholder entirely since SafeContext.CallingMethod is the fallback in GetPlaceholderScope().
987
var
escapeFrom = GetValEscape(node.InitializerExpressionOpt);
992
private void VisitObjectCreationWithInitializer(BoundObjectCreationExpressionBase node, in MethodInvocationInfo methodInvocationInfo,
SafeContext
initializerEscape)
1093
private void GetAwaitableInstancePlaceholders(ArrayBuilder<(BoundValuePlaceholderBase, SafeContextAndLocation)> placeholders, BoundAwaitableInfo awaitableInfo,
SafeContext
valEscapeScope)
1167
SafeContext
valEscape = nestedVariables is null
1208
internal readonly
SafeContext
ValEscape;
1211
internal DeconstructionVariable(BoundExpression expression,
SafeContext
valEscape, ArrayBuilder<DeconstructionVariable>? nestedVariables)
1232
? new DeconstructionVariable(expr, valEscape:
SafeContext
.Empty, GetDeconstructionAssignmentVariables(tuple))
1259
SafeContext
collectionEscape;
1320
SafeContext
receiverScope;
1331
var
safeContext = node.Elements.Length == 0 || LocalRewriter.ShouldUseRuntimeHelpersCreateSpan(node, elementType.Type)
1332
?
SafeContext
.CallingMethod
1355
var
elementsScope =
SafeContext
.CallingMethod;
1380
if (TryGetCollectionExpressionElementValEscape(element, out
var
spreadEscape))
1410
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)