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

Cache static method group conversions #6502

Closed
wants to merge 11 commits into from

Conversation

pawchen
Copy link
Contributor

@pawchen pawchen commented Nov 1, 2015

This is an early implementation for #5835, not request for review/merge right now, but want CI runs. If someone is interested comment is welcomed.

The cache strategy is generating two nested static classes to provide generic variations. Consider the following code:

class I<T> { }

class C0<K>
{
    class C1
    {
        class C2<V>
        {
            public static void Target<A, B>( A a, I<B> b ) { }
        }

        delegate void D1<C, D>( I<C> c, I<D> d );
        void Invoke<X, Y>( D1<Y, X> d ) { }

        void Test<P>( string[] args )
        {
            Invoke<K, P>(C2<int>.Target);
            // define class Target_TargetFrame<T0=C0.K=?, T1=C2.V=?, T2=Target.A=?, T3=Target.B=?>
            // because converting from: C0<K=K>.C1.C2<V=int>.Target<A=I<T=Test.P>, B=C0.K>
            // So construct Target_TargetFrame<T0=C0.K, T1=int, T2=I<T=Test.P>, T3=C0.K>
            // define class Target_TargetFrame<,,,>.D1_DelegateFrame<T4=D1.C, T5=D1.D>
            // because converting to: D1<C=Test.P, D=C0.K>
            // So construct Target_TargetFrame<,,,>.D1_DelegateFrame<T4=Test.P, T5=C0.K>
            // Now we get Target_TargetFrame<K, int, I<P>, K>.D1_DelegateFrame<P, K>.DelegateField
            // as the field to store the cached instance
        }

        [CompilerGenerated]
        static class Target_TargetFrame<T0, T1, T2, T3>
        {
            public static class D1_DelegateFrame<T4, T5>
            {
                public static D1<T4, T5> DelegateField;
            }
        }
    }
}

Known issue and questions:

  1. EnC may not work, I'm not sure here, but EnC.NoPIAReferences fails right now.
  2. [working on it] Currently the generated frame may not be in an optimal location, just within the ContainingType of CurrentMethod, maybe is a good to just define the inner frame having only 1 type parameter(or remove the inner frame, just define another type parameter for the outer frame) and have that constructed for the whole delegate type, so the outer frame can move up to the top and can be shared by multiple types?
  3. Is it ok for ExpressionEvaluator to not use this? Currently not.
  4. Concurrent issues? And notice the changed behavior on LockDelegate
  5. Need a good way to GeneratedNames

@pawchen
Copy link
Contributor Author

pawchen commented Nov 4, 2015

Worked out the top level classes in this, closing this. Will create another PR when VB part done.

@pawchen pawchen closed this Nov 4, 2015
@pawchen pawchen deleted the CacheStaticMethodGroupConversion branch November 4, 2015 18:17
@davkean davkean added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Dec 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-already-signed Community The pull request was submitted by a contributor who is not a Microsoft employee.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants