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

Restructure binding module code gen #877

Merged
merged 78 commits into from
Mar 13, 2024

Conversation

ZacSweers
Copy link
Collaborator

@ZacSweers ZacSweers commented Feb 16, 2024

This PR reimplements binding module generation to perform all merging at the IR level and eliminate intermediate merged binding modules.

At a high level, this does the following

  • Updates @ContributesBinding and @ContributesMultiBinding to instead generate binding modules per-binding.
  • Each binding modules is annotated with a new @InternalBindingMarker annotation that contains a minimal amount of metadata
    • originClass - the origin class that contributed the binding
    • isMultibinding - indicates if the binding is a multibinding
    • priority - corresponds to ContributesBinding.Priority.
    • qualifierKey - the computed "qualifier key"
  • Each binding module is annotated with @ContributesTo and propagated via that infrastructure.
  • During ModuleMergerIr, these binding modules are merged and metadata read from @InternalBindingMarker to properly allow for excludes, replaces, priority, etc all work correctly.
  • Update tests for this new infrastructure, preserving as much of the existing binding module tests (unit and integration) while removing only now-irrelevant ones (i.e. ones that explicitly expect a BindingModule of the old style to always be generated).

This also functionally completes #751!


  • Update ContributesBinding and ContributesMultibinding to generate contributed binding modules
  • Update ContributesBinding and ContributesMultibinding tests for new impl
  • Aggregate contributed bindings in ModuleMergerIr + new modeling using @InternalBindingMarker
  • Finish reimplementing prioritization and replacements in ModuleMergerIr. This is a little tricky because BindingModuleMerger speaks classes but ModuleMergerIr speaks modules.
  • Update tests

@ZacSweers ZacSweers changed the title Implement module gen in ContributesBindingCodeGen Restructure binding module code gen Feb 16, 2024
@ZacSweers ZacSweers changed the title Restructure binding module code gen (WIP) Restructure binding module code gen Feb 16, 2024
Comment on lines +42 to +46
val suffix = "As" +
contribution.boundType.generateClassNameString().capitalize() +
"To" +
contribution.scope.generateClassNameString().capitalize() +
bindingModuleNameSuffix
Copy link
Member

Choose a reason for hiding this comment

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

Could we break this up with some underscores?

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 we could I was less worried about readability given this is never accessed directly by users and trying to minimize chars to avoid too-long class names

RBusarow added a commit that referenced this pull request Mar 12, 2024
If we make any changes while syncing the local state with our internal cache, that will affect the source files and PSI parsing, but it doesn't affect the state represented by the ModuleDescriptor.  In order to get things in sync, we need to return a `RetryWithAdditionalRoots`.

While doing that analysis, the compiler will also sync its own files -- which means it will delete any `.class` files that are no longer current.

See discussion here: #877 (comment)
RBusarow added a commit that referenced this pull request Mar 12, 2024
If we make any changes while syncing the local state with our internal cache, that will affect the source files and PSI parsing, but it doesn't affect the state represented by the ModuleDescriptor.  In order to get things in sync, we need to return a `RetryWithAdditionalRoots`.

While doing that analysis, the compiler will also sync its own files -- which means it will delete any `.class` files that are no longer current.

See discussion here: #877 (comment)
@ZacSweers
Copy link
Collaborator Author

@RBusarow wanna take a look at the updated 1:1 impl before I merge?

@RBusarow
Copy link
Member

@RBusarow wanna take a look at the updated 1:1 impl before I merge?

Sorry, I should have been more clear with my comment here. I have taken a look and I am happy with it.

@ZacSweers ZacSweers enabled auto-merge (squash) March 13, 2024 20:14
@ZacSweers ZacSweers mentioned this pull request Mar 13, 2024
15 tasks
@ZacSweers ZacSweers merged commit bc91949 into square:main Mar 13, 2024
17 checks passed
@ZacSweers ZacSweers deleted the z/ksp/newBindsModule branch March 13, 2024 20:47
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.

None yet

2 participants