Skip to content

C#: Generated code contains compilation errors (+ lots of other opinionated problems) #1265

@just-ero

Description

@just-ero

Hello. I've used https://github.com/bytecodealliance/componentize-dotnet for the first time today. I ended up incredibly disappointed.

The main problem is a generated file containing some Result-related definitions. In the code, two ArgumentExceptions are thrown. There is no reference to the System namespace, such that compiling the library results in error CS0246: The type or namespace name 'ArgumentException' could not be found.


I have multiple other things I would like to address and discuss. Please let me know if I should take this somewhere else.

  1. Naming.
    • The generated code contains namespaces with parts which are all lowercase. This is unacceptable in C# and actually results in errors in all of my codebases.
    • The generated namespaces use the target world's name (world foo -> namespace FooWorld). This means it does not use the containing library's root namespace. This, along with generating FooWorld.wit.imports.sample.pkg, takes a lot of control out of the user's hands. I do not want the code to be generated in these namespaces.
  2. Types and declarations.
    • In simple examples, Result<TOk, TErr> and None (as well as IFooWorld and FooWorld) are not used at all. Why are these generated in those cases?
    • Why is Result<TOk, TErr>.Tags generated? The constants (if required at all) can be declared at the class level in Result<TOk, TErr>.
    • Why are these all declared as public? I do not want these types to be part of my library. A consumer of my library should never know about internal implementation details. Can I configure this?
      I may even want to wrap the generated imports and exports further. Everything being public is a nuisance for this purpose.
  3. DllImport module and entry point name.
    • My host app does not export functions in sample:pkg/foo, but instead in env. The generated code always uses [DllImport("sample:pkg/foo", ...), ...]. Can I configure this?
    • My host app does not export functions as kebab-case, but snake_case. The generated code always uses kebab-case. Can I configure this?
  4. This should be a source generator.
    • The fact that this is a separate software from componentize-dotnet is a huge problem for this point. An incremental source generator using additional files provided by the user would be much more convenient to use. The code would be generated while the user types, not upon executing a build. This would require the bindings generation to be done completely in C#, but is a lot more pleasant to use.

Metadata

Metadata

Assignees

No one assigned

    Labels

    gen-c#Related to the C# code generator

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions