bytecodealliance / wit-bindgen

A language binding generator for WebAssembly interface types
Apache License 2.0
997 stars 190 forks source link

C#: Consider changing `List` parameters to e.g. `IEnumerable` #1013

Open dicej opened 2 months ago

dicej commented 2 months ago

Per https://github.com/dotnet/runtimelab/pull/2614#discussion_r1699995101, List parameters are often unnecessarily restrictive -- callers might want to pass collections of other types without converting them to Lists first.

pavelsavara commented 2 months ago

note that IEnumerable doesn't have Count/Length but you will likely need to know it upfront to allocate for marshaling. So maybe other interfaces I mentioned would be better fit. Or you could even generate multiple signatures.

pavelsavara commented 2 months ago

I don't know if we also marshal arrays of structs and primitive types (not resources), but in such case Span<T> and ReadOnlySpan<T> are better choices. Because those could live on stack. It would also help with stream APIs