-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
compiler: remove unused struct fields #21010
Comments
Wouldn't this mean no function that uses a struct with possibly-unused fields can be sent to code generation until all functions have been analyzed? Since a function analyzed later could use the field and thus affect the codegen of previous functions. |
That's a great point, and since it might have compiler design implications, it means it needs to be tackled earlier. |
Yeah, this isn't feasible as-is for precisely the reason silversquirl gave above. Moreover, any semantic analysis which requires resolving the type layout -- for instance, |
If we go ahead with SpexGuy's idea to make |
It would be possible to combine these two things:
in order to trade programmer effort for optimality. It would probably be a huge pain in the ass though. |
Hmm -- so for every field, you can mark it (fictional syntax) |
My point is that the unused declaration would exist potentially even outside the module that declares the struct. The struct would be declared like normal (consider the motivating use case of #20977). |
Unfortunately we cannot have a compile error for unused struct fields (#12854) since whether a field is used depends on semantic analysis (#3028). However, for structs that have automatic layout, it is legal for the compiler to remove fields that are not used. The compiler should do that automatically.
The text was updated successfully, but these errors were encountered: