bytecodealliance / bytecodealliance/wit-bindgen

C#: Tidy client facing function location

Open
#1,359 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
Rust
Stars
1.5k
Forks
286
Avg merge
6h 32m
Merged PRs (30d)
19

Description

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
```c#
// Generated by `wit-bindgen` 0.43.0. DO NOT EDIT!
//
#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

```c#
// Generated by `wit-bindgen` 0.44.0. DO NOT EDIT!
//
#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?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.