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

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

Closed
jcouv opened this issue Jan 18, 2023 · 4 comments · Fixed by #85360
Closed

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

jcouv opened this issue Jan 18, 2023 · 4 comments · Fixed by #85360
Assignees
Labels
api-approved API was approved in API review, it can be implemented area-System.Reflection.Metadata
Milestone

Comments

@jcouv
Copy link
Member

jcouv commented Jan 18, 2023

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

@jcouv jcouv added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Jan 18, 2023
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jan 18, 2023
@ghost
Copy link

ghost commented Jan 18, 2023

Tagging subscribers to this area: @dotnet/area-system-reflection-metadata
See info in area-owners.md if you want to be subscribed.

Issue Details

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

Author: jcouv
Assignees: -
Labels:

api-suggestion, area-System.Reflection.Metadata, untriaged

Milestone: -

@steveharter
Copy link
Member

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

Also exists on FieldTypeEncoder today.

@steveharter steveharter added api-ready-for-review API is ready for review, it is NOT ready for implementation and removed api-suggestion Early API idea and discussion, it is NOT ready for implementation untriaged New issue has not been triaged by the area owner labels Jan 26, 2023
@steveharter steveharter added this to the 8.0.0 milestone Jan 26, 2023
@bartonjs
Copy link
Member

bartonjs commented Mar 23, 2023

Video

Looks good as proposed.

namespace System.Reflection.Metadata.Ecma335;
public readonly partial struct SignatureTypeEncoder
{
    public void TypedReference();
}

@bartonjs bartonjs added api-approved API was approved in API review, it can be implemented and removed api-ready-for-review API is ready for review, it is NOT ready for implementation labels Mar 23, 2023
@teo-tsirpanis teo-tsirpanis self-assigned this Apr 24, 2023
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Apr 25, 2023
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label May 1, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Jun 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-approved API was approved in API review, it can be implemented area-System.Reflection.Metadata
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants