Skip to content

C#: Tidy client facing function locationΒ #1359

@yowl

Description

@yowl

cc @bytecodealliance/dotnet-core
As part of the future work, I'm was trying to tidy up the location of the import and export methods. At present we have this for the import-export-same-func.wit codegen test

// Generated by `wit-bindgen` 0.43.0. DO NOT EDIT!
// <auto-generated />
#nullable enable

namespace MyWorldWorld {

    public interface IMyWorldWorld {

        static abstract void Purple();

    }

    namespace exports {
        public static class MyWorldWorld
        {

            internal static class PurpleWasmInterop
            {
                [global::System.Runtime.InteropServices.DllImportAttribute("$root", EntryPoint = "purple"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute]
                internal static extern void wasmImportPurple();
            }

            public static unsafe void Purple()
            {
                PurpleWasmInterop.wasmImportPurple();

            }

            [global::System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(EntryPoint = "purple")]
            public static unsafe void wasmExportPurple() {

                MyWorldWorldImpl.Purple();

            }
        }
    }

}

As you can see the user facting imported function is in the exports namespace, but the imported function is in the interface IMyWorldWorld. This has the advantage that they can have the same name without a conflict but is not very symmetrical or intuitive. I propose to change this to

// Generated by `wit-bindgen` 0.44.0. DO NOT EDIT!
// <auto-generated />
#nullable enable

namespace MyWorldWorld {

    public interface IMyWorldWorld {

        public interface Exports
        {
            public static unsafe void Purple()
            {
                exports.MyWorldWorldInterop.PurpleWasmInterop.wasmImportPurple();

            }

        }

        public interface Imports
        {
            static abstract void Purple();

        }

    }

    namespace exports {
        public static class MyWorldWorldInterop
        {

            internal static class PurpleWasmInterop
            {
                [global::System.Runtime.InteropServices.DllImportAttribute("$root", EntryPoint = "purple"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute]
                internal static extern void wasmImportPurple();
            }

            [global::System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(EntryPoint = "purple")]
            public static unsafe void wasmExportPurple() {

                MyWorldWorldImpl.Purple();

            }
        }
    }

}

Where both the import and export are in the interface, but separated to avoid name conflicts by nested interfaces, Imports and Exports.

Does this sound bad to anyone?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions