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

Generate Poko function declarations in FIR #465

Merged
merged 12 commits into from
Jan 15, 2025

Conversation

drewhamilton
Copy link
Owner

@drewhamilton drewhamilton commented Jan 11, 2025

Previously, we only modified code at the IR layer; finding the Any.equals, Any.hashCode, and Any.toString functions, modifying their dispatch receiver to the Poko class and generating the body. With this change, when K2 is enabled, we instead generate these function declarations for each Poko class in FIR, and then (still) fill in the body in IR. This should make it possible for theoretical FIR-based linters to recognize that Poko classes have implemented these functions.

This new approach is hidden behind an experimental flag, poko.experimental.enableFirDeclarationGeneration, and is disabled by default. It should not be used in production yet.

Incidentally, this diverges from data classes, which do not declare these functions in FIR. I'm not sure if this is an intentional choice or just a holdover from pre-FIR days. Data classes declare these functions in FIR in a more complicated way than this in order to account for various possibilities in the superclass, like final overrides and expect/actual delarations. We'll have to mimic the resulting behavior before promoting this to default-enabled.

@drewhamilton drewhamilton force-pushed the drew/fir-generated-poko-functions branch from 205f21f to a25f117 Compare January 14, 2025 23:31
@drewhamilton drewhamilton marked this pull request as ready for review January 14, 2025 23:36
@drewhamilton drewhamilton merged commit 76328a5 into main Jan 15, 2025
9 checks passed
@drewhamilton drewhamilton deleted the drew/fir-generated-poko-functions branch January 15, 2025 03:27
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.

1 participant