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

Implementing an task-like type with ref readonly in builder type #22273

Open
OmarTawfik opened this issue Sep 21, 2017 · 1 comment
Open

Implementing an task-like type with ref readonly in builder type #22273

OmarTawfik opened this issue Sep 21, 2017 · 1 comment
Assignees
Milestone

Comments

@OmarTawfik
Copy link
Contributor

Part of test plan #19216

@OmarTawfik OmarTawfik added Area-Compilers New Language Feature - Readonly References Readonly References Test Test failures in roslyn-CI labels Sep 21, 2017
@OmarTawfik OmarTawfik added this to the 15.5 milestone Sep 21, 2017
@jcouv jcouv self-assigned this Sep 28, 2017
@jcouv
Copy link
Member

jcouv commented Sep 29, 2017

I took a plain implementation of a task-like type builder and sprinkled ref readonly in a number of places.
In a couple of places (MyTask.GetAwaiter, MyTaskBuilder.Create, SetResult, SetException), I got errors.
But in the places with comments (see code below), I got no emit diagnostics, which I found surprising. I didn't try executing the code, since the methods have dummy implementations.

What do you think?

Tagging @cston @VSadov

        [Fact]
        public void AsyncTasklike_WithRefReadonly2()
        {
            var source = @"
using System;
using System.Runtime.CompilerServices;
class C
{
    static async MyTask<T> M<T>()
    {
        await M<T>();
        return default;
    }
}
[AsyncMethodBuilder(typeof(MyTaskBuilder<>))]
class MyTask<T>
{
    public Awaiter<T> GetAwaiter() => null;
}
class Awaiter<T> : INotifyCompletion
{
    public bool IsCompleted => true; 
    public T GetResult() => default;
    public void OnCompleted(Action completion) { } 
}
class MyTaskBuilder<T>
{
    public static MyTaskBuilder<T> Create() => null;

// ref readonly instead of ref
    public void Start<TStateMachine>(ref readonly TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine { } 
    public void SetStateMachine(IAsyncStateMachine stateMachine) { }
    public void SetResult(T result) { }
    public void SetException(Exception exception) { }

// ref readonly return
    public ref readonly MyTask<T> Task => throw null; 

// ref readonly instead of ref
    public void AwaitOnCompleted<TAwaiter, TStateMachine>(ref readonly TAwaiter awaiter, ref readonly TStateMachine stateMachine) where TAwaiter : INotifyCompletion where TStateMachine : IAsyncStateMachine { } 

// ref readonly instead of ref
    public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(ref readonly TAwaiter awaiter, ref readonly TStateMachine stateMachine) where TAwaiter : ICriticalNotifyCompletion where TStateMachine : IAsyncStateMachine { } 
}
namespace System.Runtime.CompilerServices
{
    class AsyncMethodBuilderAttribute : System.Attribute { public AsyncMethodBuilderAttribute(System.Type t) { } }
}
";
            var compilation = CreateCompilation(source, options: TestOptions.ReleaseDll);
            compilation.VerifyEmitDiagnostics();
        }

We should also test ref struct and readonly struct as task-like.

@jcouv jcouv modified the milestones: 15.5, 15.later Oct 25, 2017
@jaredpar jaredpar modified the milestones: 15.6, 15.7 Jan 4, 2018
@jcouv jcouv modified the milestones: 15.7, 15.8 Mar 20, 2018
@jcouv jcouv modified the milestones: 15.8, 15.9 Jun 30, 2018
@jcouv jcouv modified the milestones: 15.9, 16.0 Jul 7, 2018
@jcouv jcouv modified the milestones: 16.0, 16.1, 16.2 Apr 18, 2019
@jcouv jcouv modified the milestones: 16.2, 16.3, Compiler.Next Jun 25, 2019
@jaredpar jaredpar modified the milestones: Compiler.Next, Backlog Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants