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 (140)
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)
386if (indexerAccess.Indexer.RefKind != RefKind.None)
404var useSetAccessor = coreValueKind == BindValueKind.Assignable && indexerAccess.Indexer.RefKind != RefKind.Ref;
413ArrayBuilder<RefKind>? refKindsBuilderOpt;
416refKindsBuilderOpt = ArrayBuilder<RefKind>.GetInstance(accessorForDefaultArguments.ParameterCount);
1033if (localSymbol.RefKind == RefKind.RefReadOnly ||
1034(localSymbol.RefKind == RefKind.None && !localSymbol.IsWritableVariable))
1042if (localSymbol.RefKind == RefKind.None)
1074if (localSymbol.RefKind == RefKind.None)
1115if (parameterSymbol.RefKind is RefKind.In or RefKind.RefReadOnlyParameter && RequiresAssignableVariable(valueKind))
1120else if (parameterSymbol.RefKind == RefKind.None && RequiresRefAssignableVariable(valueKind))
1126Debug.Assert(parameterSymbol.RefKind != RefKind.None || !RequiresRefAssignableVariable(valueKind));
1130if (parameterSymbol.RefKind == RefKind.None &&
1134Debug.Assert(backingField.RefKind == RefKind.None);
1139Debug.Assert(backingField.RefKind == RefKind.None);
1229{ RefKind: RefKind.Out, UseUpdatedEscapeRules: true } => ReturnOnlyScope,
1241{ RefKind: RefKind.None } => CurrentMethodScope,
1243{ HasUnscopedRefAttribute: true, RefKind: RefKind.Out } => ReturnOnlyScope,
1276Debug.Assert(parameterSymbol.RefKind == RefKind.None || isRefScoped || refSafeToEscape == ReturnOnlyScope);
1326if ((fieldSymbol.RefKind == RefKind.None ? RequiresAssignableVariable(valueKind) : RequiresRefAssignableVariable(valueKind)) &&
1338case RefKind.None:
1340case RefKind.Ref:
1342case RefKind.RefReadOnly:
1363case RefKind.None:
1366case RefKind.Ref:
1367case RefKind.RefReadOnly:
1466if (fieldSymbol.RefKind != RefKind.None)
1490if (fieldSymbol.RefKind != RefKind.None)
1626if (RequiresVariable(valueKind) && methodSymbol.RefKind == RefKind.None)
1641if (RequiresAssignableVariable(valueKind) && methodSymbol.RefKind == RefKind.RefReadOnly)
1672propertySymbol.RefKind == RefKind.None)
1696if (RequiresAssignableVariable(valueKind) && propertySymbol.RefKind == RefKind.RefReadOnly)
1702var requiresSet = RequiresAssignableVariable(valueKind) && propertySymbol.RefKind == RefKind.None;
1771var requiresGet = !RequiresAssignmentOnly(valueKind) || propertySymbol.RefKind != RefKind.None;
1944ImmutableArray<RefKind> argRefKindsOpt,
2033ImmutableArray<RefKind> argRefKindsOpt,
2063(param is { RefKind: not RefKind.None, Type: { } type } && type.IsRefLikeOrAllowsRefLikeType())) &&
2098ImmutableArray<RefKind> argRefKindsOpt,
2155var valid = effectiveRefKind != RefKind.None && isRefEscape ?
2191ImmutableArray<RefKind> argRefKindsOpt,
2224(param is { RefKind: not RefKind.None, Type: { } type } && type.IsRefLikeOrAllowsRefLikeType())) &&
2264ImmutableArray<RefKind> argRefKindsOpt,
2325var refKind = parameter?.RefKind ?? RefKind.None;
2330if (refKind == RefKind.None &&
2331parameter?.RefKind is RefKind.In or RefKind.RefReadOnlyParameter)
2366if (getArgument.RefKind == RefKind.Ref)
2372if (setArgument.RefKind == RefKind.Ref)
2388return new EscapeArgument(parameter: null, receiver, RefKind.None);
2391var refKind = RefKind.None;
2411ImmutableArray<RefKind> argRefKindsOpt,
2418var refKind = argRefKindsOpt.IsDefault ? RefKind.None : argRefKindsOpt[argIndex];
2421if (refKind == RefKind.Ref && mixableArguments is not null)
2441ImmutableArray<RefKind> argRefKindsOpt,
2511ImmutableArray<RefKind> argRefKindsOpt,
2566ImmutableArray<RefKind> argRefKindsOpt,
2596if (refKind != RefKind.None)
2609if (parameter.Type.IsRefLikeOrAllowsRefLikeType() && parameter.RefKind != RefKind.Out && GetParameterValEscapeLevel(parameter) is { } valEscapeLevel)
2616if (parameter.RefKind != RefKind.None && GetParameterRefEscapeLevel(parameter) is { } refEscapeLevel)
2642ImmutableArray<RefKind> argRefKindsOpt,
2685if (parameter.RefKind != RefKind.None)
2756ImmutableArray<RefKind> argRefKindsOpt,
2856ImmutableArray<RefKind> argRefKindsOpt,
2978Debug.Assert(underlyingParameter.RefKind != RefKind.Out); // Shouldn't get here for a constructor
2988public override RefKind RefKind
2992if (_underlyingParameter.RefKind is not RefKind.None and var underlyingRefKind)
2999return RefKind.None;
3004return RefKind.Ref;
3212Debug.Assert(field.RefKind == RefKind.None ? RequiresAssignableVariable(kind) : RequiresRefAssignableVariable(kind));
3409if (methodSymbol.RefKind == RefKind.None)
3431if (methodSymbol.RefKind == RefKind.None)
3492if (methodSymbol.RefKind == RefKind.None)
3519Debug.Assert(GetInlineArrayAccessEquivalentSignatureMethod(elementAccess, out _, out _).RefKind == RefKind.None);
3524ImmutableArray<RefKind> refKinds;
3527Debug.Assert(equivalentSignatureMethod.RefKind != RefKind.None);
3571conversion.Conversion.Method.RefKind == RefKind.None));
3578unaryMethod.RefKind == RefKind.None));
3585binaryMethod.RefKind == RefKind.None));
3591logicalOperator.LogicalOperator.RefKind == RefKind.None));
3598compoundMethod.RefKind == RefKind.None));
3726if (methodSymbol.RefKind == RefKind.None)
3752if (indexerSymbol.RefKind == RefKind.None)
3783if (indexerSymbol.RefKind == RefKind.None)
3809if (methodSymbol.RefKind == RefKind.None)
3840Debug.Assert(GetInlineArrayAccessEquivalentSignatureMethod(elementAccess, out _, out _).RefKind == RefKind.None);
3845ImmutableArray<RefKind> refKinds;
3848Debug.Assert(equivalentSignatureMethod.RefKind != RefKind.None);
3870if (signature.RefKind == RefKind.None)
3894if (propertySymbol.RefKind == RefKind.None)
3941conversion.Conversion.Method.RefKind == RefKind.None);
3948unaryMethod.RefKind == RefKind.None));
3955binaryMethod.RefKind == RefKind.None));
3961logicalOperator.LogicalOperator.RefKind == RefKind.None));
3968compoundMethod.RefKind == RefKind.None));
4213ImmutableArray<RefKind> refKinds;
4326ImmutableArray<RefKind> refKinds;
4526if (constructMethod is not { Parameters: [{ RefKind: RefKind.None } parameter] })
4661var accessorKind = property.RefKind == RefKind.None ? AccessorKind.Set : AccessorKind.Get;
4946ImmutableArray<RefKind> refKinds;
5100ImmutableArray<RefKind> refKinds;
5420private SignatureOnlyMethodSymbol GetInlineArrayAccessEquivalentSignatureMethod(BoundInlineArrayAccess elementAccess, out ImmutableArray<BoundExpression> arguments, out ImmutableArray<RefKind> refKinds)
5422RefKind resultRefKind;
5423RefKind parameterRefKind;
5434resultRefKind = RefKind.None;
5435parameterRefKind = RefKind.None;
5439resultRefKind = elementAccess.GetItemOrSliceHelper is WellKnownMember.System_ReadOnlySpan_T__get_Item ? RefKind.In : RefKind.Ref;
5448resultRefKind = RefKind.None;
5449parameterRefKind = elementAccess.GetItemOrSliceHelper is WellKnownMember.System_ReadOnlySpan_T__Slice_Int_Int ? RefKind.In : RefKind.Ref;
5482private SignatureOnlyMethodSymbol GetInlineArrayConversionEquivalentSignatureMethod(BoundConversion conversion, out ImmutableArray<BoundExpression> arguments, out ImmutableArray<RefKind> refKinds)
5488private SignatureOnlyMethodSymbol GetInlineArrayConversionEquivalentSignatureMethod(BoundExpression inlineArray, TypeSymbol resultType, out ImmutableArray<BoundExpression> arguments, out ImmutableArray<RefKind> refKinds)
5494RefKind parameterRefKind = resultType.OriginalDefinition.Equals(_compilation.GetWellKnownType(WellKnownType.System_ReadOnlySpan_T), TypeCompareKind.AllIgnoreOptions) ? RefKind.In : RefKind.Ref;
5509RefKind.None,
5725((BoundParameter)expression).ParameterSymbol.RefKind is not (RefKind.In or RefKind.RefReadOnlyParameter);
5731return !((CodeGenerator.IsStackLocal(local, stackLocalsOpt) && local.RefKind == RefKind.None) ||
5732(!IsAnyReadOnly(addressKind) && local.RefKind == RefKind.RefReadOnly));
5735var methodRefKind = ((BoundCall)expression).Method.RefKind;
5736return methodRefKind == RefKind.Ref ||
5737(IsAnyReadOnly(addressKind) && methodRefKind == RefKind.RefReadOnly);
5741var dupRefKind = ((BoundDup)expression).RefKind;
5742return dupRefKind == RefKind.Ref ||
5743(IsAnyReadOnly(addressKind) && dupRefKind == RefKind.RefReadOnly);
5757var lhsRefKind = assignment.Left.GetRefKind();
5758return lhsRefKind == RefKind.Ref ||
5759(IsAnyReadOnly(addressKind) && lhsRefKind is RefKind.RefReadOnly or RefKind.RefReadOnlyParameter);
5825if (field.RefKind is RefKind.Ref)
5848if (field.RefKind == RefKind.RefReadOnly)
5853Debug.Assert(field.RefKind == RefKind.None);
Binder\Binder_Expressions.cs (64)
454if (field is { IsStatic: false, RefKind: RefKind.None, ContainingSymbol: SourceMemberContainerTypeSymbol { PrimaryConstructor: { } primaryConstructor } } &&
466RefKind refKind,
1892private bool IsBadLocalOrParameterCapture(Symbol symbol, TypeSymbol type, RefKind refKind)
1894if (refKind != RefKind.None || type.IsRestrictedType())
2018if (localSymbol.RefKind == RefKind.None && type.IsRestrictedType(ignoreSpanLikeTypes: true))
2058if (parameter.RefKind != RefKind.None)
2078(parameter.RefKind != RefKind.None || parameter.Type.IsRestrictedType()) &&
2081if (parameter.RefKind != RefKind.None)
2095else if (primaryCtor is { ThisParameter.RefKind: not RefKind.None } &&
2456if (thisSymbol is not null && thisSymbol.ContainingSymbol != ContainingMemberOrLambda && thisSymbol.RefKind != RefKind.None)
3010RefKind origRefKind = argumentSyntax.RefOrOutKeyword.Kind().GetRefKind();
3014RefKind refKind = origRefKind == RefKind.None || RefMustBeObeyed(isDelegateCreation, argumentSyntax) ? origRefKind : RefKind.None;
3027if (!hadError && isDelegateCreation && origRefKind != RefKind.None && result.Arguments.Count == 1)
3034var requiredValueKind = origRefKind == RefKind.In ? BindValueKind.ReadonlyRef : BindValueKind.RefOrOut;
3046private BoundExpression BindArgumentValue(BindingDiagnosticBag diagnostics, ArgumentSyntax argumentSyntax, bool allowArglist, RefKind refKind)
3245RefKind refKind)
3253if (refKind != RefKind.None)
3263result.RefKinds.Add(RefKind.None);
3311private BoundExpression BindArgumentExpression(BindingDiagnosticBag diagnostics, ExpressionSyntax argumentExpression, RefKind refKind, bool allowArglist)
3314refKind == RefKind.None ?
3316refKind == RefKind.In ?
3367var argRefKind = analyzedArguments.RefKind(arg);
3373if (argRefKind is RefKind.None or RefKind.In &&
3374getCorrespondingParameter(in result, parameters, arg).RefKind == RefKind.RefReadOnlyParameter)
3385if (argRefKind == RefKind.Ref)
3387if (getCorrespondingParameter(in result, parameters, arg).RefKind == RefKind.In)
3397else if (argRefKind == RefKind.None &&
3398getCorrespondingParameter(in result, parameters, arg).RefKind == RefKind.RefReadOnlyParameter)
3750var argumentRefKindsBuilder = ArrayBuilder<RefKind>.GetInstance(handlerArgumentIndexes.Length);
3760RefKind refKind;
3766refKind = RefKind.None;
3844argumentRefKindsBuilder.Add(refKind == RefKind.RefReadOnlyParameter ? RefKind.In : refKind);
4938if (analyzedArguments.RefKind(i) is (RefKind.Ref or RefKind.Out))
5455ArrayBuilder<RefKind> refKinds,
5646var rhsExpr = initializer.Right.CheckAndUnwrapRefExpression(diagnostics, out RefKind refKind);
5647bool isRef = refKind == RefKind.Ref;
5764ImmutableArray<RefKind> argumentRefKindsOpt = default;
8113extensionMethodArguments.RefKinds.Add(RefKind.None);
8247RefKind returnRefKind,
8509fieldSymbol.RefKind != RefKind.None)
9471RefKind refKind = analyzedArguments.RefKind(i);
9472if (refKind != RefKind.None)
9571default(ImmutableArray<RefKind>),
9689ImmutableArray<RefKind> argumentRefKinds = analyzedArguments.RefKinds.ToImmutableOrNull();
9940original.Parameters[0] is { Type.SpecialType: SpecialType.System_Int32, RefKind: RefKind.None })
10038original.Parameters[0] is { Type.SpecialType: SpecialType.System_Int32, RefKind: RefKind.None } &&
10039original.Parameters[1] is { Type.SpecialType: SpecialType.System_Int32, RefKind: RefKind.None };
10102getMethod.RefKind == RefKind.None &&
10145RefKind returnRefKind = default,
10166RefKind returnRefKind = default,
10193RefKind returnRefKind,
10214RefKind returnRefKind = default,
10284RefKind returnRefKind = default,
10602RefKind? returnRefKindOverride = null,
10609var returnRefKind = returnRefKindOverride ?? methodSymbol.RefKind;
10629if (returnsVoid && returnRefKind != RefKind.None)
10643returnRefKind == RefKind.None &&
10645(parameterRefKinds.IsDefault || parameterRefKinds.All(refKind => refKind == RefKind.None)) &&
10679parameterRefKinds.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)
860internal BoundExpression BindInferredVariableInitializer(BindingDiagnosticBag diagnostics, RefKind refKind, EqualsValueClauseSyntax initializer,
909RefKind variableRefKind,
914RefKind expressionRefKind = RefKind.None;
916if (variableRefKind == RefKind.None)
919if (expressionRefKind == RefKind.Ref)
927valueKind = variableRefKind == RefKind.RefReadOnly
936else if (expressionRefKind != RefKind.Ref)
997if (localSymbol.RefKind != RefKind.None)
1063localSymbol.RefKind != RefKind.None ? ConversionForAssignmentFlags.RefAssignment : ConversionForAssignmentFlags.None);
1414var rhsExpr = node.Right.CheckAndUnwrapRefExpression(diagnostics, out var refKind);
1415var isRef = refKind == RefKind.Ref;
1444var lhsRefKind = boundLeft.GetRefKind();
1445if (lhsRefKind is RefKind.Ref or RefKind.Out)
2108var delegateRefKind = delegateParameters[i].RefKind;
2109if (delegateRefKind != RefKind.None)
2149var lambdaRefKind = anonymousFunction.RefKind(i);
2151var delegateRefKind = delegateParameters[i].RefKind;
2163if (delegateRefKind == RefKind.None)
2870protected virtual TypeSymbol GetCurrentReturnType(out RefKind refKind)
2887refKind = RefKind.None;
2893var refKind = RefKind.None;
2911RefKind sigRefKind;
2922if (refKind != RefKind.None)
2934else if ((object)retType != null && (refKind != RefKind.None) != (sigRefKind != RefKind.None))
2936var errorCode = refKind != RefKind.None
3034RefKind returnRefKind,
3044Debug.Assert(returnRefKind == RefKind.None);
3066if (returnRefKind != RefKind.None)
3082RefKind unusedRefKind;
3350internal BoundBlock CreateBlockFromExpression(CSharpSyntaxNode node, ImmutableArray<LocalSymbol> locals, RefKind refKind, BoundExpression expression, ExpressionSyntax expressionSyntax, BindingDiagnosticBag diagnostics)
3352RefKind returnRefKind;
3357if (IsInAsyncMethod() && refKind != RefKind.None)
3366if ((refKind != RefKind.None) != (returnRefKind != RefKind.None) && expression.Kind != BoundKind.ThrowExpression)
3368var errorCode = refKind != RefKind.None
3373statement = new BoundReturnStatement(syntax, RefKind.None, expression, @checked: CheckOverflowAtRuntime) { WasCompilerGenerated = true };
3477RefKind refKind;
3493RefKind refKind;
3506return bodyBinder.CreateBlockFromExpression(body, bodyBinder.GetDeclaredLocalsForScope(body), RefKind.None, expression, body, diagnostics);
3509private BindValueKind GetRequiredReturnValueKind(RefKind refKind)
3512if (refKind != RefKind.None)
3514GetCurrentReturnType(out var sigRefKind);
3515requiredValueKind = sigRefKind == RefKind.Ref ?
3866argumentRefKindsOpt: ImmutableArray<RefKind>.Empty,
Binder\Semantics\OverloadResolution\OverloadResolution.cs (78)
143RefKind returnRefKind = default,
191RefKind returnRefKind = default,
263RefKind returnRefKind,
725RefKind? returnRefKind,
750else if (returnRefKind == RefKind.None)
2040var type1 = getParameterTypeAndRefKind(i, m1.Result, m1LeastOverriddenParameters, m1.Result.ParamsElementTypeOpt, out RefKind parameter1RefKind);
2042var type2 = getParameterTypeAndRefKind(i, m2.Result, m2LeastOverriddenParameters, m2.Result.ParamsElementTypeOpt, out RefKind parameter2RefKind);
2434static TypeSymbol getParameterTypeAndRefKind(int i, MemberAnalysisResult result, ImmutableArray<ParameterSymbol> parameters, TypeWithAnnotations paramsElementTypeOpt, out RefKind parameter1RefKind)
2505if (p1.RefKind == RefKind.None && isAcceptableRefMismatch(p2.RefKind, isInterpolatedStringHandlerConversion))
2516else if (p2.RefKind == RefKind.None && isAcceptableRefMismatch(p1.RefKind, isInterpolatedStringHandlerConversion))
2532static bool isAcceptableRefMismatch(RefKind refKind, bool isInterpolatedStringHandlerConversion)
2535RefKind.In or RefKind.RefReadOnlyParameter => true,
2536RefKind.Ref when isInterpolatedStringHandlerConversion => true,
2712RefKind refKind1,
2715RefKind refKind2,
2740Debug.Assert(refKind1 == RefKind.None || refKind1 == RefKind.Ref);
2741Debug.Assert(refKind2 == RefKind.None || refKind2 == RefKind.Ref);
2745if (refKind1 == RefKind.None)
2754else if (refKind1 == RefKind.Ref)
3495ArrayBuilder<RefKind> argumentRefKinds,
3501out ImmutableArray<RefKind> parameterRefKinds)
3517internal readonly ImmutableArray<RefKind> ParameterRefKinds;
3520internal EffectiveParameters(ImmutableArray<TypeWithAnnotations> types, ImmutableArray<RefKind> refKinds, int firstParamsElementIndex)
3534ArrayBuilder<RefKind> argumentRefKinds,
3549ImmutableArray<RefKind> parameterRefKinds = member.GetParameterRefKinds();
3557ArrayBuilder<RefKind> refs = null;
3571RefKind argRefKind = hasAnyRefArg ? argumentRefKinds[arg] : RefKind.None;
3572RefKind paramRefKind = GetEffectiveParameterRefKind(parameter, argRefKind, options, binder, ref hasAnyRefOmittedArgument);
3576if (paramRefKind != RefKind.None)
3578refs = ArrayBuilder<RefKind>.GetInstance(arg, RefKind.None);
3588var refKinds = refs != null ? refs.ToImmutableAndFree() : default(ImmutableArray<RefKind>);
3592private static RefKind GetEffectiveParameterRefKind(
3594RefKind argRefKind,
3599var paramRefKind = parameter.RefKind;
3608if (paramRefKind == RefKind.In)
3610if (argRefKind == RefKind.None)
3612return RefKind.None;
3615if (argRefKind == RefKind.Ref && binder.Compilation.IsFeatureEnabled(MessageID.IDS_FeatureRefReadonlyParameters))
3617return RefKind.Ref;
3620else if (paramRefKind == RefKind.RefReadOnlyParameter && argRefKind is RefKind.None or RefKind.Ref or RefKind.In)
3633if ((options & Options.AllowRefOmittedArguments) != 0 && paramRefKind == RefKind.Ref && argRefKind == RefKind.None && !binder.InAttributeArgument)
3636return RefKind.None;
3645internal static bool AreRefsCompatibleForMethodConversion(RefKind candidateMethodParameterRefKind, RefKind delegateParameterRefKind, CSharpCompilation compilation)
3655(RefKind.RefReadOnlyParameter, RefKind.Ref) or
3656(RefKind.RefReadOnlyParameter, RefKind.In) or
3657(RefKind.In, RefKind.RefReadOnlyParameter))
3663(candidateMethodParameterRefKind, delegateParameterRefKind) is (RefKind.In, RefKind.Ref))
3675ArrayBuilder<RefKind> argumentRefKinds,
3686ArrayBuilder<RefKind> argumentRefKinds,
3694var refs = ArrayBuilder<RefKind>.GetInstance();
3724var argRefKind = hasAnyRefArg ? argumentRefKinds[arg] : RefKind.None;
3725var paramRefKind = GetEffectiveParameterRefKind(parameter, argRefKind, options, binder, ref hasAnyRefOmittedArgument);
3728if (paramRefKind != RefKind.None)
3734var refKinds = anyRef ? refs.ToImmutable() : default(ImmutableArray<RefKind>);
4149RefKind argumentRefKind = arguments.RefKind(argumentPosition);
4150RefKind parameterRefKind = parameters.ParameterRefKinds.IsDefault ? RefKind.None : parameters.ParameterRefKinds[argumentPosition];
4155Debug.Assert(argumentRefKind == RefKind.None);
4156if (parameterRefKind == RefKind.Ref)
4170&& parameterRefKind == RefKind.Ref
4265RefKind argRefKind,
4267RefKind parRefKind,
4303Debug.Assert(argRefKind != RefKind.None);
4309if (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))
778var returnType = DelegateReturnTypeWithAnnotations(invokeMethod, out RefKind refKind);
797refKind == CodeAnalysis.RefKind.None &&
817if (lambdaSymbol.RefKind == CodeAnalysis.RefKind.RefReadOnly)
884ImmutableArray<RefKind> parameterRefKinds,
885RefKind refKind)
899var returnType = DelegateReturnTypeWithAnnotations(invokeMethod, out RefKind refKind);
932ImmutableArray<RefKind> parameterRefKinds)
934bool hasExplicitReturnType = HasExplicitReturnType(out var refKind, out var returnType);
989ImmutableArray<RefKind> parameterRefKinds,
991RefKind refKind)
1025public readonly ImmutableArray<RefKind> ParameterRefKinds;
1028public static readonly ReturnInferenceCacheKey Empty = new ReturnInferenceCacheKey(ImmutableArray<TypeWithAnnotations>.Empty, ImmutableArray<RefKind>.Empty, null);
1030private ReturnInferenceCacheKey(ImmutableArray<TypeWithAnnotations> parameterTypes, ImmutableArray<RefKind> parameterRefKinds, NamedTypeSymbol? taskLikeReturnTypeOpt)
1091out ImmutableArray<RefKind> parameterRefKinds,
1097parameterRefKinds = ImmutableArray<RefKind>.Empty;
1106var refKindsBuilder = ArrayBuilder<RefKind>.GetInstance(parameterCount);
1182?? rebind(ReallyInferReturnType(delegateType: null, ImmutableArray<TypeWithAnnotations>.Empty, ImmutableArray<RefKind>.Empty));
1199ImmutableArray<RefKind> parameterRefKinds)
1202var refKind = inferredReturnType.RefKind;
1214refKind = CodeAnalysis.RefKind.None;
1427private readonly RefKind _returnRefKind;
1433private readonly ImmutableArray<RefKind> _parameterRefKinds;
1442RefKind returnRefKind,
1448ImmutableArray<RefKind> parameterRefKinds,
1473public override bool HasExplicitReturnType(out RefKind refKind, out TypeWithAnnotations returnType)
1532public override RefKind RefKind(int index)
1535return _parameterRefKinds.IsDefault ? Microsoft.CodeAnalysis.RefKind.None : _parameterRefKinds[index];
1570statements[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 (32)
1084VisitArguments(node.Arguments, default(ImmutableArray<RefKind>), null);
1245VisitRvalue(node.InitializerOpt, isKnownToBeAnLvalue: node.LocalSymbol.RefKind != RefKind.None);
1248if (node.LocalSymbol.RefKind != RefKind.None)
1388WriteArgument(receiverOpt, RefKind.Ref, method: null);
1394var thisRefKind = thisParameter.RefKind;
1468protected virtual void VisitArguments(ImmutableArray<BoundExpression> arguments, ImmutableArray<RefKind> refKindsOpt, MethodSymbol method)
1475private void VisitArgumentsBeforeCall(ImmutableArray<BoundExpression> arguments, ImmutableArray<RefKind> refKindsOpt)
1480RefKind refKind = GetRefKind(refKindsOpt, i);
1481if (refKind != RefKind.Out)
1483VisitRvalue(arguments[i], isKnownToBeAnLvalue: refKind != RefKind.None);
1495private void VisitArgumentsAfterCall(ImmutableArray<BoundExpression> arguments, ImmutableArray<RefKind> refKindsOpt, MethodSymbol method)
1499RefKind refKind = GetRefKind(refKindsOpt, i);
1501if (refKind != RefKind.None)
1508protected static RefKind GetRefKind(ImmutableArray<RefKind> refKindsOpt, int index)
1510return refKindsOpt.IsDefault || refKindsOpt.Length <= index ? RefKind.None : refKindsOpt[index];
1513protected virtual void WriteArgument(BoundExpression arg, RefKind refKind, MethodSymbol method)
1936VisitRvalue(node.ExpressionOpt, isKnownToBeAnLvalue: node.RefKind != RefKind.None);
1939if (node.RefKind != RefKind.None)
2049if (property.RefKind == RefKind.None)
2067var refKind = node.Left.Kind == BoundKind.BadExpression
2068? RefKind.Ref
2104if (property.RefKind == RefKind.None)
2123if (property.RefKind == RefKind.None)
2715if (property.RefKind == RefKind.None)
3212WriteArgument(operand, RefKind.Ref, method: null);
3398this.WriteArgument(operand, RefKind.Out, null); //Out because we know it will definitely be assigned.
3439VisitArguments(node.Arguments, default(ImmutableArray<RefKind>), node.Constructor);
3523VisitArguments(node.Arguments, default(ImmutableArray<RefKind>), node.AddMethod);
3529VisitArguments(node.Arguments, default(ImmutableArray<RefKind>), node.AddMethod);
3537VisitArguments(node.Arguments, default(ImmutableArray<RefKind>), method: null);
3619property.RefKind == RefKind.None)
FlowAnalysis\NullableWalker.cs (53)
1242var refKind = parameter.RefKind;
1243if (refKind != RefKind.Out && refKind != RefKind.Ref)
2333RefKind refKind,
2343if (refKind == RefKind.Ref)
2346return AreParameterAnnotationsCompatible(RefKind.None, overriddenType, overriddenAnnotations, overridingType, overridingAnnotations, forRef: true) &&
2347AreParameterAnnotationsCompatible(RefKind.Out, overriddenType, overriddenAnnotations, overridingType, overridingAnnotations);
2350if (refKind is RefKind.None or RefKind.In or RefKind.RefReadOnlyParameter)
2380if (refKind == RefKind.Out)
2785if (parameter.RefKind != RefKind.Out)
2858if (node.RefKind == RefKind.None &&
2867if (node.RefKind == RefKind.None)
6104var refKind = GetRefKind(node.ArgumentRefKindsOpt, 0);
6162ImmutableArray<RefKind> refKindsOpt = node.ArgumentRefKindsOpt;
6592protected override void VisitArguments(ImmutableArray<BoundExpression> arguments, ImmutableArray<RefKind> refKindsOpt, MethodSymbol method)
6601ImmutableArray<RefKind> refKindsOpt,
6614ImmutableArray<RefKind> refKindsOpt,
6629ImmutableArray<RefKind> refKindsOpt,
6650ImmutableArray<RefKind> refKindsOpt,
6691ImmutableArray<RefKind> refKindsOpt,
6861ImmutableArray<RefKind> refKindsOpt,
6879static void expandParamsCollection(ref ImmutableArray<BoundExpression> arguments, ref ImmutableArray<RefKind> refKindsOpt, ImmutableArray<ParameterSymbol> parametersOpt, ref ImmutableArray<int> argsToParamsOpt, ref BitVector defaultArguments)
6939var refKindsBuilder = ArrayBuilder<RefKind>.GetInstance(refKindsOpt.Length + elements.Length - 1);
6941refKindsBuilder.AddMany(RefKind.None, elements.Length);
7064ImmutableArray<RefKind> refKindsOpt,
7125private VisitResult VisitArgumentEvaluate(BoundExpression argument, RefKind refKind, FlowAnalysisAnnotations annotations)
7137private VisitResult VisitArgumentEvaluateEpilogue(BoundExpression argument, RefKind refKind, FlowAnalysisAnnotations annotations)
7143case RefKind.Ref:
7146case RefKind.None:
7147case RefKind.In:
7169case RefKind.Out:
7192RefKind refKind,
7207case RefKind.None:
7208case RefKind.In:
7246case RefKind.Ref:
7266case RefKind.Out:
7329RefKind refKind,
7342case RefKind.None:
7343case RefKind.In:
7349case RefKind.Ref:
7376case RefKind.Out:
7582ImmutableArray<RefKind> refKindsOpt)
7593RefKind refKind = GetRefKind(refKindsOpt, i);
7596if (refKind == RefKind.None)
7664ImmutableArray<RefKind> argumentRefKindsOpt,
7673var refKinds = ArrayBuilder<RefKind>.GetInstance();
7694parameterRefKinds: out ImmutableArray<RefKind> parameterRefKinds);
9933case BoundLocal { LocalSymbol.RefKind: RefKind.None }:
9934case BoundParameter { ParameterSymbol: { RefKind: RefKind.None } parameter } when
11811TypeWithAnnotations elementType = InMethodBinder.GetIteratorElementTypeFromReturnType(compilation, RefKind.None,
11851VisitArguments(node, node.ConstructorArguments, ImmutableArray<RefKind>.Empty, node.Constructor, argsToParamsOpt: node.ConstructorArgumentsToParamsOpt, defaultArguments: node.ConstructorDefaultArguments,
Generated\BoundNodes.xml.Generated.cs (37)
920public BoundDup(SyntaxNode syntax, RefKind refKind, TypeSymbol? type, bool hasErrors)
926public BoundDup(SyntaxNode syntax, RefKind refKind, TypeSymbol? type)
932public RefKind RefKind { get; }
937public BoundDup Update(RefKind refKind, TypeSymbol? type)
1445public BoundFunctionPointerInvocation(SyntaxNode syntax, BoundExpression invokedExpression, ImmutableArray<BoundExpression> arguments, ImmutableArray<RefKind> argumentRefKindsOpt, LookupResultKind resultKind, TypeSymbol type, bool hasErrors = false)
1462public ImmutableArray<RefKind> ArgumentRefKindsOpt { get; }
1468public BoundFunctionPointerInvocation Update(BoundExpression invokedExpression, ImmutableArray<BoundExpression> arguments, ImmutableArray<RefKind> argumentRefKindsOpt, LookupResultKind resultKind, TypeSymbol type)
3063public BoundArgListOperator(SyntaxNode syntax, ImmutableArray<BoundExpression> arguments, ImmutableArray<RefKind> argumentRefKindsOpt, TypeSymbol? type, bool hasErrors = false)
3075public ImmutableArray<RefKind> ArgumentRefKindsOpt { get; }
3080public BoundArgListOperator Update(ImmutableArray<BoundExpression> arguments, ImmutableArray<RefKind> argumentRefKindsOpt, TypeSymbol? type)
3569public BoundReturnStatement(SyntaxNode syntax, RefKind refKind, BoundExpression? expressionOpt, bool @checked, bool hasErrors = false)
3577public RefKind RefKind { get; }
3584public BoundReturnStatement Update(RefKind refKind, BoundExpression? expressionOpt, bool @checked)
5893public BoundDynamicInvocation(SyntaxNode syntax, ImmutableArray<string?> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, ImmutableArray<MethodSymbol> applicableMethods, BoundExpression expression, ImmutableArray<BoundExpression> arguments, TypeSymbol type, bool hasErrors = false)
5909public ImmutableArray<RefKind> ArgumentRefKindsOpt { get; }
5915public BoundDynamicInvocation Update(ImmutableArray<string?> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, ImmutableArray<MethodSymbol> applicableMethods, BoundExpression expression, ImmutableArray<BoundExpression> arguments, TypeSymbol type)
6143public 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)
6172public ImmutableArray<RefKind> ArgumentRefKindsOpt { get; }
6184public 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)
6282public BoundUnconvertedObjectCreationExpression(SyntaxNode syntax, ImmutableArray<BoundExpression> arguments, ImmutableArray<(string Name, Location Location)?> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, InitializerExpressionSyntax? initializerOpt, Binder binder, bool hasErrors = false)
6299public ImmutableArray<RefKind> ArgumentRefKindsOpt { get; }
6306public BoundUnconvertedObjectCreationExpression Update(ImmutableArray<BoundExpression> arguments, ImmutableArray<(string Name, Location Location)?> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, InitializerExpressionSyntax? initializerOpt, Binder binder)
6341public 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)
6367public override ImmutableArray<RefKind> ArgumentRefKindsOpt { get; }
6378public 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)
6621public 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)
6642public override ImmutableArray<RefKind> ArgumentRefKindsOpt { get; }
6650public BoundDynamicObjectCreationExpression Update(string name, ImmutableArray<BoundExpression> arguments, ImmutableArray<string?> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, BoundObjectInitializerExpressionBase? initializerExpressionOpt, ImmutableArray<MethodSymbol> applicableMethods, bool wasTargetTyped, TypeSymbol type)
6743public 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)
6767public ImmutableArray<RefKind> ArgumentRefKindsOpt { get; }
6778public 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)
7409public 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)
7436public ImmutableArray<RefKind> ArgumentRefKindsOpt { get; }
7446public 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)
7550public BoundDynamicIndexerAccess(SyntaxNode syntax, BoundExpression receiver, ImmutableArray<BoundExpression> arguments, ImmutableArray<string?> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, ImmutableArray<PropertySymbol> applicableIndexers, TypeSymbol type, bool hasErrors = false)
7570public ImmutableArray<RefKind> ArgumentRefKindsOpt { get; }
7576public BoundDynamicIndexerAccess Update(BoundExpression receiver, ImmutableArray<BoundExpression> arguments, ImmutableArray<string?> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, ImmutableArray<PropertySymbol> applicableIndexers, TypeSymbol type)
Lowering\LocalRewriter\LocalRewriter_Call.cs (81)
140ref ImmutableArray<RefKind> argumentRefKindsOpt,
285var thisRefKind = methodThisParameter.RefKind;
288if (thisRefKind != RefKind.None
291thisRefKind == RefKind.Ref ? Binder.AddressKind.Writeable : Binder.AddressKind.ReadOnlyStrict,
305if (argumentRefKindsOpt.IsDefault && thisRefKind != RefKind.None)
386ImmutableArray<RefKind> argRefKindsOpt = node.ArgumentRefKindsOpt;
444ImmutableArray<RefKind> argumentRefKinds,
531argumentRefKinds: default(ImmutableArray<RefKind>),
536private static bool IsSafeForReordering(BoundExpression expression, RefKind kind)
562return kind != RefKind.None;
660ImmutableArray<RefKind> argumentRefKindsOpt,
680RefKind refKind;
692refKind = rewrittenReceiver.Type.IsValueType || rewrittenReceiver.Type.Kind == SymbolKind.TypeParameter ? RefKind.Ref : RefKind.None;
698refKind = RefKind.None;
704if (refKind == RefKind.None &&
711refKind = RefKind.Ref;
880RefKind argRefKind = argumentRefKindsOpt.RefKinds(argIndex);
881RefKind paramRefKind = parameters[paramIndex].RefKind;
883local = _factory.StoreToTemp(visitedArgument, out var store, refKind: paramRefKind is RefKind.In or RefKind.RefReadOnlyParameter ? RefKind.In : argRefKind);
952var intermediateRef = _factory.Local(_factory.SynthesizedLocal(receiverType, refKind: RefKind.Ref));
1003ref ImmutableArray<RefKind> argumentRefKindsOpt,
1086ArrayBuilder<RefKind> refKinds = ArrayBuilder<RefKind>.GetInstance(parameters.Length, RefKind.None);
1156private static ImmutableArray<RefKind> GetEffectiveArgumentRefKinds(ImmutableArray<RefKind> argumentRefKindsOpt, ImmutableArray<ParameterSymbol> parameters)
1158ArrayBuilder<RefKind>? refKindsBuilder = null;
1161var paramRefKind = parameters[i].RefKind;
1162if (paramRefKind is RefKind.In or RefKind.RefReadOnlyParameter)
1164var argRefKind = argumentRefKindsOpt.IsDefault ? RefKind.None : argumentRefKindsOpt[i];
1166refKindsBuilder[i] = argRefKind == RefKind.None ? RefKind.In : RefKindExtensions.StrictIn;
1168else if (paramRefKind == RefKind.Ref)
1170var argRefKind = argumentRefKindsOpt.IsDefault ? RefKind.None : argumentRefKindsOpt[i];
1171if (argRefKind == RefKind.None)
1177refKindsBuilder[i] = RefKind.Ref;
1191static void fillRefKindsBuilder(ImmutableArray<RefKind> argumentRefKindsOpt, ImmutableArray<ParameterSymbol> parameters, [NotNull] ref ArrayBuilder<RefKind>? refKindsBuilder)
1198refKindsBuilder = ArrayBuilder<RefKind>.GetInstance(parameters.Length);
1203refKindsBuilder = ArrayBuilder<RefKind>.GetInstance(parameters.Length, fillWithValue: RefKind.None);
1244private static ImmutableArray<RefKind> GetRefKindsOrNull(ArrayBuilder<RefKind> refKinds)
1248if (refKind != RefKind.None)
1253return default(ImmutableArray<RefKind>);
1306ImmutableArray<RefKind> argumentRefKinds,
1310/* out */ ArrayBuilder<RefKind> refKinds,
1322RefKind argRefKind = argumentRefKinds.RefKinds(a);
1323RefKind paramRefKind = parameters[p].RefKind;
1331Debug.Assert(argRefKind == RefKind.None);
1347arg.rewriter.StoreArgumentToTempIfNecessary(arg.forceLambdaSpilling, arg.storesToTemps, element, RefKind.None, RefKind.None),
1364if (paramRefKind is RefKind.In or RefKind.RefReadOnlyParameter)
1366Debug.Assert(argRefKind is RefKind.None or RefKind.In or RefKind.Ref);
1367argRefKind = argRefKind == RefKind.None ? RefKind.In : RefKindExtensions.StrictIn;
1376private BoundExpression StoreArgumentToTempIfNecessary(bool forceLambdaSpilling, ArrayBuilder<BoundAssignmentOperator> storesToTemps, BoundExpression argument, RefKind argRefKind, RefKind paramRefKind)
1388refKind: paramRefKind is RefKind.In or RefKind.RefReadOnlyParameter
1389? (argRefKind == RefKind.None ? RefKind.In : RefKindExtensions.StrictIn)
1443default(ImmutableArray<RefKind>),
1603ArrayBuilder<RefKind> argsRefKindsBuilder,
1616RefKind paramRefKind = parameters[argIndex].RefKind;
1617RefKind argRefKind = argsRefKindsBuilder[argIndex];
1621if (argRefKind != RefKind.None || paramRefKind != RefKind.Ref)
1629var localRefKind = ((BoundLocal)argument).LocalSymbol.RefKind;
1630if (localRefKind == RefKind.Ref)
1636Debug.Assert(localRefKind == RefKind.None);
1648argsRefKindsBuilder[argIndex] = RefKind.Ref;
Lowering\LocalRewriter\LocalRewriter_ForEachStatement.cs (5)
621RefKind collectionTempRefKind = RefKind.None;
709private delegate BoundStatement? GetForEachStatementAsForPreamble(LocalRewriter rewriter, SyntaxNode syntax, ForEachEnumeratorInfo enumeratorInfo, ref BoundExpression rewrittenExpression, out LocalSymbol? preambleLocal, out RefKind collectionTempRefKind);
748return static (LocalRewriter rewriter, SyntaxNode syntax, ForEachEnumeratorInfo enumeratorInfo, ref BoundExpression rewrittenExpression, out LocalSymbol? preambleLocal, out RefKind collectionTempRefKind) =>
762collectionTempRefKind = 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)
307if (local.RefKind != RefKind.None)
540var sacrificialTemp = F.SynthesizedLocal(type, refKind: RefKind.Ref);
560RefKind refKind,
570BoundExpression expression = HoistExpression(array.Expression, awaitSyntaxOpt, syntaxOffset, RefKind.None, sideEffects, hoistedFields, ref needsSacrificialEvaluation);
574indices.Add(HoistExpression(index, awaitSyntaxOpt, syntaxOffset, RefKind.None, sideEffects, hoistedFields, ref needsSacrificialEvaluation));
587if (refKind != RefKind.None || field.FieldSymbol.IsReadOnly) return expr;
591if (refKind == RefKind.None)
599isFieldOfStruct ? refKind : RefKind.None, sideEffects, hoistedFields, ref needsSacrificialEvaluation);
621if (refKind != RefKind.None && refKind != RefKind.In)
623Debug.Assert(refKind is RefKindExtensions.StrictIn or RefKind.Ref or RefKind.Out);
624Debug.Assert(call.Method.RefKind != RefKind.None);
628refKind = RefKind.None;
639if (refKind != RefKind.None && refKind != RefKind.RefReadOnly)
641Debug.Assert(refKind is RefKindExtensions.StrictIn or RefKind.Ref or RefKind.In);
646refKind = RefKind.None;
655if (refKind != RefKind.None)
Lowering\SyntheticBoundNodeFactory.cs (25)
612Debug.Assert(CurrentFunction.RefKind == RefKind.None);
637RefKind refKind = RefKind.None,
677return SynthesizedParameterSymbol.Create(container, TypeWithAnnotations.Create(type), ordinal, RefKind.None, name);
800public BoundObjectCreationExpression New(MethodSymbol constructor, ImmutableArray<BoundExpression> arguments, ImmutableArray<RefKind> argumentRefKinds)
914static ImmutableArray<RefKind> getArgumentRefKinds(MethodSymbol method, bool useStrictArgumentRefKinds)
918if (!result.IsDefaultOrEmpty && (result.Contains(RefKind.RefReadOnlyParameter) ||
919(useStrictArgumentRefKinds && result.Contains(RefKind.In))))
921var builder = ArrayBuilder<RefKind>.GetInstance(result.Length);
923foreach (var refKind in result)
927RefKind.In or RefKind.RefReadOnlyParameter when useStrictArgumentRefKinds => RefKindExtensions.StrictIn,
928RefKind.RefReadOnlyParameter => RefKind.In,
940public BoundCall Call(BoundExpression? receiver, MethodSymbol method, ImmutableArray<RefKind> refKinds, ImmutableArray<BoundExpression> args)
1689RefKind refKind = RefKind.None,
1706case RefKind.Out:
1707refKind = RefKind.Ref;
1710case RefKind.In:
1719Debug.Assert(argument.GetRefKind() != RefKind.In);
1720refKind = RefKind.None;
1724case RefKind.None:
1725case RefKind.Ref:
1756isRef: 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)
2152var refKind1 = method1.Parameters[i].RefKind;
2153var refKind2 = method2.Parameters[i].RefKind;
3902if (methodParam.RefKind != RefKind.None)
3925methodParams[0].RefKind == RefKind.None &&
4250RefKind.Out
4252RefKind.None,
4298RefKind.None
4300RefKind.None,
4347RefKind.None)),
4348RefKind.None,
4403RefKind.None,
4482RefKind.None,
4575RefKind.None,
4606RefKind.None,
4672RefKind.None
4674RefKind.None,
4873_ = fieldSyntax.Declaration.Type.SkipScoped(out _).SkipRefInField(out var refKind);
4882var 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)
39RefKind.None,
Symbols\Synthesized\Records\SynthesizedRecordPropertySymbol.cs (1)
37RefKind.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,