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

Implement support for captured Primary Constructor parameters in EE when portable PDB is used. #67266

Merged
merged 2 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,10 @@ public static IReadOnlyDictionary<ParameterSymbol, FieldSymbol> GetCapturedParam

foreach (var parameter in captured)
{
// https://github.com/dotnet/roslyn/issues/67103: Figure out naming strategy
// Some thoughts/recommendations from Tomas:
// We should define GeneratedNameKind entry (e..g P looks free to use) and add a helper to GeneratedNames that produces the name.
// I'd also just keep the name as short as possible to avoid unnecessary metadata bloat. Could be just <name>P.
string name = "<" + parameter.Name + ">PC__BackingField";
result.Add(parameter, new SynthesizedPrimaryConstructorParameterBackingFieldSymbol(parameter, name, isReadOnly: containingType.IsReadOnly));
result.Add(parameter,
new SynthesizedPrimaryConstructorParameterBackingFieldSymbol(parameter,
GeneratedNames.MakePrimaryConstructorParameterFieldName(parameter.Name),
isReadOnly: containingType.IsReadOnly));
}

captured.Free();
Expand Down
3 changes: 2 additions & 1 deletion src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,8 @@ private static MethodBody GenerateMethodBody(
stateMachineAwaiterSlots,
StateMachineStatesDebugInfo.Create(variableSlotAllocatorOpt, stateMachineStateDebugInfos),
moveNextBodyDebugInfoOpt,
codeCoverageSpans);
codeCoverageSpans,
isPrimaryConstructor: method is SynthesizedPrimaryConstructor);
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ internal enum GeneratedNameKind
AsyncBuilderField = 't',
DelegateCacheContainerType = 'O',
DynamicCallSiteContainerType = 'o',
PrimaryConstructorParameter = 'P',
DynamicCallSiteField = 'p',
AsyncIteratorPromiseOfValueOrEndBackingField = 'v',
DisposeModeField = 'w',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -173,6 +174,21 @@ internal static bool TryParseAnonymousTypeParameterName(string typeParameterName
return false;
}

internal static bool TryParsePrimaryConstructorParameterFieldName(string fieldName, [NotNullWhen(true)] out string? parameterName)
{
Debug.Assert((char)GeneratedNameKind.PrimaryConstructorParameter == 'P');

if (fieldName.StartsWith("<", StringComparison.Ordinal) &&
fieldName.EndsWith(">P", StringComparison.Ordinal))
{
parameterName = fieldName.Substring(1, fieldName.Length - 3);
return true;
}

parameterName = null;
return false;
}

private const int sha256LengthBytes = 32;
private const int sha256LengthHexChars = sha256LengthBytes * 2;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ internal static string MakeBackingFieldName(string propertyName)
return "<" + propertyName + ">k__BackingField";
}

internal static string MakePrimaryConstructorParameterFieldName(string parameterName)
{
Debug.Assert((char)GeneratedNameKind.PrimaryConstructorParameter == 'P');
return "<" + parameterName + ">P";
}

internal static string MakeIteratorFinallyMethodName(StateMachineState finalizeState)
{
Debug.Assert((int)finalizeState < -2);
Expand Down
Loading