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

Drop (empty) unused structs #107

Closed
franziskuskiefer opened this issue Dec 7, 2024 · 2 comments · Fixed by FStarLang/karamel#506
Closed

Drop (empty) unused structs #107

franziskuskiefer opened this issue Dec 7, 2024 · 2 comments · Fixed by FStarLang/karamel#506

Comments

@franziskuskiefer
Copy link
Collaborator

Eurydice shouldn't produce empty structs, especially when they are not actually used.
In Rust we sometimes need structs to attach functions while they don't actually do anything.
While the generated code is correct, the struct in the following example should not be generated (dropped).

struct MyStruct {}

trait Fun {
    fn f() -> u8;
}

impl Fun for MyStruct {
    fn f() -> u8 {
        5
    }
}

fn generic_fun<F: Fun>() -> u8 {
    F::f()
}

The following struct won't compile (in most cases) and is not needed.

typedef struct eurydice_tests_MyStruct_s {  } eurydice_tests_MyStruct;
@msprotz
Copy link
Contributor

msprotz commented Dec 9, 2024

What behavior would you like? I can probably rather easily replace the struct with a unit, which would then allow unused parameter elimination, etc.

@franziskuskiefer
Copy link
Collaborator Author

I want compiling C code 😉 So I think it's either a unit as you suggest, or treating them specially to drop them. I actually thought that the phase that removes unused code would also cover structs. But maybe it doesn't?
But a unit sounds reasonable and should work.

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 a pull request may close this issue.

2 participants