Skip to content

wit/bindgen: generate named result types #335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed

Conversation

ydnar
Copy link
Collaborator

@ydnar ydnar commented Apr 18, 2025

This is a rudimentary POC to demonstrate an alternative approach to #331. It generates named Go types for any result directly used in a function.

It trades Go generic complexity for additional named type surface area. I’m not sure which is better.

Inspired by a suggestion from @Mossaka.

@ydnar ydnar requested a review from Mossaka April 18, 2025 04:39
@ydnar ydnar self-assigned this Apr 18, 2025
@ydnar ydnar force-pushed the ydnar/better-results branch from 28c0bc9 to c229183 Compare April 18, 2025 07:51
@ydnar ydnar force-pushed the ydnar/better-results branch from f3928b7 to 9a5a247 Compare April 18, 2025 08:07
Copy link
Member

@Mossaka Mossaka left a comment

Choose a reason for hiding this comment

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

I like this change personally!

// ResultTupleIncomingDatagramStreamOutgoingDatagramStreamErrorCode represents the imported result "#".
//
// result<tuple<incoming-datagram-stream, outgoing-datagram-stream>, error-code>
type ResultTupleIncomingDatagramStreamOutgoingDatagramStreamErrorCode cm.Result[TupleIncomingDatagramStreamOutgoingDatagramStreamShape, cm.Tuple[IncomingDatagramStream, OutgoingDatagramStream], ErrorCode]
Copy link
Member

Choose a reason for hiding this comment

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

oh wow this type name is brutally long.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, this isn’t great.

Comment on lines +1 to +22
// Code generated by wit-bindgen-go. DO NOT EDIT.

package streams

import (
"go.bytecodealliance.org/cm"
)

// ResultListU8StreamError represents the imported result "#".
//
// result<list<u8>, stream-error>
type ResultListU8StreamError cm.Result[cm.List[uint8], cm.List[uint8], StreamError]

// ResultU64StreamError represents the imported result "#".
//
// result<u64, stream-error>
type ResultU64StreamError cm.Result[uint64, uint64, StreamError]

// ResultStreamError represents the imported result "#".
//
// result<_, stream-error>
type ResultStreamError cm.Result[StreamError, struct{}, StreamError]
Copy link
Member

Choose a reason for hiding this comment

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

nice this will reduce the burden of spelling out the shape of the Result type everytime you use it.

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'm not sure it's better!

@ydnar
Copy link
Collaborator Author

ydnar commented May 7, 2025

Not going in this direction.

@ydnar ydnar closed this May 7, 2025
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