-
Notifications
You must be signed in to change notification settings - Fork 312
Commit d53f55f
authored
fx.Annotate: Refactor and support fx.Supply (#802)
This changes how we implement fx.Annotate.
Rather than generating a constructor when fx.Annotate is called,
we now build an internal `fx.annotate` type--a more featureful
version of `fx.Annotated`.
We then intercept this `fx.annotated` type,
similar to how we intercept `fx.Annotated`,
and convert it into a constructor on-demand.
To build the constructor itself,
we rely on the `annotated.Build` method.
The Build method operates by splitting annotation into two:
- parameter annotation
- result annotation
For both pieces, we turn annotations into:
types []reflect.Type
remap func([]reflect.Value) []reflect.Value
Where `types` specifies the type of parameters/results
for the generated function,
and `remap` turns maps function arguments/results
from/to the generated function.
.--------------------.
| generated function |
| |
| +--------------+ |
args ----->| remap params | |
| +------.-------+ |
| | |
| | |
| .------v-------. |
| | original fn | |
| '------.-------' |
| | |
| | |
| +------v-------+ |
out <-----| remap output | |
| +------.-------+ |
'--------------------'
Besides providing a cleaner implementation,
this lets us implement support for fx.Annotate in fx.Supply
with a fairly small change.
Resolves #7141 parent 7406155 commit d53f55fCopy full SHA for d53f55f
File tree
Expand file treeCollapse file tree
5 files changed
+407
-236
lines changedFilter options
Expand file treeCollapse file tree
5 files changed
+407
-236
lines changed
0 commit comments