anvil icon indicating copy to clipboard operation
anvil copied to clipboard

Restructure binding module code gen

Open ZacSweers opened this issue 1 year ago • 0 comments

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!


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

ZacSweers avatar Feb 16 '24 18:02 ZacSweers