Skip to content

Commit

Permalink
Eliminate constructors
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 707419342
  • Loading branch information
oprypin authored and copybara-github committed Dec 18, 2024
1 parent dcd750f commit 753fc09
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions pytype/typegraph/solver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,13 @@ namespace internal {
struct RemoveResult {
const GoalSet removed_goals;
const GoalSet new_goals;
RemoveResult(const GoalSet& removed_goals, const GoalSet& new_goals):
removed_goals(removed_goals), new_goals(new_goals) {}
};

struct TraverseState {
GoalSet goals_to_remove;
GoalSet seen_goals;
GoalSet removed_goals;
GoalSet new_goals;
TraverseState() {}
TraverseState(GoalSet goals_to_remove, GoalSet seen_goals,
GoalSet removed_goals, GoalSet new_goals)
: goals_to_remove(goals_to_remove),
seen_goals(seen_goals),
removed_goals(removed_goals),
new_goals(new_goals) {}
};

// Remove all goals that can be fulfilled at the current CFG node.
Expand All @@ -65,36 +56,35 @@ static std::vector<RemoveResult> remove_finished_goals(const CFGNode* pos,
std::inserter(state.new_goals, state.new_goals.begin()),
pointer_less<Binding>());
std::deque<TraverseState> queue;
queue.emplace_back(state);
queue.push_back(std::move(state));
std::vector<RemoveResult> results;
while (!queue.empty()) {
state = std::move(queue.front());
queue.pop_front();
if (state.goals_to_remove.empty()) {
results.push_back(RemoveResult(state.removed_goals, state.new_goals));
results.push_back({state.removed_goals, state.new_goals});
continue;
}
const auto* goal = *state.goals_to_remove.begin();
state.goals_to_remove.erase(state.goals_to_remove.begin());
if (state.seen_goals.count(goal)) {
// Only process a goal once, to prevent infinite loops.
queue.emplace_back(std::move(state));
queue.push_back(std::move(state));
continue;
}
state.seen_goals.insert(goal);
const auto* origin = goal->FindOrigin(pos);
if (!origin) {
state.new_goals.insert(goal);
queue.emplace_back(std::move(state));
queue.push_back(std::move(state));
continue;
}
state.removed_goals.insert(goal);
for (const auto& source_set : origin->source_sets) {
GoalSet next_goals_to_remove(state.goals_to_remove);
next_goals_to_remove.insert(source_set.begin(), source_set.end());
queue.push_back(TraverseState(std::move(next_goals_to_remove),
state.seen_goals, state.removed_goals,
state.new_goals));
queue.push_back({std::move(next_goals_to_remove), state.seen_goals,
state.removed_goals, state.new_goals});
}
}
return results;
Expand Down

0 comments on commit 753fc09

Please sign in to comment.