Skip to content

Commit bd91edf

Browse files
ZacSweersvRallev
andauthored
Top-level contribution providers (#2057)
Co-authored-by: Ralf Wondratschek <[email protected]>
1 parent 02adceb commit bd91edf

58 files changed

Lines changed: 2766 additions & 105 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/benchmark-regression.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ jobs:
558558
# Only run on push to main, after both benchmark jobs complete
559559
if: github.event_name == 'push'
560560
needs: [benchmark, build-benchmark]
561-
runs-on: ubuntu-latest
561+
runs-on: ubuntu-slim
562562

563563
steps:
564564
- name: Checkout gh-pages

.github/workflows/benchmarks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ jobs:
8989
# Shared job to validate inputs and build modes string
9090
validate:
9191
name: "Validate inputs"
92-
runs-on: ubuntu-latest
92+
runs-on: ubuntu-slim
9393
outputs:
9494
modes: ${{ steps.modes.outputs.modes }}
9595
is_single_ref: ${{ steps.check_mode.outputs.is_single_ref }}

.github/workflows/check-kotlin-bootstrap.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ env:
1212

1313
jobs:
1414
check-versions:
15-
runs-on: ubuntu-latest
15+
runs-on: ubuntu-slim
1616
permissions:
1717
issues: write
1818

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929

3030
generate-matrix:
3131
name: "⊹ generate compiler matrix ⊹"
32-
runs-on: ubuntu-latest
32+
runs-on: ubuntu-slim
3333
outputs:
3434
matrix: ${{ steps.generate.outputs.matrix }}
3535
steps:
@@ -211,7 +211,7 @@ jobs:
211211
# https://jakewharton.com/fan-in-to-a-single-required-github-action/
212212
final-status:
213213
if: always()
214-
runs-on: ubuntu-latest
214+
runs-on: ubuntu-slim
215215
needs:
216216
- format
217217
- core

.github/workflows/ide-integration.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ concurrency:
2121
jobs:
2222
generate-matrix:
2323
name: Generate IDE matrix
24-
runs-on: ubuntu-latest
24+
runs-on: ubuntu-slim
2525
outputs:
2626
ide-matrix: ${{ steps.matrix.outputs.ide-matrix }}
2727
steps:
@@ -134,7 +134,7 @@ jobs:
134134
135135
ide-integration:
136136
if: always()
137-
runs-on: ubuntu-latest
137+
runs-on: ubuntu-slim
138138
needs:
139139
- ide-tests
140140
steps:

.github/workflows/update-ide-mappings.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ permissions:
1212

1313
jobs:
1414
update-mappings:
15-
runs-on: ubuntu-latest
15+
runs-on: ubuntu-slim
1616
timeout-minutes: 15
1717
steps:
1818
- uses: actions/checkout@v6

CHANGELOG.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,30 @@ Changelog
66

77
### New
88

9+
#### `generateContributionProviders`
10+
11+
This release introduces a new `generateContributionProviders` API (Kotlin 2.3.20+) to optimize behavior with contributed APIs.
12+
13+
Up to now, Metro's aggregation APIs (i.e. `@Contributes*` binding annotations) have worked similar to Anvil, where the ultimately just generate `@Binds` declarations as simple shorthands for the consuming graphs. This comes with the caveat that the injected class _must_ be publicly visible if it's used outside of that module.
14+
15+
Now, if you enable the new `generateContributionProviders` feature, Metro will instead generate top-level `@Provides` declarations that mirror the injected class's inputs but only return its _bound type_. This means the annotated class can remain `internal`, which both helps encapsulation and incremental compilation.
16+
17+
```
18+
interface Base
19+
20+
@ContributesBinding(AppScope::class)
21+
@Inject
22+
internal class Impl : Base
23+
24+
// Works across modules!
25+
@DependencyGraph(AppScope::class)
26+
interface AppGraph {
27+
val base: Base
28+
}
29+
```
30+
31+
The tradeoff is that `Impl` is no longer available directly on the graph. If you had any explicit code usages of `Impl`, you would have to remove those too in favor of purely the bound type.
32+
933
#### [**[MEEP-1776]**](https://github.com/ZacSweers/metro/discussions/1776) `@DefaultBinding`
1034

1135
This release introduces a new `@DefaultBinding` annotation that allows for setting a default binding on _supertypes_ of contributed classes. This is useful for common base classes with generics that would otherwise require repetitive (or error-prone) explicit `binding<T>()` declarations in subtypes.
@@ -19,6 +43,10 @@ interface BaseFactory<T : BaseFactory<T>>
1943
class HomeFactory(...) : BaseFactory<HomeFactory>
2044
```
2145

46+
### Fixes
47+
48+
- **[IR]** Consider Anvil's `rank` parameter when processing contributed binding containers.
49+
2250
### Changes
2351

2452
- Removed `@Assisted.value`. See the [docs](https://zacsweers.github.io/metro/latest/injection-types/#assisted-injection) on why in case you missed this! TL;DR, Metro matches by parameter names going forward.

compiler-tests/src/generator220/kotlin/dev/zacsweers/metro/compiler/GenerateTestsImpl.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import org.jetbrains.kotlin.generators.generateTestGroupSuiteWithJUnit5
88
inline fun <
99
reified Box,
1010
reified FastInitBox,
11+
reified ContributionProvidersBox,
1112
reified Diagnostic,
1213
reified FirDump,
1314
reified IrDump,
@@ -23,6 +24,7 @@ inline fun <
2324
}
2425
testClass<Box> { commonModel("box") }
2526
testClass<FastInitBox> { commonModel("box") }
27+
testClass<ContributionProvidersBox> { commonModel("box/aggregation") }
2628
testClass<Diagnostic> { commonModel("diagnostic") }
2729
testClass<FirDump> { commonModel("dump/fir") }
2830
testClass<IrDump> { commonModel("dump/ir") }

compiler-tests/src/generator230/kotlin/dev/zacsweers/metro/compiler/GenerateTestsImpl.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.generators.dsl.junit5.generateTestGroupSuiteWithJUni
99
inline fun <
1010
reified Box,
1111
reified FastInitBox,
12+
reified ContributionProvidersBox,
1213
reified Diagnostic,
1314
reified FirDump,
1415
reified IrDump,
@@ -24,6 +25,7 @@ inline fun <
2425
}
2526
testClass<Box> { commonModel("box") }
2627
testClass<FastInitBox> { commonModel("box") }
28+
testClass<ContributionProvidersBox> { commonModel("box/aggregation") }
2729
testClass<Diagnostic> { commonModel("diagnostic") }
2830
testClass<FirDump> { commonModel("dump/fir") }
2931
testClass<IrDump> { commonModel("dump/ir") }

compiler-tests/src/generator2320/kotlin/dev/zacsweers/metro/compiler/GenerateTestsImpl.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.generators.dsl.junit5.generateTestGroupSuiteWithJUni
99
inline fun <
1010
reified Box,
1111
reified FastInitBox,
12+
reified ContributionProvidersBox,
1213
reified Diagnostic,
1314
reified FirDump,
1415
reified IrDump,
@@ -24,6 +25,7 @@ inline fun <
2425
}
2526
testClass<Box> { commonModel("box") }
2627
testClass<FastInitBox> { commonModel("box") }
28+
testClass<ContributionProvidersBox> { commonModel("box/aggregation") }
2729
testClass<Diagnostic> { commonModel("diagnostic") }
2830
testClass<FirDump> { commonModel("dump/fir") }
2931
testClass<IrDump> { commonModel("dump/ir") }

0 commit comments

Comments
 (0)