-
Notifications
You must be signed in to change notification settings - Fork 313
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
refactor(model): Stop implementing Comparable with DependencyReference #8697
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #8697 +/- ##
============================================
- Coverage 67.85% 67.84% -0.01%
Complexity 1165 1165
============================================
Files 244 244
Lines 7736 7735 -1
Branches 865 865
============================================
- Hits 5249 5248 -1
Misses 2128 2128
Partials 359 359
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
8d060bd
to
4569367
Compare
@@ -295,7 +295,7 @@ data class RootDependencyIndex( | |||
* Note: This is by intention no data class. Equality is tested via references and not via the values contained. | |||
*/ | |||
@JsonInclude(JsonInclude.Include.NON_DEFAULT) | |||
class DependencyReference( | |||
data class DependencyReference( |
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.
Commit message: Could you please add a permalink to the exact test case? I'm having trouble finding it.
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've also re-written the commit message as the thing with the copy()
was not exactly right.
fragment - other.fragment | ||
} | ||
} | ||
) |
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'm not sure what the original motivation for this compareTo()
implementation was... like, was the implementation more or less arbitrary, just to be able to use the class in sorted sets, or was there more to it, like and intention to sort by indices in some representation?
Maybe @oheger-bosch can chime in here to confirm that this change (by now, with the preceding changes) is uncritical?
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.
It's been a while... But as far as I remember, the purpose of the compareTo()
implementation was to have a more deterministic order in dependency graphs. During tests, it popped up that the order in which items were added to a graph builder had an impact on the resulting graphs. They were isomorphic, but not identical. By defining an ordering, the effect could be reduced, but not fully eliminated.
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.
"They were isomorphic, but not identical"
Do you remember in what way this could be problematic? Was it non-deterministic without implementing compareTo()
?
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 am not 100% sure, but I think for a given order in which the graph builder was called, the results were the same.
4569367
to
7fbfc48
Compare
@@ -302,7 +295,7 @@ data class RootDependencyIndex( | |||
* Note: This is by intention no data class. Equality is tested via references and not via the values contained. | |||
*/ | |||
@JsonInclude(JsonInclude.Include.NON_DEFAULT) | |||
class DependencyReference( | |||
data class DependencyReference( |
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.
This change makes me worry. The class comment says "This is by intention no data class. Equality is tested via references and not via the values contained." If you now have a generated equals()
implementation that checks all properties, you can get very expensive traversals over whole graphs.
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.
Hm, the tests which started failing when stopping to implement Comparable
, could it be that they asserted a bit too much? (e.g. is there maybe a fix for this possible in test code?)
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.
Another alternative could be to hold these dependency references always in lists, not sets, to avoid the equals()
calls in the first place.
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.
equals()
is called when constructing the dependency graph to match subtrees. This was the reason why this class was not a data class. I am pretty sure that this change will blow up for bigger graphs. Did you test this with a larger project?
@oheger-bosch @sschuberth given above comments, do you have any preference how the top commit should be changed to move this forward? |
Signed-off-by: Frank Viernau <[email protected]>
Improve readability, and while at it make use of the default value for scope roots in two of the calls. Signed-off-by: Frank Viernau <[email protected]>
Only sort on serialization for human readability and reproducibility. Also, remove the now unused comparator, which was used only by tests before. Signed-off-by: Frank Viernau <[email protected]>
7fbfc48
to
9ece42c
Compare
I've split-out the non-controversial commits to #8705. |
The first two test cases of `AnalyzerResultBuilder` [1] compare instances of `DependencyReference`s in their assertion. Without the `Comparable` interface implemented, these assertions fail because the equality is changed to compare whether the instances (memory locations) are the same. So, turn the `DependencyReference` into a data class to fix that. [1]: https://github.com/oss-review-toolkit/ort/blob/41b450b11c5930179016ba1a54d77e03f0c70b4c/analyzer/src/test/kotlin/AnalyzerResultBuilderTest.kt#L128-L154 Signed-off-by: Frank Viernau <[email protected]>
SortedSet
/ SortedMap
from classes which get serialized
@oheger-bosch another question which just came up to me: Do you recall why it is necessary to have tests for de-serialization and serialization? It seems that no custom serializers are at play, so normally we do no test serialization in that scenario IIUC. So, could it be an option to just drop these serialization tests from AnalyzerResultBuilderTest ? |
I don't recally exactly any more. But I think these tests have been added in the progress of migrating from the old format for dependency trees to the dependency graph format. Since this was a major rewrite, it was useful to have tests in place. |
Pull request was converted to draft
This is a single commit, based on #8705. This PR has to be merged afterwards.