JuliaIO / ProtoBuf.jl

Julia protobuf implementation
Other
205 stars 55 forks source link

Bugfix/broken submodule topological sort #242

Closed ajwittmond closed 10 months ago

ajwittmond commented 10 months ago

This is a bugfix for a subtle issue in the topological sorting of nested submodules. The issue occurs when

  1. Submodules are nested at least 2 deep
  2. A module imports a another module, traversing up 2 levels (such as mod1.a imports mod2.b)
  3. One of the modules upstream of the module that does this is named such that its name is lexographically less than the aforementioned module

This issue occurs due to the fact that when sorting submodules, the external modules are not included in the sort however they are still returned from get_upstream_dependencies! This breaks the algorithms and causes nodes with these dependencies to not be processed and instead be falsely identified as cyclical dependencies.

The result of this is that the generated files have the wrong import order, which results in undefined references.

I have added and example of this occurring to the tests.

codecov[bot] commented 10 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (97f55ed) 92.34% compared to head (0b4bd35) 92.73%. Report is 1 commits behind head on master.

:exclamation: Current head 0b4bd35 differs from pull request most recent head 272b8fd. Consider uploading reports for the commit 272b8fd to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #242 +/- ## ========================================== + Coverage 92.34% 92.73% +0.39% ========================================== Files 25 25 Lines 2807 2808 +1 ========================================== + Hits 2592 2604 +12 + Misses 215 204 -11 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

Drvi commented 10 months ago

Hey @ajwittmond, thanks so much for your contribution, and sorry for the delay with my review. This is a great catch and I really appreciate you figuring out what went wrong and how to fix it. After a bit of investigation, I think the crux of the issue is that we didn't specify the upstream dependencies for internal modules correctly (which you solved by removing the bad dependencies), I tweaked the logic to generate the right dependencies to begin with.

Could you please check if the new version still fixes the original issue you encountered? Thanks again.

ajwittmond commented 10 months ago

I have confirmed that the new changes fix the original issue and agree that passing all of the relevant dependencies to the sort as nodes is a better solution. Thank you for addressing this.