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)
1094private bool CheckLocalRefEscape(SyntaxNode node, BoundLocal local, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 1251private static EscapeLevel? EscapeLevelFromScope(SafeContext lifetime) => lifetime switch 1258private static SafeContext GetParameterValEscape(ParameterSymbol parameter) 1262{ EffectiveScope: ScopedKind.ScopedValue } => SafeContext.CurrentMethod, 1263{ RefKind: RefKind.Out, UseUpdatedEscapeRules: true } => SafeContext.ReturnOnly, 1264_ => SafeContext.CallingMethod 1271private static SafeContext GetParameterRefEscape(ParameterSymbol parameter) 1275{ RefKind: RefKind.None } => SafeContext.CurrentMethod, 1276{ EffectiveScope: ScopedKind.ScopedRef } => SafeContext.CurrentMethod, 1277{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, RefKind: RefKind.Out } => SafeContext.ReturnOnly, 1278{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, IsThis: false } => SafeContext.CallingMethod, 1279_ => SafeContext.ReturnOnly 1286private bool CheckParameterValEscape(SyntaxNode node, ParameterSymbol parameter, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1304private bool CheckParameterRefEscape(SyntaxNode node, BoundExpression parameter, ParameterSymbol parameterSymbol, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 1306var refSafeToEscape = GetParameterRefEscape(parameterSymbol); 1502private SafeContext GetFieldRefEscape(BoundFieldAccess fieldAccess, SafeContext localScopeDepth) 1509return SafeContext.CallingMethod; 1525private bool CheckFieldRefEscape(SyntaxNode node, BoundFieldAccess fieldAccess, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1549private bool CheckFieldLikeEventRefEscape(SyntaxNode node, BoundEventAccess eventAccess, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1947internal SafeContext GetInterpolatedStringHandlerConversionEscapeScope( 1949SafeContext localScopeDepth) 1959SafeContext escapeScope = GetValEscape(data.Construction, localScopeDepth); 1969SafeContext argEscape = GetValEscape(argument, localScopeDepth); 1987private SafeContext GetInvocationEscapeScope( 1995SafeContext localScopeDepth, 2012SafeContext getInvocationEscapeWithOldRules(MethodInfo methodInfo, ImmutableArray<ParameterSymbol> parameters, BoundExpression? receiver, ImmutableArray<BoundExpression> argsOpt, ImmutableArray<RefKind> argRefKindsOpt, ImmutableArray<int> argsToParamsOpt, SafeContext localScopeDepth, bool isRefEscape) 2026SafeContext escapeScope = SafeContext.CallingMethod; 2053SafeContext argumentEscape = (isRefEscape, argumentIsRefEscape) switch 2083private SafeContext GetInvocationEscapeWithUpdatedRules( 2091SafeContext localScopeDepth, 2095SafeContext escapeScope = SafeContext.CallingMethod; 2122SafeContext argEscape = isArgumentRefEscape ? 2201SafeContext escapeFrom, 2202SafeContext escapeTo, 2223bool checkingReceiver, SafeContext escapeFrom, SafeContext escapeTo, 2305SafeContext escapeFrom, 2306SafeContext escapeTo, 2869SafeContext localScopeDepth, 2884SafeContext localScopeDepth, BindingDiagnosticBag diagnostics, Symbol symbolForReporting) 2899SafeContext escapeTo = localScopeDepth; 2939var inferredDestinationValEscape = SafeContext.CallingMethod; 2979SafeContext localScopeDepth, 3000var toArgEscape = GetValEscape(mixableArg.Argument, localScopeDepth); 3039var inferredDestinationValEscape = SafeContext.CallingMethod; 3313private static ErrorCode GetStandardRValueRefEscapeError(SafeContext escapeTo) 3397internal void ValidateEscape(BoundExpression expr, SafeContext escapeTo, bool isByRef, BindingDiagnosticBag diagnostics) 3420internal SafeContext GetRefEscape(BoundExpression expr, SafeContext localScopeDepth) 3429return SafeContext.CallingMethod; 3435return SafeContext.CallingMethod; 3452return SafeContext.CallingMethod; 3458return SafeContext.CurrentMethod; 3515return SafeContext.CallingMethod; 3605return SafeContext.CallingMethod; 3728internal bool CheckRefEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeFrom, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 4097internal SafeContext GetBroadestValEscape(BoundTupleExpression expr, SafeContext localScopeDepth) 4099SafeContext broadest = localScopeDepth; 4102SafeContext valEscape; 4123internal SafeContext GetValEscape(BoundExpression expr, SafeContext localScopeDepth) 4132return SafeContext.CallingMethod; 4138return SafeContext.CallingMethod; 4144return SafeContext.CallingMethod; 4159return SafeContext.CallingMethod; 4167return SafeContext.CallingMethod; 4179return SafeContext.CallingMethod; 4182return SafeContext.CallingMethod; 4199return SafeContext.CurrentMethod; 4204var consEscape = GetValEscape(conditional.Consequence, localScopeDepth); 4229return SafeContext.CallingMethod; 4364var escape = GetInvocationEscapeScope( 4388var escape = SafeContext.CallingMethod; 4435SafeContext.CurrentMethod : 4436SafeContext.CallingMethod; 4532return (range.LeftOperandOpt is { } left ? GetValEscape(left, localScopeDepth) : SafeContext.CallingMethod) 4533.Intersect(range.RightOperandOpt is { } right ? GetValEscape(right, localScopeDepth) : SafeContext.CallingMethod); 4592return SafeContext.CallingMethod; 4666private SafeContext GetTupleValEscape(ImmutableArray<BoundExpression> elements, SafeContext localScopeDepth) 4668SafeContext narrowestScope = localScopeDepth; 4683private SafeContext GetValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr, SafeContext localScopeDepth) 4685var result = SafeContext.CallingMethod; 4688var exprResult = GetValEscapeOfObjectMemberInitializer(expr, localScopeDepth); 4695private SafeContext GetValEscapeOfObjectMemberInitializer(BoundExpression expr, SafeContext localScopeDepth) 4697SafeContext result; 4701var rightEscape = assignment.IsRef 4726SafeContext getIndexerEscape( 4729SafeContext rightEscapeScope) 4735return SafeContext.CallingMethod; 4742return SafeContext.CallingMethod; 4759SafeContext receiverEscapeScope = SafeContext.CallingMethod; 4769SafeContext escapeScope = escapeValue.IsRefEscape 4779SafeContext getPropertyEscape( 4781SafeContext rightEscapeScope) 4787return SafeContext.CallingMethod; 4796private SafeContext GetValEscape(ImmutableArray<BoundExpression> expressions, SafeContext localScopeDepth) 4798var result = SafeContext.CallingMethod; 4812internal bool CheckValEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeFrom, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 4902if (!SafeContext.CurrentMethod.IsConvertibleTo(escapeTo)) 5211if (HasLocalScope((BoundCollectionExpression)conversion.Operand) && !SafeContext.CurrentMethod.IsConvertibleTo(escapeTo)) 5644private bool CheckTupleValEscape(ImmutableArray<BoundExpression> elements, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5659private bool CheckValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5675private bool CheckValEscape(ImmutableArray<BoundExpression> expressions, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5688private bool CheckInterpolatedStringHandlerConversionEscape(BoundExpression expression, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics)
Binder\Binder_Operators.cs (3)
4382var currentScope = _localScopeDepth; 4385SafeContext whenTrueEscape = GetValEscape(trueExpr, currentScope); 4386SafeContext 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); 570static SafeContext getDeclarationValEscape(BoundTypeExpression typeExpression, SafeContext valEscape) 575return typeExpression.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 621static SafeContext getPositionalValEscape(Symbol? symbol, SafeContext valEscape) 625: symbol.GetTypeOrReturnType().IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 634static SafeContext getMemberValEscape(BoundPropertySubpatternMember? member, SafeContext valEscape) 638return member.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 668var placeholders = ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)>.GetInstance(); 699ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)> placeholders, 710SafeContext valEscapeScope; 718valEscapeScope = SafeContext.CallingMethod; 740valEscapeScope = SafeContext.CallingMethod; // Consider skipping this placeholder entirely since SafeContext.CallingMethod is the fallback in GetPlaceholderScope(). 814var escapeFrom = GetValEscape(node.InitializerExpressionOpt, _localScopeDepth); 909var placeholders = ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)>.GetInstance(); 916private void GetAwaitableInstancePlaceholders(ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)> placeholders, BoundAwaitableInfo awaitableInfo, SafeContext valEscapeScope) 970var placeholders = ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)>.GetInstance(); 983SafeContext valEscape = nestedVariables is null 1019internal readonly SafeContext ValEscape; 1022internal DeconstructionVariable(BoundExpression expression, SafeContext valEscape, ArrayBuilder<DeconstructionVariable>? nestedVariables) 1043? new DeconstructionVariable(expr, valEscape: SafeContext.Empty, GetDeconstructionAssignmentVariables(tuple)) 1070SafeContext collectionEscape; 1106var 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)