Skip to content
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

Store FFI value in enum, turn them into singletons #670

Merged
merged 4 commits into from
Sep 3, 2024

Conversation

Manishearth
Copy link
Contributor

It's more efficient as an integer and avoids hitting the maps on the hot paths.

This also cleans up the codegen to use an internal constructor. We should do more of this instead of generating complex code.

@Manishearth
Copy link
Contributor Author

Actually, hold on, we should construct these so that object equality works. I have an idea.

@Manishearth Manishearth changed the title Store FFI value in enum Store FFI value in enum, turn them into singletons Sep 3, 2024
@Manishearth
Copy link
Contributor Author

Sweet, fixed it so that no matter how an enum gets constructed, it always uses the same object value for the same variant

Copy link
Member

@ambiguousname ambiguousname left a comment

Choose a reason for hiding this comment

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

Looks great! Much cleaner than how enums used to be handled.

@@ -9,6 +9,7 @@ export class MyEnum {

get ffiValue() : number;


Copy link
Member

Choose a reason for hiding this comment

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

nit: Whitespace

@Manishearth Manishearth merged commit 9e91151 into rust-diplomat:main Sep 3, 2024
16 checks passed
@Manishearth Manishearth deleted the enum-discriminant branch September 3, 2024 18:54
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