-
Notifications
You must be signed in to change notification settings - Fork 239
Add generic depdency graph implementation to smithy-utils and use it for handling topological sorting #2774
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
base: main
Are you sure you want to change the base?
Conversation
{ | ||
"type": "feature", | ||
"description": "Add a generic dependency graph to smithy-utils to be used for sorting various dependent objects, such as integrations and plugins.", | ||
"pull_requests": [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gotta update this
6740b0e
to
5eb3729
Compare
...hy-codegen-core/src/jmh/java/software/amazon/smithy/codegen/core/jmh/SmithyIntegrations.java
Show resolved
Hide resolved
...hy-codegen-core/src/jmh/java/software/amazon/smithy/codegen/core/jmh/SmithyIntegrations.java
Show resolved
Hide resolved
...degen-core/src/main/java/software/amazon/smithy/codegen/core/IntegrationTopologicalSort.java
Outdated
Show resolved
Hide resolved
smithy-utils/src/main/java/software/amazon/smithy/utils/DependencyGraph.java
Outdated
Show resolved
Hide resolved
4bd3c5b
to
0a992d7
Compare
5e7393c
to
c74510b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know there are a couple other places that use topological sorting, TopologicalShapeSort
and TopologicalIndex
at least. TopologicalIndex
requires pulling cycles out and storing them, so I don't think it can migrate to this. TopologicalShapeSort
looks like it could, though.
smithy-build/src/test/java/software/amazon/smithy/build/TimestampPlugin1.java
Show resolved
Hide resolved
remaining.add(node.toString()); | ||
} | ||
} | ||
throw new IllegalStateException( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using this detailed exception from TopologicalShapeSort
-
smithy/smithy-model/src/main/java/software/amazon/smithy/model/loader/TopologicalShapeSort.java
Line 116 in 426c1ef
public static final class CycleException extends RuntimeException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can use something like that, but I can't use that since smithy-model depends on smithy-utils, not the other way around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this isn't so simple because exceptions can't be generic. Best I can do is Set<?>
, which isn't great. But I can point people to findCycles
for better info if needed.
546aeb1
to
f794a27
Compare
This adds a generic dependency graph to smithy-utils. This is intended to be used to sort SmithyIntegrations, SmithyBuildPlugins, and anything else that needs a topological sort.
ac1ee14
to
adb6a85
Compare
This updates the SmithyIntegration sorting to use the generic DependencyGraph. It also adds some benchmarking configurations, which show a minor speed bump for highly dependent integrations and a major speed bump for highly independent integrations.
This adds the concept of dependencies to build plugins. Plugins can now declare that they must be run before or after some plugins. This uses the same dependency graph that is used by SmithyIntegration, but unlike integrations there is no concept of a "priority". This is because we may want to be able to run the plugins themselves in parallell, and such a priority would complicate that.
This changes the DependencyGraph's topological sort to throw a dedicated exception class so that it can be better handled.
This updates LoaderShapeMap to use DependencyGraph to sort shapes instead of TopologicalShapeSort. This results in some error messages changing: * There is no longer a special message for missing transitive mixins. * The message for genrically missing mixins is now applied by ApplyMixin, which has a slightly different wording and which will trigger for each mising mixin. * The error message for detected cycles will now include the entire cycle that a shape is part of, rather than just the edges that it is directly connected to.
This deprecates TopologicalShapeSort in favor of DependencyGraph. The internal implementation is left alone because it does not inherently enqueue dependencies like DependencyGraph does. This results in TopologicalShapeSort throwing a cycle exception when dependencies are missing, which is a behavior that some may rely on.
adb6a85
to
4ac8f7e
Compare
Both
|
This adds a new
DependencyGraph
to smithy-utils, intended for use in the numerous locations where we perform topological sorts.Performance-wise, it's a bit faster for dense graphs (integrations with lots of dependencies) and a bit slower for sparse graphs. In the sizes we're realistically looking at for integrations (dozens, tops) the difference is insignificant. We're talking about a microsecond or two.
Here's benchmarking output for the old integration sort:

And here's output for the new:

I also plan to add the same sort of ordering capabilities to smithy build plugins, which is why I've gone to the trouble to make this generic.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.