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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect cycles in flake follows. #9169

Merged
merged 2 commits into from Oct 18, 2023
Merged

Conversation

vkryachko
Copy link
Contributor

This change results in an error thrown as opposed to segfaulting due to stack overflow.

Fixes #9144

Motivation

Context

Priorities

Add 馃憤 to pull requests you find important.

This change results in an error thrown as opposed to segfaulting due to
stack overflow.

Fixes NixOS#9144
@github-actions github-actions bot added the with-tests Issues related to testing. PRs with tests have some priority label Oct 16, 2023
Copy link
Member

@thufschmitt thufschmitt left a comment

Choose a reason for hiding this comment

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

Thanks, that's great!

Just one minor question, but it's good apart from that (and with a neat test 馃ぉ )

auto pos = root;

auto pathS = printInputPath(path);
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to eagerly print the paths? Couldn't we have visited be a std::vector<FlakeId> and only print the paths if we get a cycle?

(not that it matters too much from a performance pov, but it would make the intent clearer I think)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm a bit rusty on c++(no pun intended :)), but:

I used a similar approach although using std::vector<InputPath>, then it turned out that InputPath is itself a vector, so to avoid the copy I decided to switch to std::vector<const InputPath&>, but apparently c++ does not like vectors of vector references, which have to be wrapped in std::reference_wrapper. So I decided to convert to path strings for visited.

Like you mention, even using vector<InputPath> will likely not matter in terms of performance, switched back to that.

Copy link
Member

Choose a reason for hiding this comment

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

Oh indeed, we're copying too much any way. Well, so be it then, we'll live with that.

Copy link
Member

@thufschmitt thufschmitt left a comment

Choose a reason for hiding this comment

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

Looking great, thanks!

@thufschmitt thufschmitt merged commit c1a1766 into NixOS:master Oct 18, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug flakes with-tests Issues related to testing. PRs with tests have some priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Segmentation fault when flake inputs follow each other
3 participants