Skip to content

Conversation

@yowl
Copy link
Collaborator

@yowl yowl commented Aug 20, 2025

This PR adds enough code gen to support the simple-future wit runtime test. As for the async PR, this is pretty much the minimum PR in terms of future support. I've not tackled the typed canonical methods except to add a "void" implementation which is hard coded as the one to use.

Have followed the c test cases rather than the rust ones.

Also changed Export and Import in namespaces to be uppercase and moved resources and other methods to the appropriate import or export class. Some types are still produced from the import side, and have introduced a concept of a bidirectional type (enum, flags) that sit above the import/export split.

The current codegen produced is at https://github.com/yowl/wit-bindgen-simple-future

Move export and import types to respective classes.
Capitilase import and export
Add initial future support
@yowl yowl force-pushed the csharp-future-simple branch from b14b14b to c3fce61 Compare November 30, 2025 16:05
@yowl
Copy link
Collaborator Author

yowl commented Dec 1, 2025

cc @pavelsavara @dicej @jsturtevant

@yowl yowl marked this pull request as ready for review December 1, 2025 19:06
@dicej
Copy link
Collaborator

dicej commented Dec 2, 2025

Thanks for doing this, @yowl! I'm planning to review it by the end of the week.

Copy link
Collaborator

@dicej dicej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this! Looks like a good start; please see my comments inline.

let op = &operands[0];
self.interface_gen.add_future(self.func_name);

results.push(format!("{op}.Handle"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FutureReader should probably have a TakeHandle() method that zeros out the handle field (and asserts that it wasn't already zero) before returning the original value so that the application won't accidentally try to use the no-longer-valid handle.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done this, but not sure I understand in what situation it would be used.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I meant not only that we should add a FutureReader.TakeHandle() method but that we should use it here (instead of just reading the Handle field) for the Instruction::FutureLower { .. } case.

.interface_fragments
.push(InterfaceFragment {
csharp_src: format!(r#"
public class FutureReader{future_type_name} : FutureReader
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered making FutureReader and FutureWriter generic classes rather than generating separate classes for each payload type? That's what we do in Rust and in Go, for example. Note how we use "vtable"-style structure in both Rust and Go to specialize the implementations internally. Happy to discuss further if this isn't clear.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a test that exercises the generic types with more than one concrete implementation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nevermind, I've found what I was missing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants