Skip to content

[API Proposal]: SignatureTypeEncoder.TypedReference() #80812

Closed

Description

@jcouv

Background and motivation

The roslyn compiler made two changes:

  1. produce a warning instead of an error for pointer to managed type in unsafe context
  2. consider System.TypedReference to be managed

As a result, it is possible to emit reference to this type in new contexts. For example in a pointer type.
The natural way to do it in Microsoft.Cci.MetadataWriter.SerializeTypeReference would be to call a SignatureTypeEncoder.TypedReference() method, but that method doesn't exist.
Note that such an API exists on ReturnTypeEncoder, LocalVariableTypeEncoder, and ParameterTypeEncoder already.

Relates to dotnet/roslyn#66328

API Proposal

namespace System.Reflection.Metadata.Ecma335;
public readonly struct SignatureTypeEncoder
{
    // additional method:
    public void TypedReference()
    {
        Builder.WriteByte((byte)SignatureTypeCode.TypedReference);
    }
}

API Usage

        private void SerializeTypeReference(SignatureTypeEncoder encoder, ITypeReference typeReference)
        {
            while (true)
            {
                if (module.IsPlatformType(typeReference, PlatformType.SystemTypedReference))
                {
                    encoder.TypedReference();
                    return;
                }
                ... handle other types and recursive scenarios
        }

Alternative Designs

It is possible to call Builder.WriteByte((byte)SignatureTypeCode.TypedReference); directly. That's the workaround used by the compiler for now.

Risks

No response

Activity

  1. added
    api-suggestion
    on Jan 18, 2023
  2. ghost added
    untriaged
    on Jan 18, 2023
  3. steveharter commented on Jan 26, 2023

    @steveharter
    Contributor

    Note that such an API exists on ReturnTypeEncoder, LocalVariableTypeEncoder, and ParameterTypeEncoder already.

    Also exists on FieldTypeEncoder today.

  4. added
    api-ready-for-review
    and removed
    api-suggestion
    untriaged
    on Jan 26, 2023
  5. added this to the 8.0.0 milestone on Jan 26, 2023
  6. bartonjs commented on Mar 23, 2023

    @bartonjs
    Member

    Video

    Looks good as proposed.

    namespace System.Reflection.Metadata.Ecma335;
    public readonly partial struct SignatureTypeEncoder
    {
        public void TypedReference();
    }
  7. added
    api-approved
    and removed
    api-ready-for-review
    on Mar 23, 2023
  8. ghost added
    in-pr
    on Apr 25, 2023
  9. ghost removed
    in-pr
    on May 1, 2023
  10. ghost locked as resolved and limited conversation to collaborators on Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api-approvedarea-System.Reflection.Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions