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);
216 references to SafeContext
Microsoft.CodeAnalysis.CSharp (216)
Binder\Binder.ValueChecks.cs (128)
1090
private bool CheckLocalRefEscape(SyntaxNode node, BoundLocal local,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
1247
private static EscapeLevel? EscapeLevelFromScope(
SafeContext
lifetime) => lifetime switch
1254
private static
SafeContext
GetParameterValEscape(ParameterSymbol parameter)
1258
{ EffectiveScope: ScopedKind.ScopedValue } =>
SafeContext
.CurrentMethod,
1259
{ RefKind: RefKind.Out, UseUpdatedEscapeRules: true } =>
SafeContext
.ReturnOnly,
1260
_ =>
SafeContext
.CallingMethod
1267
private static
SafeContext
GetParameterRefEscape(ParameterSymbol parameter)
1271
{ RefKind: RefKind.None } =>
SafeContext
.CurrentMethod,
1272
{ EffectiveScope: ScopedKind.ScopedRef } =>
SafeContext
.CurrentMethod,
1273
{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, RefKind: RefKind.Out } =>
SafeContext
.ReturnOnly,
1274
{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, IsThis: false } =>
SafeContext
.CallingMethod,
1275
_ =>
SafeContext
.ReturnOnly
1282
private bool CheckParameterValEscape(SyntaxNode node, ParameterSymbol parameter,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
1300
private bool CheckParameterRefEscape(SyntaxNode node, BoundExpression parameter, ParameterSymbol parameterSymbol,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
1302
var
refSafeToEscape = GetParameterRefEscape(parameterSymbol);
1506
private
SafeContext
GetFieldRefEscape(BoundFieldAccess fieldAccess,
SafeContext
localScopeDepth)
1513
return
SafeContext
.CallingMethod;
1529
private bool CheckFieldRefEscape(SyntaxNode node, BoundFieldAccess fieldAccess,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
1553
private bool CheckFieldLikeEventRefEscape(SyntaxNode node, BoundEventAccess eventAccess,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
1951
internal
SafeContext
GetInterpolatedStringHandlerConversionEscapeScope(
1953
SafeContext
localScopeDepth)
1963
SafeContext
escapeScope = GetValEscape(data.Construction, localScopeDepth);
1973
SafeContext
argEscape = GetValEscape(argument, localScopeDepth);
1991
private
SafeContext
GetInvocationEscapeScope(
1999
SafeContext
localScopeDepth,
2016
SafeContext
getInvocationEscapeWithOldRules(MethodInfo methodInfo, ImmutableArray<ParameterSymbol> parameters, BoundExpression? receiver, ImmutableArray<BoundExpression> argsOpt, ImmutableArray<RefKind> argRefKindsOpt, ImmutableArray<int> argsToParamsOpt,
SafeContext
localScopeDepth, bool isRefEscape)
2030
SafeContext
escapeScope =
SafeContext
.CallingMethod;
2057
SafeContext
argumentEscape = (isRefEscape, argumentIsRefEscape) switch
2087
private
SafeContext
GetInvocationEscapeWithUpdatedRules(
2095
SafeContext
localScopeDepth,
2099
SafeContext
escapeScope =
SafeContext
.CallingMethod;
2126
SafeContext
argEscape = isArgumentRefEscape ?
2205
SafeContext
escapeFrom,
2206
SafeContext
escapeTo,
2227
bool checkingReceiver,
SafeContext
escapeFrom,
SafeContext
escapeTo,
2309
SafeContext
escapeFrom,
2310
SafeContext
escapeTo,
2873
SafeContext
localScopeDepth,
2888
SafeContext
localScopeDepth, BindingDiagnosticBag diagnostics, Symbol symbolForReporting)
2903
SafeContext
escapeTo = localScopeDepth;
2943
var
inferredDestinationValEscape =
SafeContext
.CallingMethod;
2983
SafeContext
localScopeDepth,
3004
var
toArgEscape = GetValEscape(mixableArg.Argument, localScopeDepth);
3039
void inferDeclarationExpressionValEscape(ImmutableArray<BoundExpression> argsOpt,
SafeContext
localScopeDepth, ArrayBuilder<EscapeValue> escapeValues)
3043
var
inferredDestinationValEscape =
SafeContext
.CallingMethod;
3317
private static ErrorCode GetStandardRValueRefEscapeError(
SafeContext
escapeTo)
3401
internal void ValidateEscape(BoundExpression expr,
SafeContext
escapeTo, bool isByRef, BindingDiagnosticBag diagnostics)
3424
internal
SafeContext
GetRefEscape(BoundExpression expr,
SafeContext
localScopeDepth)
3433
return
SafeContext
.CallingMethod;
3439
return
SafeContext
.CallingMethod;
3456
return
SafeContext
.CallingMethod;
3462
return
SafeContext
.CurrentMethod;
3519
return
SafeContext
.CallingMethod;
3609
return
SafeContext
.CallingMethod;
3739
internal bool CheckRefEscape(SyntaxNode node, BoundExpression expr,
SafeContext
escapeFrom,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
4115
internal
SafeContext
GetBroadestValEscape(BoundTupleExpression expr,
SafeContext
localScopeDepth)
4117
SafeContext
broadest = localScopeDepth;
4120
SafeContext
valEscape;
4141
internal
SafeContext
GetValEscape(BoundExpression expr,
SafeContext
localScopeDepth)
4150
return
SafeContext
.CallingMethod;
4156
return
SafeContext
.CallingMethod;
4162
return
SafeContext
.CallingMethod;
4177
return
SafeContext
.CallingMethod;
4185
return
SafeContext
.CallingMethod;
4197
return
SafeContext
.CallingMethod;
4200
return
SafeContext
.CallingMethod;
4217
return
SafeContext
.CurrentMethod;
4222
var
consEscape = GetValEscape(conditional.Consequence, localScopeDepth);
4247
return
SafeContext
.CallingMethod;
4382
var
escape = GetInvocationEscapeScope(
4406
var
escape =
SafeContext
.CallingMethod;
4453
SafeContext
.CurrentMethod :
4454
SafeContext
.CallingMethod;
4584
return (range.LeftOperandOpt is { } left ? GetValEscape(left, localScopeDepth) :
SafeContext
.CallingMethod)
4585
.Intersect(range.RightOperandOpt is { } right ? GetValEscape(right, localScopeDepth) :
SafeContext
.CallingMethod);
4644
return
SafeContext
.CallingMethod;
4718
private
SafeContext
GetTupleValEscape(ImmutableArray<BoundExpression> elements,
SafeContext
localScopeDepth)
4720
SafeContext
narrowestScope = localScopeDepth;
4735
private
SafeContext
GetValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr,
SafeContext
localScopeDepth)
4737
var
result =
SafeContext
.CallingMethod;
4740
var
exprResult = GetValEscapeOfObjectMemberInitializer(expr, localScopeDepth);
4747
private
SafeContext
GetValEscapeOfObjectMemberInitializer(BoundExpression expr,
SafeContext
localScopeDepth)
4749
SafeContext
result;
4753
var
rightEscape = assignment.IsRef
4778
SafeContext
getIndexerEscape(
4781
SafeContext
rightEscapeScope)
4787
return
SafeContext
.CallingMethod;
4794
return
SafeContext
.CallingMethod;
4811
SafeContext
receiverEscapeScope =
SafeContext
.CallingMethod;
4821
SafeContext
escapeScope = escapeValue.IsRefEscape
4831
SafeContext
getPropertyEscape(
4833
SafeContext
rightEscapeScope)
4839
return
SafeContext
.CallingMethod;
4848
private
SafeContext
GetValEscape(ImmutableArray<BoundExpression> expressions,
SafeContext
localScopeDepth)
4850
var
result =
SafeContext
.CallingMethod;
4864
internal bool CheckValEscape(SyntaxNode node, BoundExpression expr,
SafeContext
escapeFrom,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
4954
if (!
SafeContext
.CurrentMethod.IsConvertibleTo(escapeTo))
5263
if (HasLocalScope((BoundCollectionExpression)conversion.Operand) && !
SafeContext
.CurrentMethod.IsConvertibleTo(escapeTo))
5731
private bool CheckTupleValEscape(ImmutableArray<BoundExpression> elements,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5746
private bool CheckValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5762
private bool CheckValEscape(ImmutableArray<BoundExpression> expressions,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5775
private bool CheckInterpolatedStringHandlerConversionEscape(BoundExpression expression,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
Binder\Binder_Operators.cs (3)
5804
var
currentScope = _localScopeDepth;
5807
SafeContext
whenTrueEscape = GetValEscape(trueExpr, currentScope);
5808
SafeContext
whenFalseEscape = GetValEscape(falseExpr, currentScope);
Binder\Binder_Statements.cs (3)
1564
var
leftEscape = GetRefEscape(op1, _localScopeDepth);
1565
var
rightEscape = GetRefEscape(op2, _localScopeDepth);
1609
var
leftEscape = GetValEscape(op1, _localScopeDepth);
Binder\RefSafetyAnalysis.cs (62)
62
private
SafeContext
_localScopeDepth;
63
private Dictionary<LocalSymbol, (
SafeContext
RefEscapeScope,
SafeContext
ValEscapeScope)>? _localEscapeScopes;
64
private Dictionary<BoundValuePlaceholderBase,
SafeContext
>? _placeholderScopes;
65
private
SafeContext
_patternInputValEscape;
86
_localScopeDepth =
SafeContext
.CurrentMethod.Wider();
101
_analysis.AddLocalScopes(local, refEscapeScope: _analysis._localScopeDepth, valEscapeScope:
SafeContext
.CallingMethod);
136
private readonly
SafeContext
_previousInputValEscape;
138
public PatternInput(RefSafetyAnalysis analysis,
SafeContext
patternInputValEscape)
154
private readonly ArrayBuilder<(BoundValuePlaceholderBase,
SafeContext
)> _placeholders;
156
public PlaceholderRegion(RefSafetyAnalysis analysis, ArrayBuilder<(BoundValuePlaceholderBase,
SafeContext
)> placeholders)
176
private (
SafeContext
RefEscapeScope,
SafeContext
ValEscapeScope) GetLocalScopes(LocalSymbol local)
182
: (
SafeContext
.CurrentMethod,
SafeContext
.CallingMethod);
185
private void SetLocalScopes(LocalSymbol local,
SafeContext
refEscapeScope,
SafeContext
valEscapeScope)
192
private void AddPlaceholderScope(BoundValuePlaceholderBase placeholder,
SafeContext
valEscapeScope)
199
_placeholderScopes ??= new Dictionary<BoundValuePlaceholderBase,
SafeContext
>();
214
private
SafeContext
GetPlaceholderScope(BoundValuePlaceholderBase placeholder)
218
return _placeholderScopes?.TryGetValue(placeholder, out
var
scope) == true
220
:
SafeContext
.CallingMethod;
346
var placeholders = ArrayBuilder<(BoundValuePlaceholderBase,
SafeContext
)>.GetInstance();
349
SafeContext
valEscapeScope = node.ExpressionOpt is { } expr
363
var placeholders = ArrayBuilder<(BoundValuePlaceholderBase,
SafeContext
)>.GetInstance();
435
private void AddLocalScopes(LocalSymbol local,
SafeContext
refEscapeScope,
SafeContext
valEscapeScope)
451
SafeContext
.CurrentMethod;
454
SafeContext
.CallingMethod;
462
private void AddOrSetLocalScopes(LocalSymbol local,
SafeContext
refEscapeScope,
SafeContext
valEscapeScope)
464
_localEscapeScopes ??= new Dictionary<LocalSymbol, (
SafeContext
RefEscapeScope,
SafeContext
ValEscapeScope)>();
485
(
SafeContext
refEscapeScope,
SafeContext
valEscapeScope) = GetLocalScopes(localSymbol);
523
ValidateEscape(expr,
SafeContext
.ReturnOnly, node.RefKind != RefKind.None, _diagnostics);
533
ValidateEscape(expr,
SafeContext
.ReturnOnly, isByRef: false, _diagnostics);
605
static
SafeContext
getDeclarationValEscape(BoundTypeExpression typeExpression,
SafeContext
valEscape)
610
return typeExpression.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape :
SafeContext
.CallingMethod;
660
static
SafeContext
getPositionalValEscape(Symbol? symbol,
SafeContext
valEscape)
664
: symbol.GetTypeOrReturnType().IsRefLikeOrAllowsRefLikeType() ? valEscape :
SafeContext
.CallingMethod;
673
static
SafeContext
getMemberValEscape(BoundPropertySubpatternMember? member,
SafeContext
valEscape)
677
return member.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape :
SafeContext
.CallingMethod;
707
var placeholders = ArrayBuilder<(BoundValuePlaceholderBase,
SafeContext
)>.GetInstance();
738
ArrayBuilder<(BoundValuePlaceholderBase,
SafeContext
)> placeholders,
749
SafeContext
valEscapeScope;
757
valEscapeScope =
SafeContext
.CallingMethod;
779
valEscapeScope =
SafeContext
.CallingMethod; // Consider skipping this placeholder entirely since SafeContext.CallingMethod is the fallback in GetPlaceholderScope().
853
var
escapeFrom = GetValEscape(node.InitializerExpressionOpt, _localScopeDepth);
948
var placeholders = ArrayBuilder<(BoundValuePlaceholderBase,
SafeContext
)>.GetInstance();
955
private void GetAwaitableInstancePlaceholders(ArrayBuilder<(BoundValuePlaceholderBase,
SafeContext
)> placeholders, BoundAwaitableInfo awaitableInfo,
SafeContext
valEscapeScope)
1009
var placeholders = ArrayBuilder<(BoundValuePlaceholderBase,
SafeContext
)>.GetInstance();
1022
SafeContext
valEscape = nestedVariables is null
1058
internal readonly
SafeContext
ValEscape;
1061
internal DeconstructionVariable(BoundExpression expression,
SafeContext
valEscape, ArrayBuilder<DeconstructionVariable>? nestedVariables)
1082
? new DeconstructionVariable(expr, valEscape:
SafeContext
.Empty, GetDeconstructionAssignmentVariables(tuple))
1109
SafeContext
collectionEscape;
1145
var placeholders = ArrayBuilder<(BoundValuePlaceholderBase,
SafeContext
)>.GetInstance();
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)
Generated\BoundNodes.xml.Generated.cs (3)
481
public BoundCapturedReceiverPlaceholder(SyntaxNode syntax, BoundExpression receiver,
SafeContext
localScopeDepth, TypeSymbol? type, bool hasErrors = false)
492
public
SafeContext
LocalScopeDepth { get; }
497
public BoundCapturedReceiverPlaceholder Update(BoundExpression receiver,
SafeContext
localScopeDepth, TypeSymbol? type)