Skip to content
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

Fix false positives in cycle detection with child scopes. #398

Merged
merged 1 commit into from
Oct 18, 2023

Conversation

JacobOaks
Copy link
Contributor

@JacobOaks JacobOaks commented Oct 18, 2023

Currently, cycle detection works by assigning each constructor node an "order"/index for the scope it was given in. If a path exists between an index and itself, a cycle is detected.

When we create a subscope, we copy all of the parent's nodes to the child scope, but we do not copy their orders. This causes all root scope constructors to effectively have order 0 in the child scope (zero value for a mapping to int). This causes false positives when doing cycle detection as an edge from order 0 to order 0 gets detected.

This PR fixes this bug by copying the order for constructor nodes from parent to child scope when a child scope is created.

The added test case fails before this PR, passes with it.

Ref: #397

Currently, cycle detection works by assigning each constructor node
an "order"/index for the scope it was given in. If an edge exists
between an index and itself, a cycle is detected.

When we create a subscope, we copy all of the parent's nodes
to the child scope, but we do not copy their orders.
This causes all root scope constructors to effectively have
order 0 in the child scope (zero value for a mapping to int).
This causes false positives when doing cycle detection
as an edge from order 0 to order 0 gets detected.

This PR fixes this bug by copying the order for constructor nodes
from parent to child scope when a child scope is created.

The added test case fails before this PR, passes with it.

Ref: uber-go#397
@JacobOaks JacobOaks marked this pull request as ready for review October 18, 2023 14:42
@codecov
Copy link

codecov bot commented Oct 18, 2023

Codecov Report

Merging #398 (f5533e4) into master (119025f) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #398   +/-   ##
=======================================
  Coverage   98.40%   98.40%           
=======================================
  Files          22       22           
  Lines        1502     1505    +3     
=======================================
+ Hits         1478     1481    +3     
  Misses         15       15           
  Partials        9        9           
Files Coverage Δ
constructor.go 97.50% <100.00%> (+0.03%) ⬆️
scope.go 98.92% <100.00%> (+0.02%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@tchung1118 tchung1118 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@sywhang sywhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice.

@JacobOaks JacobOaks merged commit 69df15c into uber-go:master Oct 18, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants