dotnet / runtimelab

This repo is for experimentation and exploring new ideas that may or may not make it into the main dotnet/runtime repo.
MIT License
1.4k stars 197 forks source link

Pin stage only accepts FixedStatementSyntaxes #1653

Closed SupinePandora43 closed 2 years ago

SupinePandora43 commented 2 years ago

Generally, we only pin for cases where we directly pass down the value. That’s why the Pin stage only accepts FixedStatementSyntaxes I’d honestly recommend keeping the heap allocation or at most adding a stackalloc optimization with the native marshalling APIs If that’s not high enough perf, then you’d have to file an issue or fork the generator

By @jkoritzinsky in private discord messages.

i'm thinking about implementing IMarshallingGenerator that will output:

    private static void ulConfigSetCachePath(IntPtr config, in string cache_path)
        {
            unsafe
            {
                global::UltralightNet.ULString __cache_path_gen = default;
                global::UltralightNet.ULString* __cache_path_gen_native = default;
                //
                // Pin
                //
                fixed(char* __cache_path_gen_native_pinned = cache_path)
                {
                    __cache_path_gen = new ULString() { data = (ushort*)__cache_path_gen_native_pinned, length = (nuint)cache_path.Length };
                    __cache_path_gen_native = &__cache_path_gen;
                    //
                    // Invoke
                    //
                    ulConfigSetCachePath__PInvoke__(config, __cache_path_gen_native);
                }
            }
        }
     [System.Runtime.InteropServices.DllImportAttribute("Ultralight", EntryPoint = "ulConfigSetCachePath")]
        extern private static unsafe void ulConfigSetCachePath__PInvoke__(global::System.IntPtr config, global::UltralightNet.ULString* cache_path);

So it isn't possible yet?

jkoritzinsky commented 2 years ago

cc: @AaronRobinsonMSFT this is the community request for the “pin as a side effect” issue we talked about yesterday.

AaronRobinsonMSFT commented 2 years ago

@jkoritzinsky Thanks. The only feedback I think I'd offer is whatever is pinned is required to be used as an input somewhere. The example we were discussing had the pinning as an implicit side-effect as opposed to being used in a subsequent call – like the above example.

/cc @elinor-fung