Commit 7960e44
Refactor graph representation (uber-go#301)
This is the first PR to prepare Dig for in-graph modifications.
This PR contains several changes to allow further extensibility in the
graph representation used in Dig, and decouple reflection Type info
from the graph algorithms as much as possible.
Specifically, this PR makes the following changes:
- Add `internal/graph` package which contains Dig-agnostic graph
algorithm used for cycle detection
- Remove the somewhat duplicated embedded cycle detection logic in
Container and cycle.go
- Add `graphHolder` type in `Container` which holds all the graph nodes
and implements the graph iterator interface used for graph algorithm
in `internal/graph`.
- Add `paramGroupedSlice` as part of node in graph.
- Remove the param visitor funcs and related helpers.
- Rename `node` to `constructorNode`.
There is also a change in the way cycle error messages are displayed.
Previously, the errors looked like:
```
typeA provided by funcName (file_location.go:line_number)
depends on typeB provided by funcName (file_location.go:line_number)
depends on typeC provided by funcName (file_location.go:line_number)
... and so on
```
This error message generation depended on knowing the "edge" info
between nodes, which is the reflect.Type that connects the two
constructor nodes.
Now that the graph representation holds not only constructor nodes but
also value groups, and because graph representation does not know what
type holds the nodes together, this needs to be changed.
Now, the error messages look like:
```
func(*typeB) *typeA provided by funcName(file_location.go:line_number)
depends on func(*typeC) *typeB provided by funcName(file_location.go:line_number)
depends on func(*typeA) *typeC provided by funcName(file_location.go:line_number)
... and so on
```
(Note that the function signature is now printed instead of the type
that holds the nodes as dependencies.)
For param value groups, the error message skips over it so that the
error message doesn't look cluttered but that can be subject to change
in the future.
Co-authored-by: Abhinav Gupta <[email protected]>1 parent 173b7b1 commit 7960e44
File tree
13 files changed
+806
-480
lines changed- internal/graph
13 files changed
+806
-480
lines changedThis file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
0 commit comments