-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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]: Support ref fields in System.Reflection.Metadata.Ecma335.BlobEncoder #68309
Comments
Tagging subscribers to this area: @dotnet/area-system-reflection-metadata Issue DetailsBackground and motivationProvide methods in API ProposalProvide a namespace System.Reflection.Metadata.Ecma335
{
public readonly struct BlobEncoder
{
public FieldTypeEncoder FieldTypeEncoder();
}
public readonly struct FieldTypeEncoder
{
public BlobBuilder Builder { get; }
public FieldTypeEncoder(BlobBuilder builder);
public CustomModifiersEncoder CustomModifiers();
public SignatureTypeEncoder Type(bool isByRef = false);
}
} API Usagevar blobBuilder = new BlobBuilder();
var encoder = new BlobEncoder(blobBuilder);
var fieldEncoder = encoder.FieldTypeEncoder();
// Ref custom modifiers: modopt(object)
var customModifiersEncoder = fieldEncoder.CustomModifiers();
customModifiersEncoder.AddModifier(MetadataTokens.TypeReferenceHandle(2), isOptional: true);
// Type: int&
var typeEncoder = fieldEncoder.Type(isByRef: true);
typeEncoder.PrimitiveType(PrimitiveTypeCode.Int32); Alternative DesignsThe alternative is the existing API which requires emitting Using the existing API: var blobBuilder = new BlobBuilder();
var encoder = new BlobEncoder(blobBuilder);
// Ref custom modifiers: modopt(object)
var customModifiersEncoder = new CustomModifiersEncoder(blobBuilder);
customModifiersEncoder.AddModifier(MetadataTokens.TypeReferenceHandle(2), isOptional: true);
// Type: int&
var typeEncoder = encoder.FieldSignature();
typeEncoder.Builder.WriteByte((byte)SignatureTypeCode.ByReference);
typeEncoder.PrimitiveType(PrimitiveTypeCode.Int32); RisksNo response
|
// Ref custom modifiers: modopt(object)
var customModifiersEncoder = fieldEncoder.CustomModifiers();
customModifiersEncoder.AddModifier(MetadataTokens.TypeReferenceHandle(2), isOptional: true); Edit Nevermind. A new instance is being created rather than using the existing one in the |
Actually, in both examples an instance of The overall difference between use of the existing API and the proposed API is small. It's perhaps just a question of whether the API for emitting fields should be aligned with the existing APIs for locals and parameters. |
namespace System.Reflection.Metadata.Ecma335;
public partial readonly struct BlobEncoder
{
public FieldTypeEncoder Field();
}
public readonly struct FieldTypeEncoder
{
public BlobBuilder Builder { get; }
public FieldTypeEncoder(BlobBuilder builder);
public CustomModifiersEncoder CustomModifiers();
public SignatureTypeEncoder Type(bool isByRef = false);
public void TypedReference();
} |
I'm working on this. |
@teo-tsirpanis Please wait for @cston to confirm he doesn't already have an implementation. Work to support |
I have not implemented this. The compiler is currently using the existing API. |
Thanks @cston. @teo-tsirpanis Looking forward to the PR. |
Fixes dotnet#68309. A test case was added.
Background and motivation
Provide methods in
System.Reflection.Metadata.Ecma335.BlobEncoder
to more directly support emitting ref fields, consistent with the corresponding APIs provided for emitting ref parameters and ref locals.API Proposal
Provide a
FieldTypeEncoder
type similar toParameterTypeEncoder
andLocalVariableTypeEncoder
.API Usage
Alternative Designs
The alternative is the existing API which requires emitting
SignatureTypeCode.ByReference
and creating aCustomModifierEncoder
explicitly. The existing API is sufficient, but inconsistent with the support for ref parameters and ref locals.Using the existing API:
Risks
BlobEncoder
already includes aFieldSignature
method that returns an encoder for a field type, so having two distinct field encoder methods may be confusing.The text was updated successfully, but these errors were encountered: