Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge main to features/list-patterns #55106

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
85bbf49
Merge pull request #52028 from dotnet/merges/main-to-features/caller-…
Mar 22, 2021
1ba39e2
Merge pull request #52201 from dotnet/merges/main-to-features/caller-…
Mar 28, 2021
20777d6
Merge pull request #52405 from dotnet/merges/main-to-features/caller-…
Apr 4, 2021
52f6db1
Feature: CallerArgumentExpressionAttribute (#51952)
Youssef1313 Apr 10, 2021
910cddd
Merge remote-tracking branch 'upstream/main' into HEAD
333fred May 20, 2021
6a2ed8c
Merge pull request #52551 from dotnet/merges/main-to-features/caller-…
333fred May 26, 2021
a0550f7
Merge branch 'features/caller-argument-expression' into merges/main-t…
333fred Jun 1, 2021
2290da1
Merge pull request #53776 from dotnet/merges/main-to-features/caller-…
Jun 1, 2021
3ff9727
Handle CallerArgumentExpression in attributes (#53535)
Youssef1313 Jun 1, 2021
3cdc553
Merge pull request #53902 from dotnet/merges/main-to-features/caller-…
Jun 6, 2021
c979f20
CallerArgumentExpression: Warning for self-referential (#54129)
Youssef1313 Jun 17, 2021
5f44ff6
Simplify unnecessary condition (#54133)
Youssef1313 Jun 17, 2021
51c36c1
Merge remote-tracking branch 'upstream/main' into merges/main-to-feat…
333fred Jun 25, 2021
69fff1b
Fix test failure (#54409)
Youssef1313 Jun 28, 2021
93b0c43
Merge pull request #54064 from dotnet/merges/main-to-features/caller-…
333fred Jun 28, 2021
af4b1e1
VB support for CallerArgumentExpression (#54132)
Youssef1313 Jun 29, 2021
fd2a03f
Remove unneeded prototype (#54645)
Youssef1313 Jul 7, 2021
4985da4
Emit caller argument expression parameter name in correct casing (#54…
Youssef1313 Jul 12, 2021
b688438
Make SourceClonedParameterSymbol abstract (#54355)
Youssef1313 Jul 13, 2021
c977a8f
Merge pull request #54596 from dotnet/merges/main-to-features/caller-…
333fred Jul 13, 2021
ccb6e2c
Merge main
Youssef1313 Jul 14, 2021
3f3778b
Fix conflicts
Youssef1313 Jul 14, 2021
ab3d2ad
Merge pull request #54824 from Youssef1313/merge-main
333fred Jul 14, 2021
9d30243
Add telemetry for cursor movement in rename so we can better track wh…
ryzngard Jul 16, 2021
abdfc45
Use try/catch
ryzngard Jul 17, 2021
e1de079
Merge pull request #54901 from dotnet/merges/main-to-features/caller-…
dotnet-bot Jul 18, 2021
54da5d6
Fix diagnostic suppressor unit tests
mavasani Jul 19, 2021
e72eb09
Run tests only in English locale
mavasani Jul 20, 2021
1741917
Update version of cloudcache lib we reference
CyrusNajmabadi Jul 21, 2021
9900000
Add tests that hammer the persistence layer.
CyrusNajmabadi Jul 21, 2021
8c91de0
Update comment
CyrusNajmabadi Jul 21, 2021
9117b38
Less iterations
CyrusNajmabadi Jul 21, 2021
50f593f
create loghub log factory and change default level to warning to avoi…
dibarbet Jul 23, 2021
faecd02
Get CallerArgumentExpression ready (#54839)
Youssef1313 Jul 23, 2021
c1e4ba9
Merge remote-tracking branch 'upstream/main' into updateVersion2
CyrusNajmabadi Jul 23, 2021
a267f73
Merge remote-tracking branch 'upstream/main' into merge-main
333fred Jul 23, 2021
a8d8606
Merge pull request #55071 from dibarbet/less_logs
dibarbet Jul 23, 2021
8a98645
Allow WatchHotReloadService to specify runtime apply-update capabilit…
tmat Jul 23, 2021
f27e633
Fixes #49529 - Where on CSharp Scripting Environment compiler couldn'…
ProIcons Jul 23, 2021
6f4a2a0
Rerun generator
333fred Jul 23, 2021
a2450b6
Merge pull request #55073 from 333fred/merge-main
333fred Jul 23, 2021
b371800
Merge pull request #55082 from dotnet/features/caller-argument-expres…
333fred Jul 23, 2021
a3b5d0f
Fix faulty cast in state machine rewriter (#55063)
333fred Jul 23, 2021
c58fbd5
Correctly set IsRetargetable for source assemblies (#55066)
333fred Jul 24, 2021
b60fe7f
Merge pull request #55016 from CyrusNajmabadi/updateVersion2
CyrusNajmabadi Jul 24, 2021
e52a161
Merge pull request #54890 from ryzngard/issues/cursor_move_rename
ryzngard Jul 24, 2021
64bbbc7
Merge pull request #54915 from mavasani/FixIssue38454
mavasani Jul 24, 2021
bce899d
Move CallerArgumentExpression to C# 10 (#55084)
333fred Jul 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/Language Feature Status.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ efforts behind them.
| [nameof(parameter)](https://github.com/dotnet/csharplang/issues/373) | main | [In Progress](https://github.com/dotnet/roslyn/issues/40524) | [jcouv](https://github.com/jcouv) | TBD | [jcouv](https://github.com/jcouv) |
| [Relax ordering of `ref` and `partial` modifiers](https://github.com/dotnet/csharplang/issues/946) | [ref-partial](https://github.com/dotnet/roslyn/tree/features/ref-partial) | In Progress | [alrz](https://github.com/alrz) | [gafter](https://github.com/gafter) | [jcouv](https://github.com/jcouv) |
| [Parameter null-checking](https://github.com/dotnet/csharplang/issues/2145) | [param-nullchecking](https://github.com/dotnet/roslyn/tree/features/param-nullchecking) | [In Progress](https://github.com/dotnet/roslyn/issues/36024) | [fayrose](https://github.com/fayrose) | [agocke](https://github.com/agocke) | [jaredpar](https://github.com/jaredpar) |
| [Caller expression attribute](https://github.com/dotnet/csharplang/issues/287) | [caller-argument-expression](https://github.com/dotnet/roslyn/tree/features/caller-argument-expression) | [In Progress](https://github.com/dotnet/roslyn/issues/52745) | [Youssef1313](https://github.com/Youssef1313) | [333fred](https://github.com/333fred),[AlekseyTs](https://github.com/AlekseyTs) | [jcouv](https://github.com/jcouv) |
| [Generic attributes](https://github.com/dotnet/csharplang/issues/124) | [generic-attributes](https://github.com/dotnet/roslyn/tree/features/generic-attributes) | [In Progress](https://github.com/dotnet/roslyn/issues/36285) | [AviAvni](https://github.com/AviAvni) | [agocke](https://github.com/agocke) | [mattwar](https://github.com/mattwar) |
| [Default in deconstruction](https://github.com/dotnet/roslyn/pull/25562) | [decon-default](https://github.com/dotnet/roslyn/tree/features/decon-default) | [Implemented](https://github.com/dotnet/roslyn/issues/25559) | [jcouv](https://github.com/jcouv) | [gafter](https://github.com/gafter) | [jcouv](https://github.com/jcouv) |
| [List patterns](https://github.com/dotnet/csharplang/issues/3435) | [list-patterns](https://github.com/dotnet/roslyn/tree/features/list-patterns) | [In Progress](https://github.com/dotnet/roslyn/issues/51289) | [alrz](https://github.com/alrz) | [jcouv](https://github.com/jcouv), [333fred](https://github.com/333fred) | [333fred](https://github.com/333fred) |
Expand All @@ -38,6 +37,7 @@ efforts behind them.
| [Interpolated string improvements](https://github.com/dotnet/csharplang/issues/4487) | main | [Merged into 17.0p3](https://github.com/dotnet/roslyn/issues/51499) | [333fred](https://github.com/333fred) | [AlekseyTs](https://github.com/AlekseyTs), [chsienki](https://github.com/chsienki) | [jaredpar](https://github.com/jaredpar) |
| [File-scoped namespace](https://github.com/dotnet/csharplang/issues/137) | main | [Merged into 17.0p3](https://github.com/dotnet/roslyn/issues/49000) | [RikkiGibson](https://github.com/RikkiGibson) | [jcouv](https://github.com/jcouv), [chsienki](https://github.com/chsienki) | [CyrusNajmabadi](https://github.com/CyrusNajmabadi) |
| [Parameterless struct constructors](https://github.com/dotnet/csharplang/issues/99) | [struct-ctors](https://github.com/dotnet/roslyn/tree/features/struct-ctors) | [Merged into 17.0p3](https://github.com/dotnet/roslyn/issues/51698) | [cston](https://github.com/cston) | [jcouv](https://github.com/jcouv), [333fred](https://github.com/333fred) | [jcouv](https://github.com/jouv) |
| [Caller expression attribute](https://github.com/dotnet/csharplang/issues/287) | main | [Merged into 17.0p3](https://github.com/dotnet/roslyn/issues/52745) | [Youssef1313](https://github.com/Youssef1313) | [333fred](https://github.com/333fred),[AlekseyTs](https://github.com/AlekseyTs) | [jcouv](https://github.com/jcouv) |

# VB 16.9

Expand Down
105 changes: 56 additions & 49 deletions src/Compilers/CSharp/Portable/Binder/Binder_Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ private CSharpAttributeData GetAttribute(BoundAttribute boundAttribute, BindingD
else
{
constructorArguments = GetRewrittenAttributeConstructorArguments(out constructorArgumentsSourceIndices, attributeConstructor,
constructorArgsArray, boundAttribute.ConstructorArgumentNamesOpt, (AttributeSyntax)boundAttribute.Syntax, diagnostics, ref hasErrors);
constructorArgsArray, boundAttribute.ConstructorArgumentNamesOpt, (AttributeSyntax)boundAttribute.Syntax, boundAttribute.ConstructorArgumentsToParamsOpt, diagnostics, ref hasErrors);
}

CompoundUseSiteInfo<AssemblySymbol> useSiteInfo = GetNewCompoundUseSiteInfo(diagnostics);
Expand Down Expand Up @@ -593,6 +593,7 @@ private ImmutableArray<TypedConstant> GetRewrittenAttributeConstructorArguments(
ImmutableArray<TypedConstant> constructorArgsArray,
ImmutableArray<string?> constructorArgumentNamesOpt,
AttributeSyntax syntax,
ImmutableArray<int> argumentsToParams,
BindingDiagnosticBag diagnostics,
ref bool hasErrors)
{
Expand All @@ -610,9 +611,6 @@ private ImmutableArray<TypedConstant> GetRewrittenAttributeConstructorArguments(
Debug.Assert(!hasNamedCtorArguments ||
constructorArgumentNamesOpt.Length == argumentsCount);

// index of the first named constructor argument
int firstNamedArgIndex = -1;

ImmutableArray<ParameterSymbol> parameters = attributeConstructor.Parameters;
int parameterCount = parameters.Length;

Expand Down Expand Up @@ -650,28 +648,20 @@ private ImmutableArray<TypedConstant> GetRewrittenAttributeConstructorArguments(
}
else
{
// named constructor argument

// Store the index of the first named constructor argument
if (firstNamedArgIndex == -1)
{
firstNamedArgIndex = argsConsumedCount;
}

// Current parameter must either have a matching named argument or a default value
// For the former case, argsConsumedCount must be incremented to note that we have
// consumed a named argument. For the latter case, argsConsumedCount stays same.
int matchingArgumentIndex;
reorderedArgument = GetMatchingNamedOrOptionalConstructorArgument(out matchingArgumentIndex, constructorArgsArray,
constructorArgumentNamesOpt, parameter, firstNamedArgIndex, argumentsCount, ref argsConsumedCount, syntax, diagnostics);
reorderedArgument = getMatchingNamedOrOptionalConstructorArgument(out matchingArgumentIndex, constructorArgsArray,
parameter, argumentsCount, ref argsConsumedCount, syntax, argumentsToParams, diagnostics);

sourceIndices = sourceIndices ?? CreateSourceIndicesArray(i, parameterCount);
sourceIndices[i] = matchingArgumentIndex;
}
}
else
{
reorderedArgument = GetDefaultValueArgument(parameter, syntax, diagnostics);
reorderedArgument = GetDefaultValueArgument(parameter, syntax, argumentsToParams, argumentsCount, diagnostics);
sourceIndices = sourceIndices ?? CreateSourceIndicesArray(i, parameterCount);
}

Expand All @@ -697,6 +687,36 @@ private ImmutableArray<TypedConstant> GetRewrittenAttributeConstructorArguments(

constructorArgumentsSourceIndices = sourceIndices != null ? sourceIndices.AsImmutableOrNull() : default(ImmutableArray<int>);
return reorderedArguments.AsImmutableOrNull();

// Local functions
TypedConstant getMatchingNamedOrOptionalConstructorArgument(
out int matchingArgumentIndex,
ImmutableArray<TypedConstant> constructorArgsArray,
ParameterSymbol parameter,
int argumentsCount,
ref int argsConsumedCount,
AttributeSyntax syntax,
ImmutableArray<int> argumentsToParams,
BindingDiagnosticBag diagnostics)
{
matchingArgumentIndex = argumentsToParams.IsDefaultOrEmpty
? parameter.Ordinal
: argumentsToParams.IndexOf(parameter.Ordinal);

if (matchingArgumentIndex > -1)
{
// found a matching named argument
Debug.Assert(matchingArgumentIndex < argumentsCount);

// increment argsConsumedCount
argsConsumedCount++;
return constructorArgsArray[matchingArgumentIndex];
}
else
{
return GetDefaultValueArgument(parameter, syntax, argumentsToParams, argumentsCount, diagnostics);
}
}
}

private static int[] CreateSourceIndicesArray(int paramIndex, int parameterCount)
Expand All @@ -718,36 +738,6 @@ private static int[] CreateSourceIndicesArray(int paramIndex, int parameterCount
return sourceIndices;
}

private TypedConstant GetMatchingNamedOrOptionalConstructorArgument(
out int matchingArgumentIndex,
ImmutableArray<TypedConstant> constructorArgsArray,
ImmutableArray<string?> constructorArgumentNamesOpt,
ParameterSymbol parameter,
int startIndex,
int argumentsCount,
ref int argsConsumedCount,
AttributeSyntax syntax,
BindingDiagnosticBag diagnostics)
{
int index = GetMatchingNamedConstructorArgumentIndex(parameter.Name, constructorArgumentNamesOpt, startIndex, argumentsCount);

if (index < argumentsCount)
{
// found a matching named argument
Debug.Assert(index >= startIndex);

// increment argsConsumedCount
argsConsumedCount++;
matchingArgumentIndex = index;
return constructorArgsArray[index];
}
else
{
matchingArgumentIndex = -1;
return GetDefaultValueArgument(parameter, syntax, diagnostics);
}
}

private static int GetMatchingNamedConstructorArgumentIndex(string parameterName, ImmutableArray<string?> argumentNamesOpt, int startIndex, int argumentsCount)
{
RoslynDebug.Assert(parameterName != null);
Expand Down Expand Up @@ -775,7 +765,7 @@ private static int GetMatchingNamedConstructorArgumentIndex(string parameterName
return argIndex;
}

private TypedConstant GetDefaultValueArgument(ParameterSymbol parameter, AttributeSyntax syntax, BindingDiagnosticBag diagnostics)
private TypedConstant GetDefaultValueArgument(ParameterSymbol parameter, AttributeSyntax syntax, ImmutableArray<int> argumentsToParams, int argumentsCount, BindingDiagnosticBag diagnostics)
{
var parameterType = parameter.Type;
ConstantValue? defaultConstantValue = parameter.IsOptional ? parameter.ExplicitDefaultConstantValue : ConstantValue.NotAvailable;
Expand Down Expand Up @@ -803,22 +793,32 @@ private TypedConstant GetDefaultValueArgument(ParameterSymbol parameter, Attribu
else
{
// Boxing or identity conversion:
parameterType = Compilation.GetSpecialType(SpecialType.System_Int32);
parameterType = GetSpecialType(SpecialType.System_Int32, diagnostics, syntax);
defaultValue = line;
}
}
else if (!IsEarlyAttributeBinder && parameter.IsCallerFilePath)
{
parameterType = Compilation.GetSpecialType(SpecialType.System_String);
parameterType = GetSpecialType(SpecialType.System_String, diagnostics, syntax);
kind = TypedConstantKind.Primitive;
defaultValue = syntax.SyntaxTree.GetDisplayPath(syntax.Name.Span, Compilation.Options.SourceReferenceResolver);
}
else if (!IsEarlyAttributeBinder && parameter.IsCallerMemberName && (object)((ContextualAttributeBinder)this).AttributedMember != null)
{
parameterType = Compilation.GetSpecialType(SpecialType.System_String);
parameterType = GetSpecialType(SpecialType.System_String, diagnostics, syntax);
kind = TypedConstantKind.Primitive;
defaultValue = ((ContextualAttributeBinder)this).AttributedMember.GetMemberCallerName();
}
// We check IsCallerMemberName here since the above if can be reached with AttributedMember == null, in which case,
// We shouldn't be checking CallerArgumentExpression
else if (!IsEarlyAttributeBinder && syntax.ArgumentList is not null && !parameter.IsCallerMemberName &&
getCallerArgumentArgumentIndex(parameter, argumentsToParams) is int argumentIndex && argumentIndex > -1 && argumentIndex < argumentsCount)
{
Debug.Assert(argumentsCount <= syntax.ArgumentList.Arguments.Count);
parameterType = GetSpecialType(SpecialType.System_String, diagnostics, syntax);
kind = TypedConstantKind.Primitive;
defaultValue = syntax.ArgumentList.Arguments[argumentIndex].Expression.ToString();
}
else if (defaultConstantValue == ConstantValue.NotAvailable)
{
// There is no constant value given for the parameter in source/metadata.
Expand Down Expand Up @@ -874,6 +874,13 @@ private TypedConstant GetDefaultValueArgument(ParameterSymbol parameter, Attribu
{
return new TypedConstant(parameterType, kind, defaultValue);
}

static int getCallerArgumentArgumentIndex(ParameterSymbol parameter, ImmutableArray<int> argumentsToParams)
{
return argumentsToParams.IsDefault || parameter.CallerArgumentExpressionParameterIndex == -1
? parameter.CallerArgumentExpressionParameterIndex
: argumentsToParams.IndexOf(parameter.CallerArgumentExpressionParameterIndex);
}
}

private static TypedConstant GetParamArrayArgument(ParameterSymbol parameter, ImmutableArray<TypedConstant> constructorArgsArray,
Expand Down
16 changes: 14 additions & 2 deletions src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,7 @@ internal void BindDefaultArguments(
// Params array is filled in the local rewriter
var lastIndex = expanded ? ^1 : ^0;

var argumentsCount = argumentsBuilder.Count;
// Go over missing parameters, inserting default values for optional parameters
foreach (var parameter in parameters.AsSpan()[..lastIndex])
{
Expand All @@ -1330,7 +1331,7 @@ internal void BindDefaultArguments(
Debug.Assert(parameter.IsOptional || !assertMissingParametersAreOptional);

defaultArguments[argumentsBuilder.Count] = true;
argumentsBuilder.Add(bindDefaultArgument(node, parameter, containingMember, enableCallerInfo, diagnostics));
argumentsBuilder.Add(bindDefaultArgument(node, parameter, containingMember, enableCallerInfo, diagnostics, argumentsBuilder, argumentsCount, argsToParamsOpt));

if (argumentRefKindsBuilder is { Count: > 0 })
{
Expand All @@ -1349,7 +1350,7 @@ internal void BindDefaultArguments(
argsToParamsBuilder.Free();
}

BoundExpression bindDefaultArgument(SyntaxNode syntax, ParameterSymbol parameter, Symbol containingMember, bool enableCallerInfo, BindingDiagnosticBag diagnostics)
BoundExpression bindDefaultArgument(SyntaxNode syntax, ParameterSymbol parameter, Symbol containingMember, bool enableCallerInfo, BindingDiagnosticBag diagnostics, ArrayBuilder<BoundExpression> argumentsBuilder, int argumentsCount, ImmutableArray<int> argsToParamsOpt)
{
TypeSymbol parameterType = parameter.Type;
if (Flags.Includes(BinderFlags.ParameterDefaultValue))
Expand Down Expand Up @@ -1384,6 +1385,12 @@ BoundExpression bindDefaultArgument(SyntaxNode syntax, ParameterSymbol parameter
var memberName = containingMember.GetMemberCallerName();
defaultValue = new BoundLiteral(syntax, ConstantValue.Create(memberName), Compilation.GetSpecialType(SpecialType.System_String)) { WasCompilerGenerated = true };
}
else if (callerSourceLocation is object && getArgumentIndex(parameter.CallerArgumentExpressionParameterIndex, argsToParamsOpt) is int argumentIndex &&
argumentIndex > -1 && argumentIndex < argumentsCount)
{
var argument = argumentsBuilder[argumentIndex];
defaultValue = new BoundLiteral(syntax, ConstantValue.Create(argument.Syntax.ToString()), Compilation.GetSpecialType(SpecialType.System_String)) { WasCompilerGenerated = true };
}
else if (defaultConstantValue == ConstantValue.NotAvailable)
{
// There is no constant value given for the parameter in source/metadata.
Expand Down Expand Up @@ -1437,6 +1444,11 @@ BoundExpression bindDefaultArgument(SyntaxNode syntax, ParameterSymbol parameter
}

return defaultValue;

static int getArgumentIndex(int parameterIndex, ImmutableArray<int> argsToParamsOpt)
=> argsToParamsOpt.IsDefault
? parameterIndex
: argsToParamsOpt.IndexOf(parameterIndex);
}

}
Expand Down
Loading