src\Analyzers\Core\Analyzers\RemoveUnusedParametersAndValues\AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer.SymbolStartAnalyzer.BlockAnalyzer.cs (2)
544case RefKind.Out:
551case RefKind.Ref:
src\Analyzers\Core\CodeFixes\GenerateParameterizedMember\AbstractGenerateDeconstructMethodService.State.cs (1)
76refKind: RefKind.None,
src\Analyzers\Core\CodeFixes\GenerateParameterizedMember\AbstractGenerateMethodService.State.cs (1)
255refKind: RefKind.None,
src\Analyzers\Core\CodeFixes\GenerateVariable\AbstractGenerateVariableService.cs (8)
153document, state, generateProperty: false, isReadonly: false, isConstant: true, refKind: RefKind.None));
167document, state, generateProperty: false, isReadonly: true, isConstant: false, refKind: RefKind.None));
181document, state, generateProperty: false, isReadonly: false, isConstant: false, refKind: RefKind.None));
229parameter.RefKind is RefKind.Out ||
254private static RefKind GetRefKindFromContext(State state)
258return RefKind.Ref;
262return RefKind.RefReadOnly;
266return RefKind.None;
src\Analyzers\Core\CodeFixes\GenerateVariable\AbstractGenerateVariableService.GenerateParameterCodeAction.cs (1)
44RefKind.None,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\CodeGenerationSymbolFactory.cs (10)
53RefKind refKind,
84ITypeSymbol type, RefKind refKind, ImmutableArray<IPropertySymbol> explicitInterfaceImplementations, string name,
157RefKind refKind,
179RefKind refKind,
269=> CreateParameterSymbol(RefKind.None, type, name);
271public static IParameterSymbol CreateParameterSymbol(RefKind refKind, ITypeSymbol type, string name)
281ImmutableArray<AttributeData> attributes, RefKind refKind, bool isParams, ITypeSymbol type, string name, bool isOptional = false, bool hasDefaultValue = false, object? defaultValue = null)
292RefKind? refKind = null,
396refKind: RefKind.None,
468RefKind refKind,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationConstructorSymbol.cs (1)
27refKind: RefKind.None,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationConversionSymbol.cs (1)
31refKind: RefKind.None,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationDestructorSymbol.cs (1)
18refKind: RefKind.None,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationOperatorSymbol.cs (1)
32refKind: RefKind.None,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\Extensions\SyntaxGeneratorExtensions_CreateEqualsMethod.cs (1)
56refKind: RefKind.None,
Binder\Binder.ValueChecks.cs (126)
53Method is { RefKind: not RefKind.None, ReturnType: { } returnType } &&
154internal RefKind RefKind { get; }
156internal EscapeArgument(ParameterSymbol? parameter, BoundExpression argument, RefKind refKind, bool isArgList = false)
164public void Deconstruct(out ParameterSymbol? parameter, out BoundExpression argument, out RefKind refKind)
363if (indexerAccess.Indexer.RefKind != RefKind.None)
386var useSetAccessor = coreValueKind == BindValueKind.Assignable && indexerAccess.Indexer.RefKind != RefKind.Ref;
395ArrayBuilder<RefKind>? refKindsBuilderOpt;
398refKindsBuilderOpt = ArrayBuilder<RefKind>.GetInstance(accessorForDefaultArguments.ParameterCount);
1037if (localSymbol.RefKind == RefKind.RefReadOnly ||
1038(localSymbol.RefKind == RefKind.None && !localSymbol.IsWritableVariable))
1046if (localSymbol.RefKind == RefKind.None)
1078if (localSymbol.RefKind == RefKind.None)
1119if (parameterSymbol.RefKind is RefKind.In or RefKind.RefReadOnlyParameter && RequiresAssignableVariable(valueKind))
1124else if (parameterSymbol.RefKind == RefKind.None && RequiresRefAssignableVariable(valueKind))
1130Debug.Assert(parameterSymbol.RefKind != RefKind.None || !RequiresRefAssignableVariable(valueKind));
1134if (parameterSymbol.RefKind == RefKind.None &&
1138Debug.Assert(backingField.RefKind == RefKind.None);
1143Debug.Assert(backingField.RefKind == RefKind.None);
1233{ RefKind: RefKind.Out, UseUpdatedEscapeRules: true } => SafeContext.ReturnOnly,
1245{ RefKind: RefKind.None } => SafeContext.CurrentMethod,
1247{ HasUnscopedRefAttribute: true, RefKind: RefKind.Out } => SafeContext.ReturnOnly,
1280Debug.Assert(parameterSymbol.RefKind == RefKind.None || isRefScoped || refSafeToEscape.IsReturnOnly);
1330if ((fieldSymbol.RefKind == RefKind.None ? RequiresAssignableVariable(valueKind) : RequiresRefAssignableVariable(valueKind)) &&
1342case RefKind.None:
1344case RefKind.Ref:
1346case RefKind.RefReadOnly:
1367case RefKind.None:
1370case RefKind.Ref:
1371case RefKind.RefReadOnly:
1382case RefKind.None:
1384case RefKind.Ref:
1385case RefKind.RefReadOnly:
1485if (fieldSymbol.RefKind != RefKind.None)
1509if (fieldSymbol.RefKind != RefKind.None)
1645if (RequiresVariable(valueKind) && methodSymbol.RefKind == RefKind.None)
1660if (RequiresAssignableVariable(valueKind) && methodSymbol.RefKind == RefKind.RefReadOnly)
1691propertySymbol.RefKind == RefKind.None)
1715if (RequiresAssignableVariable(valueKind) && propertySymbol.RefKind == RefKind.RefReadOnly)
1721var requiresSet = RequiresAssignableVariable(valueKind) && propertySymbol.RefKind == RefKind.None;
1790var requiresGet = !RequiresAssignmentOnly(valueKind) || propertySymbol.RefKind != RefKind.None;
1963ImmutableArray<RefKind> argRefKindsOpt,
2052ImmutableArray<RefKind> argRefKindsOpt,
2082(param is { RefKind: not RefKind.None, Type: { } type } && type.IsRefLikeOrAllowsRefLikeType())) &&
2117ImmutableArray<RefKind> argRefKindsOpt,
2174var valid = effectiveRefKind != RefKind.None && isRefEscape ?
2210ImmutableArray<RefKind> argRefKindsOpt,
2243(param is { RefKind: not RefKind.None, Type: { } type } && type.IsRefLikeOrAllowsRefLikeType())) &&
2283ImmutableArray<RefKind> argRefKindsOpt,
2344var refKind = parameter?.RefKind ?? RefKind.None;
2349if (refKind == RefKind.None &&
2350parameter?.RefKind is RefKind.In or RefKind.RefReadOnlyParameter)
2385if (getArgument.RefKind == RefKind.Ref)
2391if (setArgument.RefKind == RefKind.Ref)
2407return new EscapeArgument(parameter: null, receiver, RefKind.None);
2410var refKind = RefKind.None;
2430ImmutableArray<RefKind> argRefKindsOpt,
2437var refKind = argRefKindsOpt.IsDefault ? RefKind.None : argRefKindsOpt[argIndex];
2440if (refKind == RefKind.Ref && mixableArguments is not null)
2460ImmutableArray<RefKind> argRefKindsOpt,
2530ImmutableArray<RefKind> argRefKindsOpt,
2585ImmutableArray<RefKind> argRefKindsOpt,
2615if (refKind != RefKind.None)
2628if (parameter.Type.IsRefLikeOrAllowsRefLikeType() && parameter.RefKind != RefKind.Out && GetParameterValEscapeLevel(parameter) is { } valEscapeLevel)
2635if (parameter.RefKind != RefKind.None && GetParameterRefEscapeLevel(parameter) is { } refEscapeLevel)
2661ImmutableArray<RefKind> argRefKindsOpt,
2704if (parameter.RefKind != RefKind.None)
2775ImmutableArray<RefKind> argRefKindsOpt,
2875ImmutableArray<RefKind> argRefKindsOpt,
2992Debug.Assert(underlyingParameter.RefKind != RefKind.Out); // Shouldn't get here for a constructor
3002public override RefKind RefKind
3006if (_underlyingParameter.RefKind is not RefKind.None and var underlyingRefKind)
3013return RefKind.None;
3018return RefKind.Ref;
3226Debug.Assert(field.RefKind == RefKind.None ? RequiresAssignableVariable(kind) : RequiresRefAssignableVariable(kind));
3423if (methodSymbol.RefKind == RefKind.None)
3445if (methodSymbol.RefKind == RefKind.None)
3506if (methodSymbol.RefKind == RefKind.None)
3533Debug.Assert(GetInlineArrayAccessEquivalentSignatureMethod(elementAccess, out _, out _).RefKind == RefKind.None);
3538ImmutableArray<RefKind> refKinds;
3541Debug.Assert(equivalentSignatureMethod.RefKind != RefKind.None);
3585conversion.Conversion.Method.RefKind == RefKind.None));
3592unaryMethod.RefKind == RefKind.None));
3599binaryMethod.RefKind == RefKind.None));
3605logicalOperator.LogicalOperator.RefKind == RefKind.None));
3612compoundMethod.RefKind == RefKind.None));
3740if (methodSymbol.RefKind == RefKind.None)
3766if (indexerSymbol.RefKind == RefKind.None)
3797if (indexerSymbol.RefKind == RefKind.None)
3823if (methodSymbol.RefKind == RefKind.None)
3854Debug.Assert(GetInlineArrayAccessEquivalentSignatureMethod(elementAccess, out _, out _).RefKind == RefKind.None);
3859ImmutableArray<RefKind> refKinds;
3862Debug.Assert(equivalentSignatureMethod.RefKind != RefKind.None);
3884if (signature.RefKind == RefKind.None)
3908if (propertySymbol.RefKind == RefKind.None)
3955conversion.Conversion.Method.RefKind == RefKind.None);
3962unaryMethod.RefKind == RefKind.None));
3969binaryMethod.RefKind == RefKind.None));
3975logicalOperator.LogicalOperator.RefKind == RefKind.None));
3982compoundMethod.RefKind == RefKind.None));
4226ImmutableArray<RefKind> refKinds;
4339ImmutableArray<RefKind> refKinds;
4539if (constructMethod is not { Parameters: [{ RefKind: RefKind.None } parameter] })
4674var accessorKind = property.RefKind == RefKind.None ? AccessorKind.Set : AccessorKind.Get;
4959ImmutableArray<RefKind> refKinds;
5113ImmutableArray<RefKind> refKinds;
5433private SignatureOnlyMethodSymbol GetInlineArrayAccessEquivalentSignatureMethod(BoundInlineArrayAccess elementAccess, out ImmutableArray<BoundExpression> arguments, out ImmutableArray<RefKind> refKinds)
5435RefKind resultRefKind;
5436RefKind parameterRefKind;
5447resultRefKind = RefKind.None;
5448parameterRefKind = RefKind.None;
5452resultRefKind = elementAccess.GetItemOrSliceHelper is WellKnownMember.System_ReadOnlySpan_T__get_Item ? RefKind.In : RefKind.Ref;
5461resultRefKind = RefKind.None;
5462parameterRefKind = elementAccess.GetItemOrSliceHelper is WellKnownMember.System_ReadOnlySpan_T__Slice_Int_Int ? RefKind.In : RefKind.Ref;
5495private SignatureOnlyMethodSymbol GetInlineArrayConversionEquivalentSignatureMethod(BoundConversion conversion, out ImmutableArray<BoundExpression> arguments, out ImmutableArray<RefKind> refKinds)
5501private SignatureOnlyMethodSymbol GetInlineArrayConversionEquivalentSignatureMethod(BoundExpression inlineArray, TypeSymbol resultType, out ImmutableArray<BoundExpression> arguments, out ImmutableArray<RefKind> refKinds)
5507RefKind parameterRefKind = resultType.OriginalDefinition.Equals(_compilation.GetWellKnownType(WellKnownType.System_ReadOnlySpan_T), TypeCompareKind.AllIgnoreOptions) ? RefKind.In : RefKind.Ref;
5522RefKind.None,
Binder\Binder_Expressions.cs (64)
454if (field is { IsStatic: false, RefKind: RefKind.None, ContainingSymbol: SourceMemberContainerTypeSymbol { PrimaryConstructor: { } primaryConstructor } } &&
466RefKind refKind,
1933private bool IsBadLocalOrParameterCapture(Symbol symbol, TypeSymbol type, RefKind refKind)
1935if (refKind != RefKind.None || type.IsRestrictedType())
2059if (localSymbol.RefKind == RefKind.None && type.IsRestrictedType(ignoreSpanLikeTypes: true))
2099if (parameter.RefKind != RefKind.None)
2119(parameter.RefKind != RefKind.None || parameter.Type.IsRestrictedType()) &&
2122if (parameter.RefKind != RefKind.None)
2136else if (primaryCtor is { ThisParameter.RefKind: not RefKind.None } &&
2497if (thisSymbol is not null && thisSymbol.ContainingSymbol != ContainingMemberOrLambda && thisSymbol.RefKind != RefKind.None)
3051RefKind origRefKind = argumentSyntax.RefOrOutKeyword.Kind().GetRefKind();
3055RefKind refKind = origRefKind == RefKind.None || RefMustBeObeyed(isDelegateCreation, argumentSyntax) ? origRefKind : RefKind.None;
3068if (!hadError && isDelegateCreation && origRefKind != RefKind.None && result.Arguments.Count == 1)
3075var requiredValueKind = origRefKind == RefKind.In ? BindValueKind.ReadonlyRef : BindValueKind.RefOrOut;
3087private BoundExpression BindArgumentValue(BindingDiagnosticBag diagnostics, ArgumentSyntax argumentSyntax, bool allowArglist, RefKind refKind)
3286RefKind refKind)
3294if (refKind != RefKind.None)
3304result.RefKinds.Add(RefKind.None);
3352private BoundExpression BindArgumentExpression(BindingDiagnosticBag diagnostics, ExpressionSyntax argumentExpression, RefKind refKind, bool allowArglist)
3355refKind == RefKind.None ?
3357refKind == RefKind.In ?
3408var argRefKind = analyzedArguments.RefKind(arg);
3414if (argRefKind is RefKind.None or RefKind.In &&
3415getCorrespondingParameter(in result, parameters, arg).RefKind == RefKind.RefReadOnlyParameter)
3426if (argRefKind == RefKind.Ref)
3428if (getCorrespondingParameter(in result, parameters, arg).RefKind == RefKind.In)
3438else if (argRefKind == RefKind.None &&
3439getCorrespondingParameter(in result, parameters, arg).RefKind == RefKind.RefReadOnlyParameter)
3791var argumentRefKindsBuilder = ArrayBuilder<RefKind>.GetInstance(handlerArgumentIndexes.Length);
3801RefKind refKind;
3807refKind = RefKind.None;
3885argumentRefKindsBuilder.Add(refKind == RefKind.RefReadOnlyParameter ? RefKind.In : refKind);
4979if (analyzedArguments.RefKind(i) is (RefKind.Ref or RefKind.Out))
5496ArrayBuilder<RefKind> refKinds,
5689var rhsExpr = initializer.Right.CheckAndUnwrapRefExpression(diagnostics, out RefKind refKind);
5690bool isRef = refKind == RefKind.Ref;
5863ImmutableArray<RefKind> argumentRefKindsOpt = default;
8212extensionMethodArguments.RefKinds.Add(RefKind.None);
8346RefKind returnRefKind,
8608fieldSymbol.RefKind != RefKind.None)
9570RefKind refKind = analyzedArguments.RefKind(i);
9571if (refKind != RefKind.None)
9670default(ImmutableArray<RefKind>),
9788ImmutableArray<RefKind> argumentRefKinds = analyzedArguments.RefKinds.ToImmutableOrNull();
10039original.Parameters[0] is { Type.SpecialType: SpecialType.System_Int32, RefKind: RefKind.None })
10137original.Parameters[0] is { Type.SpecialType: SpecialType.System_Int32, RefKind: RefKind.None } &&
10138original.Parameters[1] is { Type.SpecialType: SpecialType.System_Int32, RefKind: RefKind.None };
10201getMethod.RefKind == RefKind.None &&
10244RefKind returnRefKind = default,
10265RefKind returnRefKind = default,
10292RefKind returnRefKind,
10313RefKind returnRefKind = default,
10383RefKind returnRefKind = default,
10798RefKind? returnRefKindOverride = null,
10805var returnRefKind = returnRefKindOverride ?? methodSymbol.RefKind;
10823if (returnsVoid && returnRefKind != RefKind.None)
10837returnRefKind == RefKind.None &&
10839(parameterRefKinds.IsDefault || parameterRefKinds.All(refKind => refKind == RefKind.None)) &&
10873parameterRefKinds.IsDefault ? RefKind.None : parameterRefKinds[i],
Binder\Binder_Query.cs (3)
696return lambdaBodyBinder.CreateBlockFromExpression(node, ImmutableArray<LocalSymbol>.Empty, RefKind.None, construction, null, d);
776return this.CreateBlockFromExpression(expression, locals, RefKind.None, result, expression, diagnostics);
818new AnonymousTypeField(fieldName, fieldValue.Syntax.Location, TypeWithAnnotations.Create(TypeOrError(fieldValue)), RefKind.None, ScopedKind.None);
Binder\Binder_Statements.cs (48)
861internal BoundExpression BindInferredVariableInitializer(BindingDiagnosticBag diagnostics, RefKind refKind, EqualsValueClauseSyntax initializer,
910RefKind variableRefKind,
915RefKind expressionRefKind = RefKind.None;
917if (variableRefKind == RefKind.None)
920if (expressionRefKind == RefKind.Ref)
928valueKind = variableRefKind == RefKind.RefReadOnly
937else if (expressionRefKind != RefKind.Ref)
998if (localSymbol.RefKind != RefKind.None)
1064localSymbol.RefKind != RefKind.None ? ConversionForAssignmentFlags.RefAssignment : ConversionForAssignmentFlags.None);
1415var rhsExpr = node.Right.CheckAndUnwrapRefExpression(diagnostics, out var refKind);
1416var isRef = refKind == RefKind.Ref;
1445var lhsRefKind = boundLeft.GetRefKind();
1446if (lhsRefKind is RefKind.Ref or RefKind.Out)
2143var delegateRefKind = delegateParameters[i].RefKind;
2144if (delegateRefKind != RefKind.None)
2184var lambdaRefKind = anonymousFunction.RefKind(i);
2186var delegateRefKind = delegateParameters[i].RefKind;
2198if (delegateRefKind == RefKind.None)
2966protected virtual TypeSymbol GetCurrentReturnType(out RefKind refKind)
2983refKind = RefKind.None;
2989var refKind = RefKind.None;
3007RefKind sigRefKind;
3018if (refKind != RefKind.None)
3030else if ((object)retType != null && (refKind != RefKind.None) != (sigRefKind != RefKind.None))
3032var errorCode = refKind != RefKind.None
3130RefKind returnRefKind,
3140Debug.Assert(returnRefKind == RefKind.None);
3162if (returnRefKind != RefKind.None)
3178RefKind unusedRefKind;
3446internal BoundBlock CreateBlockFromExpression(CSharpSyntaxNode node, ImmutableArray<LocalSymbol> locals, RefKind refKind, BoundExpression expression, ExpressionSyntax expressionSyntax, BindingDiagnosticBag diagnostics)
3448RefKind returnRefKind;
3453if (IsInAsyncMethod() && refKind != RefKind.None)
3462if ((refKind != RefKind.None) != (returnRefKind != RefKind.None) && expression.Kind != BoundKind.ThrowExpression)
3464var errorCode = refKind != RefKind.None
3469statement = new BoundReturnStatement(syntax, RefKind.None, expression, @checked: CheckOverflowAtRuntime) { WasCompilerGenerated = true };
3573RefKind refKind;
3589RefKind refKind;
3602return bodyBinder.CreateBlockFromExpression(body, bodyBinder.GetDeclaredLocalsForScope(body), RefKind.None, expression, body, diagnostics);
3605private BindValueKind GetRequiredReturnValueKind(RefKind refKind)
3608if (refKind != RefKind.None)
3610GetCurrentReturnType(out var sigRefKind);
3611requiredValueKind = sigRefKind == RefKind.Ref ?
3962argumentRefKindsOpt: ImmutableArray<RefKind>.Empty,
Binder\Semantics\OverloadResolution\OverloadResolution.cs (78)
144RefKind returnRefKind = default,
192RefKind returnRefKind = default,
433RefKind returnRefKind,
839RefKind? returnRefKind,
864else if (returnRefKind == RefKind.None)
2167var type1 = getParameterTypeAndRefKind(i, m1.Result, m1LeastOverriddenParameters, m1.Result.ParamsElementTypeOpt, out RefKind parameter1RefKind);
2169var type2 = getParameterTypeAndRefKind(i, m2.Result, m2LeastOverriddenParameters, m2.Result.ParamsElementTypeOpt, out RefKind parameter2RefKind);
2558static TypeSymbol getParameterTypeAndRefKind(int i, MemberAnalysisResult result, ImmutableArray<ParameterSymbol> parameters, TypeWithAnnotations paramsElementTypeOpt, out RefKind parameter1RefKind)
2629if (p1.RefKind == RefKind.None && isAcceptableRefMismatch(p2.RefKind, isInterpolatedStringHandlerConversion))
2640else if (p2.RefKind == RefKind.None && isAcceptableRefMismatch(p1.RefKind, isInterpolatedStringHandlerConversion))
2656static bool isAcceptableRefMismatch(RefKind refKind, bool isInterpolatedStringHandlerConversion)
2659RefKind.In or RefKind.RefReadOnlyParameter => true,
2660RefKind.Ref when isInterpolatedStringHandlerConversion => true,
2836RefKind refKind1,
2839RefKind refKind2,
2864Debug.Assert(refKind1 == RefKind.None || refKind1 == RefKind.Ref);
2865Debug.Assert(refKind2 == RefKind.None || refKind2 == RefKind.Ref);
2869if (refKind1 == RefKind.None)
2878else if (refKind1 == RefKind.Ref)
3778ArrayBuilder<RefKind> argumentRefKinds,
3784out ImmutableArray<RefKind> parameterRefKinds)
3800internal readonly ImmutableArray<RefKind> ParameterRefKinds;
3803internal EffectiveParameters(ImmutableArray<TypeWithAnnotations> types, ImmutableArray<RefKind> refKinds, int firstParamsElementIndex)
3817ArrayBuilder<RefKind> argumentRefKinds,
3832ImmutableArray<RefKind> parameterRefKinds = member.GetParameterRefKinds();
3840ArrayBuilder<RefKind> refs = null;
3854RefKind argRefKind = hasAnyRefArg ? argumentRefKinds[arg] : RefKind.None;
3855RefKind paramRefKind = GetEffectiveParameterRefKind(parameter, argRefKind, options, binder, ref hasAnyRefOmittedArgument);
3859if (paramRefKind != RefKind.None)
3861refs = ArrayBuilder<RefKind>.GetInstance(arg, RefKind.None);
3871var refKinds = refs != null ? refs.ToImmutableAndFree() : default(ImmutableArray<RefKind>);
3875private static RefKind GetEffectiveParameterRefKind(
3877RefKind argRefKind,
3882var paramRefKind = parameter.RefKind;
3891if (paramRefKind == RefKind.In)
3893if (argRefKind == RefKind.None)
3895return RefKind.None;
3898if (argRefKind == RefKind.Ref && binder.Compilation.IsFeatureEnabled(MessageID.IDS_FeatureRefReadonlyParameters))
3900return RefKind.Ref;
3903else if (paramRefKind == RefKind.RefReadOnlyParameter && argRefKind is RefKind.None or RefKind.Ref or RefKind.In)
3916if ((options & Options.AllowRefOmittedArguments) != 0 && paramRefKind == RefKind.Ref && argRefKind == RefKind.None && !binder.InAttributeArgument)
3919return RefKind.None;
3928internal static bool AreRefsCompatibleForMethodConversion(RefKind candidateMethodParameterRefKind, RefKind delegateParameterRefKind, CSharpCompilation compilation)
3938(RefKind.RefReadOnlyParameter, RefKind.Ref) or
3939(RefKind.RefReadOnlyParameter, RefKind.In) or
3940(RefKind.In, RefKind.RefReadOnlyParameter))
3946(candidateMethodParameterRefKind, delegateParameterRefKind) is (RefKind.In, RefKind.Ref))
3958ArrayBuilder<RefKind> argumentRefKinds,
3969ArrayBuilder<RefKind> argumentRefKinds,
3977var refs = ArrayBuilder<RefKind>.GetInstance();
4007var argRefKind = hasAnyRefArg ? argumentRefKinds[arg] : RefKind.None;
4008var paramRefKind = GetEffectiveParameterRefKind(parameter, argRefKind, options, binder, ref hasAnyRefOmittedArgument);
4011if (paramRefKind != RefKind.None)
4017var refKinds = anyRef ? refs.ToImmutable() : default(ImmutableArray<RefKind>);
4444RefKind argumentRefKind = arguments.RefKind(argumentPosition);
4445RefKind parameterRefKind = parameters.ParameterRefKinds.IsDefault ? RefKind.None : parameters.ParameterRefKinds[argumentPosition];
4450Debug.Assert(argumentRefKind == RefKind.None);
4451if (parameterRefKind == RefKind.Ref)
4465&& parameterRefKind == RefKind.Ref
4561RefKind argRefKind,
4563RefKind parRefKind,
4600Debug.Assert(argRefKind != RefKind.None);
4606if (argRefKind == RefKind.None || hasInterpolatedStringRefMismatch)
BoundTree\BoundObjectCreationExpression.cs (3)
13ImmutableArray<RefKind> argumentRefKindsOpt, bool expanded, ImmutableArray<int> argsToParamsOpt, BitVector defaultArguments, ConstantValue? constantValueOpt,
18public BoundObjectCreationExpression Update(MethodSymbol constructor, ImmutableArray<BoundExpression> arguments, ImmutableArray<string?> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, bool expanded,
25ImmutableArray<string?> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, bool expanded, ImmutableArray<int> argsToParamsOpt,
BoundTree\Constructors.cs (28)
63fieldSymbol.RefKind != RefKind.None ||
93ImmutableArray<RefKind> argumentRefKindsOpt,
111ImmutableArray<RefKind> argumentRefKindsOpt,
127ImmutableArray<RefKind> refKinds,
183public static BoundCall Synthesized(SyntaxNode syntax, BoundExpression? receiverOpt, ThreeState initialBindingReceiverIsSubjectToCloning, MethodSymbol method, ImmutableArray<BoundExpression> arguments, ImmutableArray<RefKind> argumentRefKindsOpt = default)
192var parameterRefKind = method.ParameterRefKinds.IsDefault ? RefKind.None : method.ParameterRefKinds[i];
193var argumentRefKind = argumentRefKindsOpt.IsDefault ? RefKind.None : argumentRefKindsOpt[i];
194Debug.Assert(argumentRefKind is RefKind.None or RefKind.Ref or RefKind.In or RefKind.Out or RefKindExtensions.StrictIn &&
198RefKind.In => argumentRefKind == RefKindExtensions.StrictIn,
199RefKind.RefReadOnlyParameter => argumentRefKind is RefKind.In or RefKindExtensions.StrictIn,
230static ImmutableArray<RefKind> getArgumentRefKinds(MethodSymbol method)
234if (!result.IsDefaultOrEmpty && result.Contains(RefKind.RefReadOnlyParameter))
236var builder = ArrayBuilder<RefKind>.GetInstance(result.Length);
238foreach (var refKind in result)
240builder.Add(refKind == RefKind.RefReadOnlyParameter ? RefKind.In : refKind);
254: this(syntax, constructor, ImmutableArray.Create<BoundExpression>(arguments), default(ImmutableArray<string?>), default(ImmutableArray<RefKind>), false, default(ImmutableArray<int>), default(BitVector), null, null, constructor.ContainingType)
258: this(syntax, constructor, arguments, default(ImmutableArray<string?>), default(ImmutableArray<RefKind>), false, default(ImmutableArray<int>), default(BitVector), null, null, constructor.ContainingType)
271ImmutableArray<RefKind> refKinds,
297ImmutableArray<RefKind> argumentRefKindsOpt,
312ImmutableArray<RefKind> argumentRefKindsOpt,
631public static BoundReturnStatement Synthesized(SyntaxNode syntax, RefKind refKind, BoundExpression expression, bool hasErrors = false)
BoundTree\UnboundLambda.cs (49)
43internal readonly RefKind RefKind;
53RefKind refKind,
171ImmutableArray<RefKind> parameterRefKinds,
172RefKind refKind)
177parameterRefKinds.IsDefault ? Enumerable.Repeat(RefKind.None, parameterTypes.Length).ToImmutableArray() : parameterRefKinds,
207RefKind refKind = RefKind.None;
210RefKind rk = returnStatement.RefKind;
211if (rk != RefKind.None)
394RefKind returnRefKind,
397ImmutableArray<RefKind> refKinds,
462public bool HasExplicitReturnType(out RefKind refKind, out TypeWithAnnotations returnType)
471public RefKind RefKind(int index) { return Data.RefKind(index); }
556public abstract bool HasExplicitReturnType(out RefKind refKind, out TypeWithAnnotations returnType);
563public abstract RefKind RefKind(int index);
638private static TypeWithAnnotations DelegateReturnTypeWithAnnotations(MethodSymbol? invokeMethod, out RefKind refKind)
642refKind = CodeAnalysis.RefKind.None;
649internal (ImmutableArray<RefKind>, ArrayBuilder<ScopedKind>, ImmutableArray<TypeWithAnnotations>, bool) CollectParameterProperties()
651var parameterRefKindsBuilder = ArrayBuilder<RefKind>.GetInstance(ParameterCount);
658var refKind = RefKind(i);
715if (!HasExplicitReturnType(out var returnRefKind, out var returnType))
779var returnType = DelegateReturnTypeWithAnnotations(invokeMethod, out RefKind refKind);
798refKind == CodeAnalysis.RefKind.None &&
818if (lambdaSymbol.RefKind == CodeAnalysis.RefKind.RefReadOnly)
885ImmutableArray<RefKind> parameterRefKinds,
886RefKind refKind)
900var returnType = DelegateReturnTypeWithAnnotations(invokeMethod, out RefKind refKind);
933ImmutableArray<RefKind> parameterRefKinds)
935bool hasExplicitReturnType = HasExplicitReturnType(out var refKind, out var returnType);
990ImmutableArray<RefKind> parameterRefKinds,
992RefKind refKind)
1026public readonly ImmutableArray<RefKind> ParameterRefKinds;
1029public static readonly ReturnInferenceCacheKey Empty = new ReturnInferenceCacheKey(ImmutableArray<TypeWithAnnotations>.Empty, ImmutableArray<RefKind>.Empty, null);
1031private ReturnInferenceCacheKey(ImmutableArray<TypeWithAnnotations> parameterTypes, ImmutableArray<RefKind> parameterRefKinds, NamedTypeSymbol? taskLikeReturnTypeOpt)
1092out ImmutableArray<RefKind> parameterRefKinds,
1098parameterRefKinds = ImmutableArray<RefKind>.Empty;
1107var refKindsBuilder = ArrayBuilder<RefKind>.GetInstance(parameterCount);
1183?? rebind(ReallyInferReturnType(delegateType: null, ImmutableArray<TypeWithAnnotations>.Empty, ImmutableArray<RefKind>.Empty));
1200ImmutableArray<RefKind> parameterRefKinds)
1203var refKind = inferredReturnType.RefKind;
1215refKind = CodeAnalysis.RefKind.None;
1428private readonly RefKind _returnRefKind;
1434private readonly ImmutableArray<RefKind> _parameterRefKinds;
1443RefKind returnRefKind,
1449ImmutableArray<RefKind> parameterRefKinds,
1474public override bool HasExplicitReturnType(out RefKind refKind, out TypeWithAnnotations returnType)
1533public override RefKind RefKind(int index)
1536return _parameterRefKinds.IsDefault ? Microsoft.CodeAnalysis.RefKind.None : _parameterRefKinds[index];
1571statements[0] is BoundReturnStatement { RefKind: Microsoft.CodeAnalysis.RefKind.None, ExpressionOpt: BoundExpression expr })
CodeGen\EmitExpression.cs (53)
710RefKind refKind = expression.ArgumentRefKindsOpt.IsDefaultOrEmpty ? RefKind.None : expression.ArgumentRefKindsOpt[i];
715private void EmitArgument(BoundExpression argument, RefKind refKind)
719case RefKind.None:
723case RefKind.In:
729Debug.Assert(refKind is RefKind.Ref or RefKind.Out or RefKindExtensions.StrictIn);
737Debug.Assert(argument.Type.IsDynamic() || argument is BoundFieldAccess { FieldSymbol.RefKind: not RefKind.None }, "passing args byref should not clone them into temps");
779if (expression.RefKind == RefKind.None)
946private void EmitArguments(ImmutableArray<BoundExpression> arguments, ImmutableArray<ParameterSymbol> parameters, ImmutableArray<RefKind> argRefKindsOpt)
951Debug.Assert(parameters.All(p => p.RefKind == RefKind.None) || !argRefKindsOpt.IsDefault, "there are nontrivial parameters, so we must have argRefKinds");
958RefKind argRefKind = GetArgumentRefKind(arguments, parameters, argRefKindsOpt, i);
967internal static RefKind GetArgumentRefKind(ImmutableArray<BoundExpression> arguments, ImmutableArray<ParameterSymbol> parameters, ImmutableArray<RefKind> argRefKindsOpt, int i)
969RefKind argRefKind;
980RefKind.In => argRefKind == RefKindExtensions.StrictIn,
981RefKind.RefReadOnlyParameter => argRefKind is RefKind.In or RefKindExtensions.StrictIn,
988Debug.Assert(parameters[i].RefKind != RefKind.RefReadOnlyParameter,
994RefKind.RefReadOnlyParameter => RefKind.In, // should not happen, asserted above
1003argRefKind = RefKind.None;
1132if (!field.IsVolatile && !field.IsStatic && fieldAccess.ReceiverOpt.Type.IsVerifierValue() && field.RefKind == RefKind.None)
1144if (field.RefKind != RefKind.None)
1288return ((BoundParameter)receiver).ParameterSymbol.RefKind != RefKind.None;
1292return ((BoundLocal)receiver).LocalSymbol.RefKind != RefKind.None;
1301if (field.IsStatic || field.RefKind != RefKind.None)
1392bool isRefLocal = local.LocalSymbol.RefKind != RefKind.None;
1424if (parameter.ParameterSymbol.RefKind != RefKind.None)
1739var methodRefKind = call.Method.RefKind;
2214return ((BoundLocal)receiver).LocalSymbol.RefKind != RefKind.None;
2217return ((BoundParameter)receiver).ParameterSymbol.RefKind != RefKind.None;
2220return ((BoundCall)receiver).Method.RefKind != RefKind.None;
2223return ((BoundFunctionPointerInvocation)receiver).FunctionPointer.Signature.RefKind != RefKind.None;
2226return ((BoundDup)receiver).RefKind != RefKind.None;
2633if (System.Linq.ImmutableArrayExtensions.All(ctor.Parameters, p => p.RefKind == RefKind.None) &&
2757return ((BoundParameter)left).ParameterSymbol.RefKind == RefKind.None;
2762return ((BoundLocal)left).LocalSymbol.RefKind == RefKind.None;
2782if (left.FieldSymbol.RefKind != RefKind.None &&
2800if (left.ParameterSymbol.RefKind != RefKind.None &&
2832if (left.LocalSymbol.RefKind != RefKind.None && !assignmentOperator.IsRef)
2931Debug.Assert(left.Method.RefKind != RefKind.None);
2942Debug.Assert(left.FunctionPointer.Signature.RefKind != RefKind.None);
2994LocalDefinition temp = EmitAddress(assignmentOperator.Right, lhs.GetRefKind() is RefKind.RefReadOnly or RefKindExtensions.StrictIn or RefKind.RefReadOnlyParameter ? AddressKind.ReadOnlyStrict : AddressKind.Writeable);
3077if (local.LocalSymbol.RefKind != RefKind.None && !assignment.IsRef)
3110Debug.Assert(((BoundDup)expression).RefKind != RefKind.None);
3133Debug.Assert(((BoundCall)expression).Method.RefKind != RefKind.None);
3138Debug.Assert(((BoundFunctionPointerInvocation)expression).FunctionPointer.Signature.RefKind != RefKind.None);
3282if (field.RefKind != RefKind.None && !refAssign)
3297if (parameter.ParameterSymbol.RefKind != RefKind.None && !refAssign)
4088if (useKind == UseKind.UsedAsValue && method.RefKind != RefKind.None)
4094Debug.Assert(method.RefKind != RefKind.None);
CodeGen\Optimizer.cs (23)
858if (node.LocalSymbol.RefKind != RefKind.None)
878if (node.LocalSymbol.RefKind != RefKind.None)
986if (localSymbol.RefKind is RefKind.RefReadOnly or RefKindExtensions.StrictIn &&
1031(lhs.Kind is BoundKind.Local or BoundKind.Parameter or BoundKind.FieldAccess && lhs.GetRefKind() != RefKind.None),
1041if (((BoundParameter)lhs).ParameterSymbol.RefKind != RefKind.None)
1049if (((BoundLocal)lhs).LocalSymbol.RefKind != RefKind.None)
1057Debug.Assert(((BoundCall)lhs).Method.RefKind == RefKind.Ref, "only ref returning methods are assignable");
1061Debug.Assert(((BoundFunctionPointerInvocation)lhs).FunctionPointer.Signature.RefKind == RefKind.Ref, "only ref returning function pointers are assignable");
1221if (unwrappedSequence is BoundLocal { LocalSymbol: { RefKind: not RefKind.None } localSymbol })
1255private ImmutableArray<BoundExpression> VisitArguments(ImmutableArray<BoundExpression> arguments, ImmutableArray<ParameterSymbol> parameters, ImmutableArray<RefKind> argRefKindsOpt)
1265RefKind argRefKind = CodeGenerator.GetArgumentRefKind(arguments, parameters, argRefKindsOpt, i);
1272private void VisitArgument(ImmutableArray<BoundExpression> arguments, ref ArrayBuilder<BoundExpression> rewrittenArguments, int i, RefKind argRefKind)
1274ExprContext context = (argRefKind == RefKind.None) ? ExprContext.Value : ExprContext.Address;
1296ImmutableArray<RefKind> argRefKindsOpt = node.ArgumentRefKindsOpt;
1300RefKind refKind = argRefKindsOpt.IsDefaultOrEmpty ? RefKind.None : argRefKindsOpt[i];
1428if (localSym.RefKind == RefKind.None)
1874Debug.Assert(local.RefKind == RefKind.None, "cannot take a ref of a ref");
1935return top.Item2 == (local.RefKind == RefKind.None ? ExprContext.Value : ExprContext.Address) &&
2162var isIndirectLocalStore = left.LocalSymbol.RefKind != RefKind.None && !node.IsRef;
2191left.LocalSymbol.RefKind == RefKind.Ref &&
2428public override RefKind RefKind
2430get { return RefKind.None; }
Compiler\MethodBodySynthesizer.cs (5)
50argumentRefKindsOpt: ImmutableArray<RefKind>.Empty,
193statement = new BoundReturnStatement(accessor.SyntaxNode, RefKind.None, fieldAccess, @checked: false);
311BoundStatement returnStatement = BoundReturnStatement.Synthesized(syntax, RefKind.None, processHandlerCall);
321BoundStatement returnStatement = new BoundReturnStatement(syntax, RefKind.None, expressionOpt: null, @checked: false);
358refKind: RefKind.None,
FlowAnalysis\AbstractFlowPass.cs (36)
1132VisitArguments(node.Arguments, default(ImmutableArray<RefKind>), null);
1293VisitRvalue(node.InitializerOpt, isKnownToBeAnLvalue: node.LocalSymbol.RefKind != RefKind.None);
1296if (node.LocalSymbol.RefKind != RefKind.None)
1436WriteArgument(receiverOpt, RefKind.Ref, method: null);
1442var thisRefKind = thisParameter.RefKind;
1516protected virtual void VisitArguments(ImmutableArray<BoundExpression> arguments, ImmutableArray<RefKind> refKindsOpt, MethodSymbol method)
1523private void VisitArgumentsBeforeCall(ImmutableArray<BoundExpression> arguments, ImmutableArray<RefKind> refKindsOpt)
1528RefKind refKind = GetRefKind(refKindsOpt, i);
1529if (refKind != RefKind.Out)
1531VisitRvalue(arguments[i], isKnownToBeAnLvalue: refKind != RefKind.None);
1543private void VisitArgumentsAfterCall(ImmutableArray<BoundExpression> arguments, ImmutableArray<RefKind> refKindsOpt, MethodSymbol method)
1547RefKind refKind = GetRefKind(refKindsOpt, i);
1550case RefKind.None:
1551case RefKind.In:
1552case RefKind.RefReadOnlyParameter:
1555case RefKind.Ref:
1556case RefKind.Out:
1566protected static RefKind GetRefKind(ImmutableArray<RefKind> refKindsOpt, int index)
1568return refKindsOpt.IsDefault || refKindsOpt.Length <= index ? RefKind.None : refKindsOpt[index];
1571protected virtual void WriteArgument(BoundExpression arg, RefKind refKind, MethodSymbol method)
2026VisitRvalue(node.ExpressionOpt, isKnownToBeAnLvalue: node.RefKind != RefKind.None);
2029if (node.RefKind != RefKind.None)
2139if (property.RefKind == RefKind.None)
2157var refKind = node.Left.Kind == BoundKind.BadExpression
2158? RefKind.Ref
2194if (property.RefKind == RefKind.None)
2213if (property.RefKind == RefKind.None)
2805if (property.RefKind == RefKind.None)
3302WriteArgument(operand, RefKind.Ref, method: null);
3488this.WriteArgument(operand, RefKind.Out, null); //Out because we know it will definitely be assigned.
3529VisitArguments(node.Arguments, default(ImmutableArray<RefKind>), node.Constructor);
3613VisitArguments(node.Arguments, default(ImmutableArray<RefKind>), node.AddMethod);
3619VisitArguments(node.Arguments, default(ImmutableArray<RefKind>), node.AddMethod);
3627VisitArguments(node.Arguments, default(ImmutableArray<RefKind>), method: null);
3709property.RefKind == RefKind.None)
FlowAnalysis\DefiniteAssignment.cs (20)
349NoteWrite(parameter, value: null, read: true, isRef: parameter.RefKind != RefKind.None);
859write: field.RefKind == RefKind.None || isRef);
971write: field.RefKind == RefKind.None || isRef);
1234((ParameterSymbol)symbol).RefKind == RefKind.Out)
1334if (fieldSymbol.RefKind != RefKind.None)
1518if (!isRef && node is BoundFieldAccess { FieldSymbol.RefKind: not RefKind.None } fieldAccess)
1571if (local.LocalSymbol.RefKind != RefKind.None && !isRef)
1622if (isRef && param.RefKind == RefKind.Out)
1640write: field.RefKind == RefKind.None || isRef);
1814if (parameter.RefKind != RefKind.Out)
1826if (thisParameter.RefKind != RefKind.Out)
1849if (current is not MethodSymbol && parameter.RefKind == RefKind.Out)
1879if (parameter.RefKind == RefKind.Out && !(this.CurrentSymbol is MethodSymbol currentMethod && currentMethod.IsAsync)) // out parameters not allowed in async
1887NoteWrite(parameter, value: null, read: true, isRef: parameter.RefKind != RefKind.None);
1945if (!parameter.IsThis && parameter.RefKind != RefKind.Out && parameter.ContainingSymbol is SynthesizedPrimaryConstructor primaryCtor)
1957if (parameter.RefKind != RefKind.None)
2567protected override void WriteArgument(BoundExpression arg, RefKind refKind, MethodSymbol method)
2569if (refKind == RefKind.Ref)
2583if (refKind != RefKind.None && ((object)method == null || method.IsExtern) && arg.Type is TypeSymbol type)
2771NoteWrite(iterationVariable, null, read: true, isRef: iterationVariable.RefKind != RefKind.None);
FlowAnalysis\NullableWalker.cs (53)
1255var refKind = parameter.RefKind;
1256if (refKind != RefKind.Out && refKind != RefKind.Ref)
2370RefKind refKind,
2380if (refKind == RefKind.Ref)
2383return AreParameterAnnotationsCompatible(RefKind.None, overriddenType, overriddenAnnotations, overridingType, overridingAnnotations, forRef: true) &&
2384AreParameterAnnotationsCompatible(RefKind.Out, overriddenType, overriddenAnnotations, overridingType, overridingAnnotations);
2387if (refKind is RefKind.None or RefKind.In or RefKind.RefReadOnlyParameter)
2417if (refKind == RefKind.Out)
2822if (parameter.RefKind != RefKind.Out)
2895if (node.RefKind == RefKind.None &&
2904if (node.RefKind == RefKind.None)
6220var refKind = GetRefKind(node.ArgumentRefKindsOpt, 0);
6278ImmutableArray<RefKind> refKindsOpt = node.ArgumentRefKindsOpt;
6708protected override void VisitArguments(ImmutableArray<BoundExpression> arguments, ImmutableArray<RefKind> refKindsOpt, MethodSymbol method)
6717ImmutableArray<RefKind> refKindsOpt,
6730ImmutableArray<RefKind> refKindsOpt,
6745ImmutableArray<RefKind> refKindsOpt,
6766ImmutableArray<RefKind> refKindsOpt,
6807ImmutableArray<RefKind> refKindsOpt,
6977ImmutableArray<RefKind> refKindsOpt,
6995static void expandParamsCollection(ref ImmutableArray<BoundExpression> arguments, ref ImmutableArray<RefKind> refKindsOpt, ImmutableArray<ParameterSymbol> parametersOpt, ref ImmutableArray<int> argsToParamsOpt, ref BitVector defaultArguments)
7055var refKindsBuilder = ArrayBuilder<RefKind>.GetInstance(refKindsOpt.Length + elements.Length - 1);
7057refKindsBuilder.AddMany(RefKind.None, elements.Length);
7218ImmutableArray<RefKind> refKindsOpt,
7279private VisitResult VisitArgumentEvaluate(BoundExpression argument, RefKind refKind, FlowAnalysisAnnotations annotations)
7291private VisitResult VisitArgumentEvaluateEpilogue(BoundExpression argument, RefKind refKind, FlowAnalysisAnnotations annotations)
7297case RefKind.Ref:
7300case RefKind.None:
7301case RefKind.In:
7323case RefKind.Out:
7346RefKind refKind,
7361case RefKind.None:
7362case RefKind.In:
7400case RefKind.Ref:
7420case RefKind.Out:
7483RefKind refKind,
7496case RefKind.None:
7497case RefKind.In:
7503case RefKind.Ref:
7530case RefKind.Out:
7736ImmutableArray<RefKind> refKindsOpt)
7747RefKind refKind = GetRefKind(refKindsOpt, i);
7750if (refKind == RefKind.None)
7818ImmutableArray<RefKind> argumentRefKindsOpt,
7827var refKinds = ArrayBuilder<RefKind>.GetInstance();
7848parameterRefKinds: out ImmutableArray<RefKind> parameterRefKinds);
10087case BoundLocal { LocalSymbol.RefKind: RefKind.None }:
10088case BoundParameter { ParameterSymbol: { RefKind: RefKind.None } parameter } when
11995TypeWithAnnotations elementType = InMethodBinder.GetIteratorElementTypeFromReturnType(compilation, RefKind.None,
12035VisitArguments(node, node.ConstructorArguments, ImmutableArray<RefKind>.Empty, node.Constructor, argsToParamsOpt: node.ConstructorArgumentsToParamsOpt, defaultArguments: node.ConstructorDefaultArguments,
Generated\BoundNodes.xml.Generated.cs (37)
921public BoundDup(SyntaxNode syntax, RefKind refKind, TypeSymbol? type, bool hasErrors)
927public BoundDup(SyntaxNode syntax, RefKind refKind, TypeSymbol? type)
933public RefKind RefKind { get; }
938public BoundDup Update(RefKind refKind, TypeSymbol? type)
1446public BoundFunctionPointerInvocation(SyntaxNode syntax, BoundExpression invokedExpression, ImmutableArray<BoundExpression> arguments, ImmutableArray<RefKind> argumentRefKindsOpt, LookupResultKind resultKind, TypeSymbol type, bool hasErrors = false)
1463public ImmutableArray<RefKind> ArgumentRefKindsOpt { get; }
1469public BoundFunctionPointerInvocation Update(BoundExpression invokedExpression, ImmutableArray<BoundExpression> arguments, ImmutableArray<RefKind> argumentRefKindsOpt, LookupResultKind resultKind, TypeSymbol type)
3064public BoundArgListOperator(SyntaxNode syntax, ImmutableArray<BoundExpression> arguments, ImmutableArray<RefKind> argumentRefKindsOpt, TypeSymbol? type, bool hasErrors = false)
3076public ImmutableArray<RefKind> ArgumentRefKindsOpt { get; }
3081public BoundArgListOperator Update(ImmutableArray<BoundExpression> arguments, ImmutableArray<RefKind> argumentRefKindsOpt, TypeSymbol? type)
3570public BoundReturnStatement(SyntaxNode syntax, RefKind refKind, BoundExpression? expressionOpt, bool @checked, bool hasErrors = false)
3578public RefKind RefKind { get; }
3585public BoundReturnStatement Update(RefKind refKind, BoundExpression? expressionOpt, bool @checked)
5894public BoundDynamicInvocation(SyntaxNode syntax, ImmutableArray<string?> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, ImmutableArray<MethodSymbol> applicableMethods, BoundExpression expression, ImmutableArray<BoundExpression> arguments, TypeSymbol type, bool hasErrors = false)
5910public ImmutableArray<RefKind> ArgumentRefKindsOpt { get; }
5916public BoundDynamicInvocation Update(ImmutableArray<string?> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, ImmutableArray<MethodSymbol> applicableMethods, BoundExpression expression, ImmutableArray<BoundExpression> arguments, TypeSymbol type)
6144public BoundCall(SyntaxNode syntax, BoundExpression? receiverOpt, ThreeState initialBindingReceiverIsSubjectToCloning, MethodSymbol method, ImmutableArray<BoundExpression> arguments, ImmutableArray<string?> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, bool isDelegateCall, bool expanded, bool invokedAsExtensionMethod, ImmutableArray<int> argsToParamsOpt, BitVector defaultArguments, LookupResultKind resultKind, ImmutableArray<MethodSymbol> originalMethodsOpt, TypeSymbol type, bool hasErrors = false)
6173public ImmutableArray<RefKind> ArgumentRefKindsOpt { get; }
6185public BoundCall Update(BoundExpression? receiverOpt, ThreeState initialBindingReceiverIsSubjectToCloning, MethodSymbol method, ImmutableArray<BoundExpression> arguments, ImmutableArray<string?> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, bool isDelegateCall, bool expanded, bool invokedAsExtensionMethod, ImmutableArray<int> argsToParamsOpt, BitVector defaultArguments, LookupResultKind resultKind, ImmutableArray<MethodSymbol> originalMethodsOpt, TypeSymbol type)
6283public BoundUnconvertedObjectCreationExpression(SyntaxNode syntax, ImmutableArray<BoundExpression> arguments, ImmutableArray<(string Name, Location Location)?> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, InitializerExpressionSyntax? initializerOpt, Binder binder, bool hasErrors = false)
6300public ImmutableArray<RefKind> ArgumentRefKindsOpt { get; }
6307public BoundUnconvertedObjectCreationExpression Update(ImmutableArray<BoundExpression> arguments, ImmutableArray<(string Name, Location Location)?> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, InitializerExpressionSyntax? initializerOpt, Binder binder)
6342public BoundObjectCreationExpression(SyntaxNode syntax, MethodSymbol constructor, ImmutableArray<MethodSymbol> constructorsGroup, ImmutableArray<BoundExpression> arguments, ImmutableArray<string?> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, bool expanded, ImmutableArray<int> argsToParamsOpt, BitVector defaultArguments, ConstantValue? constantValueOpt, BoundObjectInitializerExpressionBase? initializerExpressionOpt, bool wasTargetTyped, TypeSymbol type, bool hasErrors = false)
6368public override ImmutableArray<RefKind> ArgumentRefKindsOpt { get; }
6379public BoundObjectCreationExpression Update(MethodSymbol constructor, ImmutableArray<MethodSymbol> constructorsGroup, ImmutableArray<BoundExpression> arguments, ImmutableArray<string?> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, bool expanded, ImmutableArray<int> argsToParamsOpt, BitVector defaultArguments, ConstantValue? constantValueOpt, BoundObjectInitializerExpressionBase? initializerExpressionOpt, bool wasTargetTyped, TypeSymbol type)
6622public BoundDynamicObjectCreationExpression(SyntaxNode syntax, string name, ImmutableArray<BoundExpression> arguments, ImmutableArray<string?> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, BoundObjectInitializerExpressionBase? initializerExpressionOpt, ImmutableArray<MethodSymbol> applicableMethods, bool wasTargetTyped, TypeSymbol type, bool hasErrors = false)
6643public override ImmutableArray<RefKind> ArgumentRefKindsOpt { get; }
6651public BoundDynamicObjectCreationExpression Update(string name, ImmutableArray<BoundExpression> arguments, ImmutableArray<string?> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, BoundObjectInitializerExpressionBase? initializerExpressionOpt, ImmutableArray<MethodSymbol> applicableMethods, bool wasTargetTyped, TypeSymbol type)
6744public BoundObjectInitializerMember(SyntaxNode syntax, Symbol? memberSymbol, ImmutableArray<BoundExpression> arguments, ImmutableArray<string?> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, bool expanded, ImmutableArray<int> argsToParamsOpt, BitVector defaultArguments, LookupResultKind resultKind, AccessorKind accessorKind, TypeSymbol receiverType, TypeSymbol type, bool hasErrors = false)
6768public ImmutableArray<RefKind> ArgumentRefKindsOpt { get; }
6779public BoundObjectInitializerMember Update(Symbol? memberSymbol, ImmutableArray<BoundExpression> arguments, ImmutableArray<string?> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, bool expanded, ImmutableArray<int> argsToParamsOpt, BitVector defaultArguments, LookupResultKind resultKind, AccessorKind accessorKind, TypeSymbol receiverType, TypeSymbol type)
7412public BoundIndexerAccess(SyntaxNode syntax, BoundExpression? receiverOpt, ThreeState initialBindingReceiverIsSubjectToCloning, PropertySymbol indexer, ImmutableArray<BoundExpression> arguments, ImmutableArray<string?> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, bool expanded, AccessorKind accessorKind, ImmutableArray<int> argsToParamsOpt, BitVector defaultArguments, ImmutableArray<PropertySymbol> originalIndexersOpt, TypeSymbol type, bool hasErrors = false)
7439public ImmutableArray<RefKind> ArgumentRefKindsOpt { get; }
7449public BoundIndexerAccess Update(BoundExpression? receiverOpt, ThreeState initialBindingReceiverIsSubjectToCloning, PropertySymbol indexer, ImmutableArray<BoundExpression> arguments, ImmutableArray<string?> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, bool expanded, AccessorKind accessorKind, ImmutableArray<int> argsToParamsOpt, BitVector defaultArguments, ImmutableArray<PropertySymbol> originalIndexersOpt, TypeSymbol type)
7553public BoundDynamicIndexerAccess(SyntaxNode syntax, BoundExpression receiver, ImmutableArray<BoundExpression> arguments, ImmutableArray<string?> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, ImmutableArray<PropertySymbol> applicableIndexers, TypeSymbol type, bool hasErrors = false)
7573public ImmutableArray<RefKind> ArgumentRefKindsOpt { get; }
7579public BoundDynamicIndexerAccess Update(BoundExpression receiver, ImmutableArray<BoundExpression> arguments, ImmutableArray<string?> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, ImmutableArray<PropertySymbol> applicableIndexers, TypeSymbol type)
Lowering\LocalRewriter\LocalRewriter_Call.cs (81)
139ref ImmutableArray<RefKind> argumentRefKindsOpt,
284var thisRefKind = methodThisParameter.RefKind;
287if (thisRefKind != RefKind.None
290thisRefKind == RefKind.Ref ? CodeGenerator.AddressKind.Writeable : CodeGenerator.AddressKind.ReadOnlyStrict,
304if (argumentRefKindsOpt.IsDefault && thisRefKind != RefKind.None)
385ImmutableArray<RefKind> argRefKindsOpt = node.ArgumentRefKindsOpt;
443ImmutableArray<RefKind> argumentRefKinds,
530argumentRefKinds: default(ImmutableArray<RefKind>),
535private static bool IsSafeForReordering(BoundExpression expression, RefKind kind)
561return kind != RefKind.None;
659ImmutableArray<RefKind> argumentRefKindsOpt,
679RefKind refKind;
691refKind = rewrittenReceiver.Type.IsValueType || rewrittenReceiver.Type.Kind == SymbolKind.TypeParameter ? RefKind.Ref : RefKind.None;
697refKind = RefKind.None;
703if (refKind == RefKind.None &&
710refKind = RefKind.Ref;
879RefKind argRefKind = argumentRefKindsOpt.RefKinds(argIndex);
880RefKind paramRefKind = parameters[paramIndex].RefKind;
882local = _factory.StoreToTemp(visitedArgument, out var store, refKind: paramRefKind is RefKind.In or RefKind.RefReadOnlyParameter ? RefKind.In : argRefKind);
951var intermediateRef = _factory.Local(_factory.SynthesizedLocal(receiverType, refKind: RefKind.Ref));
1002ref ImmutableArray<RefKind> argumentRefKindsOpt,
1085ArrayBuilder<RefKind> refKinds = ArrayBuilder<RefKind>.GetInstance(parameters.Length, RefKind.None);
1155private static ImmutableArray<RefKind> GetEffectiveArgumentRefKinds(ImmutableArray<RefKind> argumentRefKindsOpt, ImmutableArray<ParameterSymbol> parameters)
1157ArrayBuilder<RefKind>? refKindsBuilder = null;
1160var paramRefKind = parameters[i].RefKind;
1161if (paramRefKind is RefKind.In or RefKind.RefReadOnlyParameter)
1163var argRefKind = argumentRefKindsOpt.IsDefault ? RefKind.None : argumentRefKindsOpt[i];
1165refKindsBuilder[i] = argRefKind == RefKind.None ? RefKind.In : RefKindExtensions.StrictIn;
1167else if (paramRefKind == RefKind.Ref)
1169var argRefKind = argumentRefKindsOpt.IsDefault ? RefKind.None : argumentRefKindsOpt[i];
1170if (argRefKind == RefKind.None)
1176refKindsBuilder[i] = RefKind.Ref;
1190static void fillRefKindsBuilder(ImmutableArray<RefKind> argumentRefKindsOpt, ImmutableArray<ParameterSymbol> parameters, [NotNull] ref ArrayBuilder<RefKind>? refKindsBuilder)
1197refKindsBuilder = ArrayBuilder<RefKind>.GetInstance(parameters.Length);
1202refKindsBuilder = ArrayBuilder<RefKind>.GetInstance(parameters.Length, fillWithValue: RefKind.None);
1243private static ImmutableArray<RefKind> GetRefKindsOrNull(ArrayBuilder<RefKind> refKinds)
1247if (refKind != RefKind.None)
1252return default(ImmutableArray<RefKind>);
1305ImmutableArray<RefKind> argumentRefKinds,
1309/* out */ ArrayBuilder<RefKind> refKinds,
1321RefKind argRefKind = argumentRefKinds.RefKinds(a);
1322RefKind paramRefKind = parameters[p].RefKind;
1330Debug.Assert(argRefKind == RefKind.None);
1346arg.rewriter.StoreArgumentToTempIfNecessary(arg.forceLambdaSpilling, arg.storesToTemps, element, RefKind.None, RefKind.None),
1363if (paramRefKind is RefKind.In or RefKind.RefReadOnlyParameter)
1365Debug.Assert(argRefKind is RefKind.None or RefKind.In or RefKind.Ref);
1366argRefKind = argRefKind == RefKind.None ? RefKind.In : RefKindExtensions.StrictIn;
1375private BoundExpression StoreArgumentToTempIfNecessary(bool forceLambdaSpilling, ArrayBuilder<BoundAssignmentOperator> storesToTemps, BoundExpression argument, RefKind argRefKind, RefKind paramRefKind)
1387refKind: paramRefKind is RefKind.In or RefKind.RefReadOnlyParameter
1388? (argRefKind == RefKind.None ? RefKind.In : RefKindExtensions.StrictIn)
1442default(ImmutableArray<RefKind>),
1602ArrayBuilder<RefKind> argsRefKindsBuilder,
1615RefKind paramRefKind = parameters[argIndex].RefKind;
1616RefKind argRefKind = argsRefKindsBuilder[argIndex];
1620if (argRefKind != RefKind.None || paramRefKind != RefKind.Ref)
1628var localRefKind = ((BoundLocal)argument).LocalSymbol.RefKind;
1629if (localRefKind == RefKind.Ref)
1635Debug.Assert(localRefKind == RefKind.None);
1647argsRefKindsBuilder[argIndex] = RefKind.Ref;
Lowering\LocalRewriter\LocalRewriter_ForEachStatement.cs (5)
619RefKind collectionTempRefKind = RefKind.None;
707private delegate BoundStatement? GetForEachStatementAsForPreamble(LocalRewriter rewriter, SyntaxNode syntax, ForEachEnumeratorInfo enumeratorInfo, ref BoundExpression rewrittenExpression, out LocalSymbol? preambleLocal, out RefKind collectionTempRefKind);
746return static (LocalRewriter rewriter, SyntaxNode syntax, ForEachEnumeratorInfo enumeratorInfo, ref BoundExpression rewrittenExpression, out LocalSymbol? preambleLocal, out RefKind collectionTempRefKind) =>
760collectionTempRefKind = enumeratorInfo.InlineArraySpanType == WellKnownType.System_Span_T ? RefKind.Ref : RefKindExtensions.StrictIn;
Lowering\LocalRewriter\LocalRewriter_ObjectOrCollectionInitializerExpression.cs (13)
132default(ImmutableArray<RefKind>),
147.All(p => p.RefKind is RefKind.None or RefKind.In or RefKind.RefReadOnlyParameter));
163var argumentRefKindsOpt = default(ImmutableArray<RefKind>);
164if (addMethod.Parameters[0].RefKind == RefKind.Ref)
169var builder = ArrayBuilder<RefKind>.GetInstance(addMethod.Parameters.Length, RefKind.None);
170builder[0] = RefKind.Ref;
307memberInit.MemberSymbol?.GetParameterRefKinds() ?? default(ImmutableArray<RefKind>),
589ImmutableArray<RefKind> paramRefKindsOpt,
609elementArg.rewriter.EvaluateSideEffects(element, RefKind.None, elementArg.sideeffects, ref elementArg.temps),
637private BoundExpression EvaluateSideEffects(BoundExpression arg, RefKind refKind, ArrayBuilder<BoundExpression> sideeffects, ref ArrayBuilder<LocalSymbol>? temps)
Lowering\LocalRewriter\LoweredDynamicOperationFactory.cs (54)
111return MakeDynamicOperation(binderConstruction, null, RefKind.None, loweredArguments, default(ImmutableArray<RefKind>), null, resultType);
147return MakeDynamicOperation(binderConstruction, null, RefKind.None, loweredArguments, default(ImmutableArray<RefKind>), null, resultType);
190return MakeDynamicOperation(binderConstruction, null, RefKind.None, loweredArguments, default(ImmutableArray<RefKind>), null, resultType);
199ImmutableArray<RefKind> refKinds,
223RefKind receiverRefKind;
228receiverRefKind = RefKind.None;
292return MakeDynamicOperation(binderConstruction, loweredReceiver, RefKind.None, loweredArguments, default(ImmutableArray<RefKind>), loweredHandler, resultType);
299ImmutableArray<RefKind> refKinds,
329return MakeDynamicOperation(binderConstruction, loweredReceiver, RefKind.None, loweredArguments, refKinds, null, resultType);
337ImmutableArray<RefKind> refKinds)
356return MakeDynamicOperation(binderConstruction, loweredReceiver, RefKind.None, loweredArguments, refKinds, null, type);
391return MakeDynamicOperation(binderConstruction, loweredReceiver, RefKind.None, loweredArguments, default(ImmutableArray<RefKind>), null, resultType);
432return MakeDynamicOperation(binderConstruction, loweredReceiver, RefKind.None, loweredArguments, default(ImmutableArray<RefKind>), loweredRight, AssemblySymbol.DynamicType);
439ImmutableArray<RefKind> refKinds)
458return MakeDynamicOperation(binderConstruction, loweredReceiver, RefKind.None, loweredArguments, refKinds, null, resultType);
465ImmutableArray<RefKind> refKinds,
481var loweredReceiverRefKind = GetReceiverRefKind(loweredReceiver);
516return MakeDynamicOperation(binderConstruction, loweredReceiver, RefKind.None, ImmutableArray<BoundExpression>.Empty, default(ImmutableArray<RefKind>), null, resultType);
542internal RefKind GetReceiverRefKind(BoundExpression loweredReceiver)
547return RefKind.None;
555return hasHome ? RefKind.Ref : RefKind.None;
562ImmutableArray<RefKind> refKinds = default(ImmutableArray<RefKind>),
564RefKind receiverRefKind = RefKind.None,
571Debug.Assert(!receiverIsStaticType || receiverRefKind == RefKind.None);
586refKinds.IsDefault ? RefKind.None : refKinds[i],
592infos[j++] = GetArgumentInfo(argumentInfoFactory, loweredRight, NoName, RefKind.None, isStaticType: false);
601RefKind receiverRefKind,
603ImmutableArray<RefKind> refKinds,
720RefKind receiverRefKind,
722ImmutableArray<RefKind> refKinds,
736bool hasByRefs = receiverRefKind != RefKind.None || !refKinds.IsDefaultOrEmpty;
776byRefs[j++] = RefKind.None;
791static RefKind getRefKind(RefKind refKind)
793Debug.Assert(refKind != RefKind.RefReadOnlyParameter);
794return refKind == RefKind.None ? RefKind.None : RefKind.Ref;
802RefKind refKind,
817Debug.Assert(refKind == RefKind.None || refKind == RefKind.Ref || refKind == RefKind.Out, "unexpected refKind in dynamic");
820if (refKind == RefKind.Out)
824else if (refKind == RefKind.Ref)
Lowering\SpillSequenceSpiller.cs (42)
305RefKind refKind = RefKind.None,
317Debug.Assert(refKind == RefKind.None);
324Debug.Assert(refKind == RefKind.None);
337if (refKind != RefKind.None || expression.Type?.IsRefLikeOrAllowsRefLikeType() == true)
370var left = Spill(builder, assignment.Left, RefKind.Ref);
371var right = Spill(builder, assignment.Right, RefKind.Ref);
380if (refKind != RefKind.None || expression.Type.IsReferenceType)
388if (refKind != RefKind.None)
397if (local.LocalSymbol.SynthesizedKind == SynthesizedLocalKind.Spill || refKind != RefKind.None)
410if (refKind != RefKind.None || fieldSymbol.IsReadOnly)
417if (refKind == RefKind.None) goto default;
419var receiver = Spill(builder, field.ReceiverOpt, fieldSymbol.ContainingType.IsValueType ? refKind : RefKind.None);
437if (refKind != RefKind.None)
482if (refKind == RefKind.None &&
489[Spill(builder, objectCreationExpression.Arguments[0], argRefKinds.IsDefault ? RefKind.None : argRefKinds[0])],
538Left: BoundLocal { LocalSymbol: { SynthesizedKind: SynthesizedLocalKind.LoweringTemp, RefKind: RefKind.Ref } receiverRefLocal },
541ValueTypeReceiver: BoundLocal { LocalSymbol: { SynthesizedKind: SynthesizedLocalKind.LoweringTemp, RefKind: RefKind.Ref } } valueTypeReceiver,
550Left: BoundLocal { LocalSymbol: { SynthesizedKind: SynthesizedLocalKind.LoweringTemp, RefKind: RefKind.None } referenceTypeClone },
551Right: BoundLocal { LocalSymbol: { SynthesizedKind: SynthesizedLocalKind.LoweringTemp, RefKind: RefKind.Ref } originalReceiverReference }
554Value: BoundLocal { LocalSymbol: { SynthesizedKind: SynthesizedLocalKind.LoweringTemp, RefKind: RefKind.None } } referenceTypeReceiver
586ImmutableArray<RefKind> refKinds = default(ImmutableArray<RefKind>),
634var refKind = refKinds.IsDefault ? RefKind.None : refKinds[i];
892expression = Spill(leftBuilder, expression, RefKind.None);
907left = Spill(leftBuilder, VisitExpression(ref leftBuilder, left), RefKind.Ref);
939expression = Spill(leftBuilder, expression, RefKind.None);
954receiver = Spill(leftBuilder, VisitExpression(ref leftBuilder, field.ReceiverOpt), RefKind.Ref);
1032RefKind refKind = ReceiverSpillRefKind(receiver);
1034Debug.Assert(refKind == RefKind.None || !receiver.Type.IsReferenceType);
1038if (refKind != RefKind.None &&
1071private static RefKind ReceiverSpillRefKind(BoundExpression receiver)
1073var result = RefKind.None;
1076result = receiver.Type.IsReadOnly ? RefKind.In : RefKind.Ref;
1265var receiverRefKind = ReceiverSpillRefKind(node.Receiver);
1286if (receiver.Type.IsReferenceType || receiver.Type.IsValueType || receiverRefKind == RefKind.None)
1289receiver = Spill(receiverBuilder, receiver, RefKind.None);
1304receiver = Spill(receiverBuilder, receiver, RefKind.Ref);
1306var clone = _F.SynthesizedLocal(receiver.Type, _F.Syntax, refKind: RefKind.None, kind: SynthesizedLocalKind.Spill);
Lowering\StateMachineRewriter\MethodToStateMachineRewriter.cs (20)
313if (local.RefKind != RefKind.None)
558var sacrificialTemp = F.SynthesizedLocal(type, refKind: RefKind.Ref);
578RefKind refKind,
588BoundExpression expression = HoistExpression(array.Expression, awaitSyntaxOpt, syntaxOffset, RefKind.None, sideEffects, hoistedFields, ref needsSacrificialEvaluation);
592indices.Add(HoistExpression(index, awaitSyntaxOpt, syntaxOffset, RefKind.None, sideEffects, hoistedFields, ref needsSacrificialEvaluation));
605if (refKind != RefKind.None || field.FieldSymbol.IsReadOnly) return expr;
609if (refKind == RefKind.None)
617isFieldOfStruct ? refKind : RefKind.None, sideEffects, hoistedFields, ref needsSacrificialEvaluation);
639if (refKind != RefKind.None && refKind != RefKind.In)
641Debug.Assert(refKind is RefKindExtensions.StrictIn or RefKind.Ref or RefKind.Out);
642Debug.Assert(call.Method.RefKind != RefKind.None);
646refKind = RefKind.None;
657if (refKind != RefKind.None && refKind != RefKind.RefReadOnly)
659Debug.Assert(refKind is RefKindExtensions.StrictIn or RefKind.Ref or RefKind.In);
664refKind = RefKind.None;
673if (refKind != RefKind.None)
Lowering\SyntheticBoundNodeFactory.cs (25)
561Debug.Assert(CurrentFunction.RefKind == RefKind.None);
586RefKind refKind = RefKind.None,
626return SynthesizedParameterSymbol.Create(container, TypeWithAnnotations.Create(type), ordinal, RefKind.None, name);
749public BoundObjectCreationExpression New(MethodSymbol constructor, ImmutableArray<BoundExpression> arguments, ImmutableArray<RefKind> argumentRefKinds)
858static ImmutableArray<RefKind> getArgumentRefKinds(MethodSymbol method, bool useStrictArgumentRefKinds)
862if (!result.IsDefaultOrEmpty && (result.Contains(RefKind.RefReadOnlyParameter) ||
863(useStrictArgumentRefKinds && result.Contains(RefKind.In))))
865var builder = ArrayBuilder<RefKind>.GetInstance(result.Length);
867foreach (var refKind in result)
871RefKind.In or RefKind.RefReadOnlyParameter when useStrictArgumentRefKinds => RefKindExtensions.StrictIn,
872RefKind.RefReadOnlyParameter => RefKind.In,
884public BoundCall Call(BoundExpression? receiver, MethodSymbol method, ImmutableArray<RefKind> refKinds, ImmutableArray<BoundExpression> args)
1633RefKind refKind = RefKind.None,
1650case RefKind.Out:
1651refKind = RefKind.Ref;
1654case RefKind.In:
1663Debug.Assert(argument.GetRefKind() != RefKind.In);
1664refKind = RefKind.None;
1668case RefKind.None:
1669case RefKind.Ref:
1700isRef: refKind != RefKind.None);
Symbols\Compilation_WellKnownMembers.cs (13)
775internal SynthesizedAttributeData? SynthesizeDynamicAttribute(TypeSymbol type, int customModifiersCount, RefKind refKindOpt = RefKind.None)
780if (type.IsDynamic() && refKindOpt == RefKind.None && customModifiersCount == 0)
889internal static ImmutableArray<TypedConstant> Encode(TypeSymbol type, RefKind refKind, int customModifiersCount, TypeSymbol booleanType)
901internal static ImmutableArray<bool> Encode(TypeSymbol type, RefKind refKind, int customModifiersCount)
908internal static ImmutableArray<bool> EncodeWithoutCustomModifierFlags(TypeSymbol type, RefKind refKind)
915internal static void Encode(TypeSymbol type, int customModifiersCount, RefKind refKind, ArrayBuilder<bool> transformFlagsBuilder, bool addCustomModifierFlags)
919if (refKind != RefKind.None)
1010void handle(RefKind refKind, ImmutableArray<CustomModifier> customModifiers, TypeWithAnnotations twa)
1017if (refKind != RefKind.None)
1172return parameter.RefKind != RefKind.None;
1177return method.RefKind != RefKind.None;
1182return property.RefKind != RefKind.None;
Symbols\FunctionPointers\FunctionPointerMethodSymbol.cs (48)
28RefKind refKind = RefKind.None;
44case SyntaxKind.RefKeyword when refKind == RefKind.None:
48refKind = RefKind.RefReadOnly;
53refKind = RefKind.Ref;
59Debug.Assert(refKind != RefKind.None);
73if (returnType.IsVoidType() && refKind != RefKind.None)
88if (refKind != RefKind.None)
247RefKind returnRefKind,
250ImmutableArray<RefKind> parameterRefKinds,
271RefKind returnRefKind,
273ImmutableArray<RefKind> parameterRefKinds,
285if (returnRefKind == RefKind.None)
310private static CustomModifier? GetCustomModifierForRefKind(RefKind refKind, CSharpCompilation compilation)
312Debug.Assert(refKind is RefKind.None or RefKind.In or RefKind.Ref or RefKind.Out);
316RefKind.In => compilation.GetWellKnownType(WellKnownType.System_Runtime_InteropServices_InAttribute),
317RefKind.Out => compilation.GetWellKnownType(WellKnownType.System_Runtime_InteropServices_OutAttribute),
323Debug.Assert(refKind != RefKind.Out && refKind != RefKind.In);
351var returnVariance = RefKind == RefKind.None ? variance : VarianceKind.None;
366(VarianceKind.In, RefKind.None) => VarianceKind.Out,
367(VarianceKind.Out, RefKind.None) => VarianceKind.In,
443RefKind refKind,
488RefKind refKind,
493ImmutableArray<RefKind> parameterRefKinds,
496Debug.Assert(refKind != RefKind.Out);
497Debug.Assert(refCustomModifiers.IsDefaultOrEmpty || refKind != RefKind.None);
509Debug.Assert(refCustomModifiers.IsEmpty || refKind != RefKind.None);
513static ImmutableArray<CustomModifier> getCustomModifierArrayForRefKind(RefKind refKind, CSharpCompilation compilation)
519RefKind refKind,
553RefKind = getRefKind(retInfo, RefCustomModifiers, RefKind.RefReadOnly, RefKind.Ref, requiresLocationAllowed: false);
554Debug.Assert(RefKind != RefKind.Out);
569RefKind paramRefKind = getRefKind(param, paramRefCustomMods, RefKind.In, RefKind.Out, requiresLocationAllowed: true);
581static RefKind getRefKind(ParamInfo<TypeSymbol> param, ImmutableArray<CustomModifier> paramRefCustomMods, RefKind hasInRefKind, RefKind hasOutRefKind, bool requiresLocationAllowed)
585false => RefKind.None,
588true when requiresLocationAllowed && CustomModifierUtils.HasRequiresLocationAttributeModifier(paramRefCustomMods) => RefKind.RefReadOnlyParameter,
589true => RefKind.Ref,
648var modifiersToSearch = RefKind != RefKind.None ? RefCustomModifiers : ReturnTypeWithAnnotations.CustomModifiers;
671var modifiersToSearch = RefKind != RefKind.None ? RefCustomModifiers : ReturnTypeWithAnnotations.CustomModifiers;
767public override RefKind RefKind { get; }
Symbols\Source\ParameterHelpers.cs (35)
42ParameterSyntax syntax, RefKind refKind, int ordinal,
82FunctionPointerParameterSyntax syntax, RefKind refKind, int ordinal,
92RefKind.In => CreateInModifiers(binder, diagnostics, syntax),
93RefKind.RefReadOnlyParameter => CreateRefReadonlyParameterModifiers(binder, diagnostics, syntax),
94RefKind.Out => CreateOutModifiers(binder, diagnostics, syntax),
124Func<Binder, TOwningSymbol, TypeWithAnnotations, TParameterSyntax, RefKind, int, SyntaxToken, SyntaxToken, bool, ScopedKind, BindingDiagnosticBag, TParameterSymbol> parameterCreationFunc,
144var refKind = GetModifiers(parameterSyntax.Modifiers, out SyntaxToken refnessKeyword, out SyntaxToken paramsKeyword, out SyntaxToken thisKeyword, out ScopedKind scope);
183if (!allowRefOrOut && (refKind == RefKind.Ref || refKind == RefKind.Out))
243if (parameter.RefKind == RefKind.In)
254else if (parameter.RefKind == RefKind.RefReadOnlyParameter)
339internal static bool IsRefScopedByDefault(bool useUpdatedEscapeRules, RefKind refKind)
341return useUpdatedEscapeRules && refKind == RefKind.Out;
653RefKind refKind,
691else if (refKind != RefKind.None &&
740var refKind = GetModifiers(parameterSyntax.Modifiers, out SyntaxToken refnessKeyword, out SyntaxToken paramsKeyword, out SyntaxToken thisKeyword, out _);
746if (refKind == RefKind.Ref || refKind == RefKind.Out)
855if (refKind == RefKind.RefReadOnlyParameter)
921internal static RefKind GetModifiers(SyntaxTokenList modifiers, out SyntaxToken refnessKeyword, out SyntaxToken paramsKeyword, out SyntaxToken thisKeyword, out ScopedKind scope)
923var refKind = RefKind.None;
935if (refKind == RefKind.None)
938refKind = RefKind.Out;
942if (refKind == RefKind.None)
945refKind = RefKind.Ref;
949if (refKind == RefKind.None)
952refKind = RefKind.In;
962Debug.Assert(refKind == RefKind.None);
966if (refKind == RefKind.Ref && refnessKeyword.GetNextToken() == modifier)
968refKind = RefKind.RefReadOnlyParameter;
976scope = (refKind == RefKind.None) ? ScopedKind.ScopedValue : ScopedKind.ScopedRef;
986internal static ImmutableArray<CustomModifier> ConditionallyCreateInModifiers(RefKind refKind, bool addRefReadOnlyModifier, Binder binder, BindingDiagnosticBag diagnostics, SyntaxNode syntax)
988if (addRefReadOnlyModifier && refKind is RefKind.In or RefKind.RefReadOnlyParameter)
Symbols\Source\SourceDelegateMethodSymbol.cs (13)
27RefKind refKind,
55returnTypeSyntax = returnTypeSyntax.SkipScoped(out _).SkipRefInLocalOrReturn(diagnostics, out RefKind refKind);
217: base(delegateType, voidType, syntax, MethodKind.Constructor, RefKind.None, DeclarationModifiers.Public)
220SynthesizedParameterSymbol.Create(this, objectType, 0, RefKind.None, "object"),
221SynthesizedParameterSymbol.Create(this, intPtrType, 1, RefKind.None, "method")));
257RefKind refKind,
280if (this.RefKind == RefKind.RefReadOnly)
319if (this.RefKind == RefKind.RefReadOnly)
355: base((SourceNamedTypeSymbol)invoke.ContainingType, iAsyncResultType, syntax, MethodKind.Ordinary, RefKind.None, DeclarationModifiers.Virtual | DeclarationModifiers.Public)
365parameters.Add(SynthesizedParameterSymbol.Create(this, asyncCallbackType, paramCount, RefKind.None, GetUniqueParameterName(parameters, "callback")));
366parameters.Add(SynthesizedParameterSymbol.Create(this, objectType, paramCount + 1, RefKind.None, GetUniqueParameterName(parameters, "object")));
402if (p.RefKind != RefKind.None)
409parameters.Add(SynthesizedParameterSymbol.Create(this, iAsyncResultType, ordinal++, RefKind.None, GetUniqueParameterName(parameters, "result")));
Symbols\Source\SourceMemberContainerSymbol.cs (18)
2154var refKind1 = method1.Parameters[i].RefKind;
2155var refKind2 = method2.Parameters[i].RefKind;
3946if (methodParam.RefKind != RefKind.None)
3969methodParams[0].RefKind == RefKind.None &&
4294RefKind.Out
4296RefKind.None,
4342RefKind.None
4344RefKind.None,
4391RefKind.None)),
4392RefKind.None,
4447RefKind.None,
4526RefKind.None,
4621RefKind.None,
4652RefKind.None,
4718RefKind.None
4720RefKind.None,
4919_ = fieldSyntax.Declaration.Type.SkipScoped(out _).SkipRefInField(out var refKind);
4928var modifiers = SourceMemberFieldSymbol.MakeModifiers(this, fieldSyntax.Declaration.Variables[0].Identifier, fieldSyntax.Modifiers, isRefField: refKind != RefKind.None, diagnostics, out modifierErrors);
Symbols\Synthesized\Records\SynthesizedPrimaryConstructor.cs (1)
43RefKind.None,
Symbols\Synthesized\Records\SynthesizedRecordDeconstruct.cs (1)
41RefKind.Out,
Symbols\Synthesized\Records\SynthesizedRecordEqualityContractProperty.cs (1)
41RefKind.None,
Symbols\Synthesized\Records\SynthesizedRecordPropertySymbol.cs (1)
39RefKind.None,
Symbols\Synthesized\RefKindVector.cs (11)
39internal RefKind this[int index]
46(false, false, false) => RefKind.None,
47(false, false, true) => RefKind.Ref,
48(false, true, false) => RefKind.Out,
49(false, true, true) => RefKind.RefReadOnly,
50(true, false, false) => RefKind.RefReadOnlyParameter,
59RefKind.None => (false, false, false),
60RefKind.Ref => (false, false, true),
61RefKind.Out => (false, true, false),
62RefKind.RefReadOnly => (false, true, true),
63RefKind.RefReadOnlyParameter => (true, false, false),
Symbols\Synthesized\SynthesizedDelegateSymbol.cs (6)
21SynthesizedParameterSymbol.Create(this, TypeWithAnnotations.Create(objectType), 0, RefKind.None, "object"),
22SynthesizedParameterSymbol.Create(this, TypeWithAnnotations.Create(intPtrType), 1, RefKind.None, "method"));
35internal ParameterDescription(TypeWithAnnotations type, RefKind refKind, ScopedKind scope, ConstantValue? defaultValue, bool isParams, bool hasUnscopedRefAttribute)
46internal readonly RefKind RefKind;
59RefKind refKind)
163public override RefKind RefKind { get; }
Symbols\Synthesized\SynthesizedEntryPointSymbol.cs (10)
115public override RefKind RefKind
117get { return RefKind.None; }
300default(ImmutableArray<RefKind>),
363argumentRefKindsOpt: default(ImmutableArray<RefKind>),
411refKind: RefKind.None,
429refKind: RefKind.None,
522RefKind.None,
541TypeWithAnnotations.Create(submissionArrayType), 0, RefKind.None, "submissionArray"));
592argumentRefKindsOpt: default(ImmutableArray<RefKind>),
613RefKind.None,
InitializeParameter\CSharpInitializeMemberFromPrimaryConstructorParameterCodeRefactoringProvider.cs (1)
254RefKind.None,
GenerateType\AbstractGenerateTypeService.GenerateNamedType.cs (1)
50RefKind.None,
InitializeParameter\AbstractInitializeMemberFromParameterCodeRefactoringProviderMemberCreation.cs (1)
346RefKind.None,
src\Analyzers\Core\Analyzers\RemoveUnusedParametersAndValues\AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer.SymbolStartAnalyzer.BlockAnalyzer.cs (2)
544case RefKind.Out:
551case RefKind.Ref:
src\Analyzers\Core\CodeFixes\GenerateParameterizedMember\AbstractGenerateDeconstructMethodService.State.cs (1)
76refKind: RefKind.None,
src\Analyzers\Core\CodeFixes\GenerateParameterizedMember\AbstractGenerateMethodService.State.cs (1)
255refKind: RefKind.None,
src\Analyzers\Core\CodeFixes\GenerateVariable\AbstractGenerateVariableService.cs (8)
153document, state, generateProperty: false, isReadonly: false, isConstant: true, refKind: RefKind.None));
167document, state, generateProperty: false, isReadonly: true, isConstant: false, refKind: RefKind.None));
181document, state, generateProperty: false, isReadonly: false, isConstant: false, refKind: RefKind.None));
229parameter.RefKind is RefKind.Out ||
254private static RefKind GetRefKindFromContext(State state)
258return RefKind.Ref;
262return RefKind.RefReadOnly;
266return RefKind.None;
src\Analyzers\Core\CodeFixes\GenerateVariable\AbstractGenerateVariableService.GenerateParameterCodeAction.cs (1)
44RefKind.None,
Editing\SyntaxGenerator.cs (12)
303RefKind refKind = RefKind.None)
313RefKind refKind,
331isScoped: symbol is { RefKind: RefKind.Ref or RefKind.In or RefKind.RefReadOnlyParameter, ScopedKind: ScopedKind.ScopedRef }
332or { RefKind: RefKind.None, Type.IsRefLikeType: true, ScopedKind: ScopedKind.ScopedValue });
1931=> TypeExpression(typeSymbol, RefKind.None);
1933private protected abstract SyntaxNode TypeExpression(ITypeSymbol typeSymbol, RefKind refKind);
2234public abstract SyntaxNode Argument(string? name, RefKind refKind, SyntaxNode expression);
2239public SyntaxNode Argument(RefKind refKind, SyntaxNode expression)
2246=> Argument(name: null, RefKind.None, expression);
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\CodeGenerationSymbolFactory.cs (10)
53RefKind refKind,
84ITypeSymbol type, RefKind refKind, ImmutableArray<IPropertySymbol> explicitInterfaceImplementations, string name,
157RefKind refKind,
179RefKind refKind,
269=> CreateParameterSymbol(RefKind.None, type, name);
271public static IParameterSymbol CreateParameterSymbol(RefKind refKind, ITypeSymbol type, string name)
281ImmutableArray<AttributeData> attributes, RefKind refKind, bool isParams, ITypeSymbol type, string name, bool isOptional = false, bool hasDefaultValue = false, object? defaultValue = null)
292RefKind? refKind = null,
396refKind: RefKind.None,
468RefKind refKind,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationConstructorSymbol.cs (1)
27refKind: RefKind.None,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationConversionSymbol.cs (1)
31refKind: RefKind.None,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationDestructorSymbol.cs (1)
18refKind: RefKind.None,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationOperatorSymbol.cs (1)
32refKind: RefKind.None,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\Extensions\SyntaxGeneratorExtensions_CreateEqualsMethod.cs (1)
56refKind: RefKind.None,