-
Notifications
You must be signed in to change notification settings - Fork 4k
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
API proposal: represent ref
fields and scoped
parameters and locals
#61647
Comments
It feels like in order to merge the feature in a timely manner, we could reduce the set of proposed public APIs for the initial merge, perhaps to just the following:
Then in the following couple of weeks or so, we could converge on a design for how to represent |
The |
Updated proposal based on recent changes to the spec:
|
@cston is this ready for review? If so, it needs the ready-for-review label. |
API Review
|
Updated the synthesized attribute in the description (see also #62838). |
Updated syntax API based on recent discussions, and moved |
API ReviewThe shape is generally approved, swapping the namespace Microsoft.CodeAnalysis
{
public interface IFieldSymbol : ISymbol
{
/// <summary>
/// Returns the RefKind of the field.
/// </summary>
RefKind RefKind { get; }
/// <summary>
/// Custom modifiers associated with the ref modifier, or an empty array if there are none.
/// </summary>
ImmutableArray<CustomModifier> RefCustomModifiers { get; }
}
public interface ILocalSymbol : ISymbol
{
/// <summary>
/// Returns the scope kind of the local.
/// </summary>
ScopedKind ScopedKind { get; }
}
public interface IParameterSymbol : ISymbol
{
/// <summary>
/// Returns the scope kind of the parameter.
/// </summary>
ScopedKind ScopedKind { get; }
}
public enum ScopedKind
{
None,
ScopedValue,
ScopedRef,
}
}
namespace Microsoft.CodeAnalysis.CSharp
{
public enum SyntaxKind
{
/// <summary>Represents <see langword="scoped"/>.</summary>
ScopedKeyword = 8447,
}
public class SyntaxFactory
{
public static ScopedTypeSyntax ScopedType(SyntaxToken scopedKeyword, TypeSyntax type);
}
}
namespace Microsoft.CodeAnalysis.CSharp.Syntax
{
public sealed class ScopedTypeSyntax : TypeSyntax
{
public SyntaxToken ScopedKeyword { get; }
public TypeSyntax Type { get; }
public ScopedTypeSyntax Update(SyntaxToken scopedKeyword, TypeSyntax type);
public ScopedTypeSyntax WithScopedKeyword(SyntaxToken scopedKeyword);
public ScopedTypeSyntax WithType(TypeSyntax type);
}
} |
The conclusion from the follow up discussion over email:
|
API has been updated. |
This issue is referenced in source/test.
Background and Motivation
Represent
ref
modifier for fields and the relatedscoped
modifier for parameters and locals (see language proposal).ref
fields:scoped
parameters and locals:Proposed API
Symbols
Syntax
SyntaxKind.ScopedKeyword
is added.ScopedTypeSyntax
is added that combines ascoped
keyword and following type syntax.If the type following
scoped
includes aref
,ref readonly
,in
, orout
, the type is represented as a nestedRefTypeSyntax
.Metadata encoding
ScopedRefAttribute
is used by the compiler to emitscoped
modifiers to metadata.The attribute type definition is synthesized by the compiler if missing from the compilation.
Usage Examples
Using
RefTypeSyntax
is a change forParameterSyntax
which currently represents ref keywords inParameterSyntax.Modifiers
. The proposal is to useRefTypeSyntax
for ref keywords in parameters withinscoped
types only, to avoid a breaking change for C#10 syntax.For example, the parameters from
static void M(ref int x, scoped ref int y)
will be represented as:Alternative Designs
Risks
The text was updated successfully, but these errors were encountered: