6 instantiations of SafeContext
Microsoft.CodeAnalysis.CSharp (6)
Binder\SafeContext.cs (6)
41public static readonly SafeContext CallingMethod = new SafeContext(CallingMethodRaw); 47public static readonly SafeContext ReturnOnly = new SafeContext(ReturnOnlyRaw); 53public static readonly SafeContext CurrentMethod = new SafeContext(CurrentMethodRaw); 58public static readonly SafeContext Empty = new SafeContext(uint.MaxValue); 67return new SafeContext(_value + 1); 77return new SafeContext(_value - 1);
215 references to SafeContext
Microsoft.CodeAnalysis.CSharp (215)
Binder\Binder.ValueChecks.cs (127)
1090private bool CheckLocalRefEscape(SyntaxNode node, BoundLocal local, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 1247private static EscapeLevel? EscapeLevelFromScope(SafeContext lifetime) => lifetime switch 1254private static SafeContext GetParameterValEscape(ParameterSymbol parameter) 1258{ EffectiveScope: ScopedKind.ScopedValue } => SafeContext.CurrentMethod, 1259{ RefKind: RefKind.Out, UseUpdatedEscapeRules: true } => SafeContext.ReturnOnly, 1260_ => SafeContext.CallingMethod 1267private 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 1282private bool CheckParameterValEscape(SyntaxNode node, ParameterSymbol parameter, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1300private bool CheckParameterRefEscape(SyntaxNode node, BoundExpression parameter, ParameterSymbol parameterSymbol, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 1302var refSafeToEscape = GetParameterRefEscape(parameterSymbol); 1506private SafeContext GetFieldRefEscape(BoundFieldAccess fieldAccess, SafeContext localScopeDepth) 1513return SafeContext.CallingMethod; 1529private bool CheckFieldRefEscape(SyntaxNode node, BoundFieldAccess fieldAccess, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1553private bool CheckFieldLikeEventRefEscape(SyntaxNode node, BoundEventAccess eventAccess, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1951internal SafeContext GetInterpolatedStringHandlerConversionEscapeScope( 1953SafeContext localScopeDepth) 1963SafeContext escapeScope = GetValEscape(data.Construction, localScopeDepth); 1973SafeContext argEscape = GetValEscape(argument, localScopeDepth); 1991private SafeContext GetInvocationEscapeScope( 1999SafeContext localScopeDepth, 2016SafeContext getInvocationEscapeWithOldRules(MethodInfo methodInfo, ImmutableArray<ParameterSymbol> parameters, BoundExpression? receiver, ImmutableArray<BoundExpression> argsOpt, ImmutableArray<RefKind> argRefKindsOpt, ImmutableArray<int> argsToParamsOpt, SafeContext localScopeDepth, bool isRefEscape) 2030SafeContext escapeScope = SafeContext.CallingMethod; 2057SafeContext argumentEscape = (isRefEscape, argumentIsRefEscape) switch 2087private SafeContext GetInvocationEscapeWithUpdatedRules( 2095SafeContext localScopeDepth, 2099SafeContext escapeScope = SafeContext.CallingMethod; 2126SafeContext argEscape = isArgumentRefEscape ? 2205SafeContext escapeFrom, 2206SafeContext escapeTo, 2227bool checkingReceiver, SafeContext escapeFrom, SafeContext escapeTo, 2309SafeContext escapeFrom, 2310SafeContext escapeTo, 2873SafeContext localScopeDepth, 2888SafeContext localScopeDepth, BindingDiagnosticBag diagnostics, Symbol symbolForReporting) 2903SafeContext escapeTo = localScopeDepth; 2943var inferredDestinationValEscape = SafeContext.CallingMethod; 2983SafeContext localScopeDepth, 3004var toArgEscape = GetValEscape(mixableArg.Argument, localScopeDepth); 3043var inferredDestinationValEscape = SafeContext.CallingMethod; 3317private static ErrorCode GetStandardRValueRefEscapeError(SafeContext escapeTo) 3401internal void ValidateEscape(BoundExpression expr, SafeContext escapeTo, bool isByRef, BindingDiagnosticBag diagnostics) 3424internal SafeContext GetRefEscape(BoundExpression expr, SafeContext localScopeDepth) 3433return SafeContext.CallingMethod; 3439return SafeContext.CallingMethod; 3456return SafeContext.CallingMethod; 3462return SafeContext.CurrentMethod; 3519return SafeContext.CallingMethod; 3609return SafeContext.CallingMethod; 3732internal bool CheckRefEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeFrom, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 4101internal SafeContext GetBroadestValEscape(BoundTupleExpression expr, SafeContext localScopeDepth) 4103SafeContext broadest = localScopeDepth; 4106SafeContext valEscape; 4127internal SafeContext GetValEscape(BoundExpression expr, SafeContext localScopeDepth) 4136return SafeContext.CallingMethod; 4142return SafeContext.CallingMethod; 4148return SafeContext.CallingMethod; 4163return SafeContext.CallingMethod; 4171return SafeContext.CallingMethod; 4183return SafeContext.CallingMethod; 4186return SafeContext.CallingMethod; 4203return SafeContext.CurrentMethod; 4208var consEscape = GetValEscape(conditional.Consequence, localScopeDepth); 4233return SafeContext.CallingMethod; 4368var escape = GetInvocationEscapeScope( 4392var escape = SafeContext.CallingMethod; 4439SafeContext.CurrentMethod : 4440SafeContext.CallingMethod; 4545return (range.LeftOperandOpt is { } left ? GetValEscape(left, localScopeDepth) : SafeContext.CallingMethod) 4546.Intersect(range.RightOperandOpt is { } right ? GetValEscape(right, localScopeDepth) : SafeContext.CallingMethod); 4605return SafeContext.CallingMethod; 4679private SafeContext GetTupleValEscape(ImmutableArray<BoundExpression> elements, SafeContext localScopeDepth) 4681SafeContext narrowestScope = localScopeDepth; 4696private SafeContext GetValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr, SafeContext localScopeDepth) 4698var result = SafeContext.CallingMethod; 4701var exprResult = GetValEscapeOfObjectMemberInitializer(expr, localScopeDepth); 4708private SafeContext GetValEscapeOfObjectMemberInitializer(BoundExpression expr, SafeContext localScopeDepth) 4710SafeContext result; 4714var rightEscape = assignment.IsRef 4739SafeContext getIndexerEscape( 4742SafeContext rightEscapeScope) 4748return SafeContext.CallingMethod; 4755return SafeContext.CallingMethod; 4772SafeContext receiverEscapeScope = SafeContext.CallingMethod; 4782SafeContext escapeScope = escapeValue.IsRefEscape 4792SafeContext getPropertyEscape( 4794SafeContext rightEscapeScope) 4800return SafeContext.CallingMethod; 4809private SafeContext GetValEscape(ImmutableArray<BoundExpression> expressions, SafeContext localScopeDepth) 4811var result = SafeContext.CallingMethod; 4825internal bool CheckValEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeFrom, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 4915if (!SafeContext.CurrentMethod.IsConvertibleTo(escapeTo)) 5224if (HasLocalScope((BoundCollectionExpression)conversion.Operand) && !SafeContext.CurrentMethod.IsConvertibleTo(escapeTo)) 5664private bool CheckTupleValEscape(ImmutableArray<BoundExpression> elements, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5679private bool CheckValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5695private bool CheckValEscape(ImmutableArray<BoundExpression> expressions, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5708private bool CheckInterpolatedStringHandlerConversionEscape(BoundExpression expression, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics)
Binder\Binder_Operators.cs (3)
4818var currentScope = _localScopeDepth; 4821SafeContext whenTrueEscape = GetValEscape(trueExpr, currentScope); 4822SafeContext whenFalseEscape = GetValEscape(falseExpr, currentScope);
Binder\Binder_Statements.cs (3)
1564var leftEscape = GetRefEscape(op1, _localScopeDepth); 1565var rightEscape = GetRefEscape(op2, _localScopeDepth); 1609var leftEscape = GetValEscape(op1, _localScopeDepth);
Binder\RefSafetyAnalysis.cs (62)
62private SafeContext _localScopeDepth; 63private Dictionary<LocalSymbol, (SafeContext RefEscapeScope, SafeContext ValEscapeScope)>? _localEscapeScopes; 64private Dictionary<BoundValuePlaceholderBase, SafeContext>? _placeholderScopes; 65private SafeContext _patternInputValEscape; 86_localScopeDepth = SafeContext.CurrentMethod.Wider(); 101_analysis.AddLocalScopes(local, refEscapeScope: _analysis._localScopeDepth, valEscapeScope: SafeContext.CallingMethod); 136private readonly SafeContext _previousInputValEscape; 138public PatternInput(RefSafetyAnalysis analysis, SafeContext patternInputValEscape) 154private readonly ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)> _placeholders; 156public PlaceholderRegion(RefSafetyAnalysis analysis, ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)> placeholders) 176private (SafeContext RefEscapeScope, SafeContext ValEscapeScope) GetLocalScopes(LocalSymbol local) 182: (SafeContext.CurrentMethod, SafeContext.CallingMethod); 185private void SetLocalScopes(LocalSymbol local, SafeContext refEscapeScope, SafeContext valEscapeScope) 192private void AddPlaceholderScope(BoundValuePlaceholderBase placeholder, SafeContext valEscapeScope) 199_placeholderScopes ??= new Dictionary<BoundValuePlaceholderBase, SafeContext>(); 214private SafeContext GetPlaceholderScope(BoundValuePlaceholderBase placeholder) 218return _placeholderScopes?.TryGetValue(placeholder, out var scope) == true 220: SafeContext.CallingMethod; 346var placeholders = ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)>.GetInstance(); 349SafeContext valEscapeScope = node.ExpressionOpt is { } expr 363var placeholders = ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)>.GetInstance(); 435private void AddLocalScopes(LocalSymbol local, SafeContext refEscapeScope, SafeContext valEscapeScope) 451SafeContext.CurrentMethod; 454SafeContext.CallingMethod; 462private void AddOrSetLocalScopes(LocalSymbol local, SafeContext refEscapeScope, SafeContext valEscapeScope) 464_localEscapeScopes ??= new Dictionary<LocalSymbol, (SafeContext RefEscapeScope, SafeContext ValEscapeScope)>(); 485(SafeContext refEscapeScope, SafeContext valEscapeScope) = GetLocalScopes(localSymbol); 523ValidateEscape(expr, SafeContext.ReturnOnly, node.RefKind != RefKind.None, _diagnostics); 533ValidateEscape(expr, SafeContext.ReturnOnly, isByRef: false, _diagnostics); 605static SafeContext getDeclarationValEscape(BoundTypeExpression typeExpression, SafeContext valEscape) 610return typeExpression.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 660static SafeContext getPositionalValEscape(Symbol? symbol, SafeContext valEscape) 664: symbol.GetTypeOrReturnType().IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 673static SafeContext getMemberValEscape(BoundPropertySubpatternMember? member, SafeContext valEscape) 677return member.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 707var placeholders = ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)>.GetInstance(); 738ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)> placeholders, 749SafeContext valEscapeScope; 757valEscapeScope = SafeContext.CallingMethod; 779valEscapeScope = SafeContext.CallingMethod; // Consider skipping this placeholder entirely since SafeContext.CallingMethod is the fallback in GetPlaceholderScope(). 853var escapeFrom = GetValEscape(node.InitializerExpressionOpt, _localScopeDepth); 948var placeholders = ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)>.GetInstance(); 955private void GetAwaitableInstancePlaceholders(ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)> placeholders, BoundAwaitableInfo awaitableInfo, SafeContext valEscapeScope) 1009var placeholders = ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)>.GetInstance(); 1022SafeContext valEscape = nestedVariables is null 1058internal readonly SafeContext ValEscape; 1061internal DeconstructionVariable(BoundExpression expression, SafeContext valEscape, ArrayBuilder<DeconstructionVariable>? nestedVariables) 1082? new DeconstructionVariable(expr, valEscape: SafeContext.Empty, GetDeconstructionAssignmentVariables(tuple)) 1109SafeContext collectionEscape; 1145var placeholders = ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)>.GetInstance();
Binder\SafeContext.cs (17)
41public static readonly SafeContext CallingMethod = new SafeContext(CallingMethodRaw); 47public static readonly SafeContext ReturnOnly = new SafeContext(ReturnOnlyRaw); 53public static readonly SafeContext CurrentMethod = new SafeContext(CurrentMethodRaw); 58public static readonly SafeContext Empty = new SafeContext(uint.MaxValue); 64public SafeContext Narrower() 74public SafeContext Wider() 86public bool IsConvertibleTo(SafeContext other) 97public SafeContext Intersect(SafeContext other) 104public SafeContext Union(SafeContext other) 108public bool Equals(SafeContext other) 112=> obj is SafeContext other && this.Equals(other); 117public static bool operator ==(SafeContext lhs, SafeContext rhs) 120public static bool operator !=(SafeContext lhs, SafeContext rhs)
Generated\BoundNodes.xml.Generated.cs (3)
500public BoundCapturedReceiverPlaceholder(SyntaxNode syntax, BoundExpression receiver, SafeContext localScopeDepth, TypeSymbol? type, bool hasErrors = false) 511public SafeContext LocalScopeDepth { get; } 516public BoundCapturedReceiverPlaceholder Update(BoundExpression receiver, SafeContext localScopeDepth, TypeSymbol? type)