-
Notifications
You must be signed in to change notification settings - Fork 10
Exclude built-in nodes from forward_class and align traversal tests #194
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
Merged
renau
merged 1 commit into
masc-ucsc:main
from
Sohamkayal4103:fix/forward-class-user-nodes
Mar 5, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -770,8 +770,9 @@ void Graph::rebuild_fast_hier_cache() const { | |
| } | ||
|
|
||
| void Graph::rebuild_forward_class_cache() const { | ||
| constexpr size_t first_user_node_idx = 4; // 0:invalid, 1:INPUT, 2:OUTPUT, 3:CONST | ||
| forward_class_cache_.clear(); | ||
| if (node_table.size() <= 1) { | ||
| if (node_table.size() <= first_user_node_idx) { | ||
| forward_class_cache_valid_ = true; | ||
| return; | ||
| } | ||
|
|
@@ -791,7 +792,7 @@ void Graph::rebuild_forward_class_cache() const { | |
|
|
||
| sink_nid &= ~static_cast<Nid>(3); | ||
| const size_t sink_idx = static_cast<size_t>(sink_nid >> 2); | ||
| if (sink_idx == 0 || sink_idx >= node_count) { | ||
| if (sink_idx < first_user_node_idx || sink_idx >= node_count) { | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -800,7 +801,7 @@ void Graph::rebuild_forward_class_cache() const { | |
| } | ||
| }; | ||
|
|
||
| for (size_t driver_idx = 1; driver_idx < node_count; ++driver_idx) { | ||
| for (size_t driver_idx = first_user_node_idx; driver_idx < node_count; ++driver_idx) { | ||
| const Nid driver_nid = static_cast<Nid>(driver_idx) << 2; | ||
|
|
||
| auto node_edges = node_table[driver_idx].get_edges(driver_nid); | ||
|
|
@@ -825,14 +826,14 @@ void Graph::rebuild_forward_class_cache() const { | |
| } | ||
|
|
||
| std::priority_queue<size_t, std::vector<size_t>, std::greater<size_t>> ready; | ||
| for (size_t idx = 1; idx < node_count; ++idx) { | ||
| for (size_t idx = first_user_node_idx; idx < node_count; ++idx) { | ||
| if (indegree[idx] == 0) { | ||
| ready.push(idx); | ||
| } | ||
| } | ||
|
|
||
| std::vector<bool> emitted(node_count, false); | ||
| forward_class_cache_.reserve(node_count - 1); | ||
| forward_class_cache_.reserve(node_count - first_user_node_idx); | ||
| while (!ready.empty()) { | ||
| const size_t node_idx = ready.top(); | ||
| ready.pop(); | ||
|
|
@@ -855,7 +856,7 @@ void Graph::rebuild_forward_class_cache() const { | |
| } | ||
|
|
||
| // Preserve determinism under cycles by appending unresolved nodes by ID. | ||
| for (size_t idx = 1; idx < node_count; ++idx) { | ||
| for (size_t idx = first_user_node_idx; idx < node_count; ++idx) { | ||
| if (!emitted[idx]) { | ||
| forward_class_cache_.emplace_back(const_cast<Graph*>(this), static_cast<Nid>(idx) << 2); | ||
| } | ||
|
|
@@ -1099,7 +1100,8 @@ auto Graph::fast_class() const -> std::span<const Node_class> { | |
| } | ||
|
|
||
| auto Graph::forward_class() const -> std::span<const Node_class> { | ||
| const size_t expected_size = node_table.size() > 0 ? node_table.size() - 1 : 0; | ||
| constexpr size_t first_user_node_idx = 4; // 0:invalid, 1:INPUT, 2:OUTPUT, 3:CONST | ||
| const size_t expected_size = node_table.size() > first_user_node_idx ? node_table.size() - first_user_node_idx : 0; | ||
| if (!forward_class_cache_valid_ || forward_class_cache_.size() != expected_size) { | ||
|
Comment on lines
+1103
to
1105
|
||
| rebuild_forward_class_cache(); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
first_user_node_idxis a magic number that is now duplicated here and again inGraph::forward_class(). To avoid the two code paths drifting (and causing cache-size mismatches / repeated rebuilds if one is updated without the other), consider defining a single shared constant (e.g., astatic constexpronGraphor a file-scope constant) and using it in both places.