Skip to content

Commit

Permalink
Collect link groups roots into set instead of list
Browse files Browse the repository at this point in the history
Summary: This change is required for further diffs where we check each node in roots when traversing graph of linkables. We can do it with `list` too, but `set` is simply more perfromant.

Reviewed By: artempyanykh

Differential Revision: D67389696

fbshipit-source-id: a5ea7ace8693dc98b9c823d4453105a4005d0062
  • Loading branch information
Nikita Patskov authored and facebook-github-bot committed Jan 2, 2025
1 parent 993e1a7 commit 5af67b0
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions prelude/cxx/cxx_executable.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -416,14 +416,14 @@ def cxx_executable(ctx: AnalysisContext, impl_params: CxxRuleConstructorParams,
for name, lib in link_group_libs.items()
},
link_strategy = link_strategy,
roots = (
roots = set(
exec_dep_roots +
find_relevant_roots(
link_group = link_group,
linkable_graph_node_map = linkable_graph_node_map,
link_group_mappings = link_group_mappings,
roots = link_group_extra_link_roots,
)
),
),
executable_label = ctx.label,
is_executable_link = True,
Expand Down Expand Up @@ -476,7 +476,7 @@ def cxx_executable(ctx: AnalysisContext, impl_params: CxxRuleConstructorParams,
link_group_preferred_linkage,
link_strategy,
pic_behavior = pic_behavior,
roots = [d.linkable_graph.nodes.value.label for d in link_deps],
roots = set([d.linkable_graph.nodes.value.label for d in link_deps]),
executable_label = ctx.label,
prefer_stripped = impl_params.prefer_stripped_objects,
)
Expand Down
2 changes: 1 addition & 1 deletion prelude/cxx/cxx_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1491,7 +1491,7 @@ def _get_shared_library_links(
for name, lib in link_group_libs.items()
},
link_strategy = link_strategy,
roots = linkable_deps(non_exported_deps + exported_deps),
roots = set(linkable_deps(non_exported_deps + exported_deps)),
pic_behavior = pic_behavior,
executable_label = None,
prefer_stripped = prefer_stripped,
Expand Down
18 changes: 9 additions & 9 deletions prelude/cxx/link_groups.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ FinalLabelsToLinks = record(

def _collect_linkables(
linkable_graph_node_map: dict[Label, LinkableNode],
roots: list[Label]) -> list[Label]:
roots: set[Label]) -> list[Label]:
def get_potential_linkables(node: Label) -> list[Label]:
linkable_node = linkable_graph_node_map[node]

Expand All @@ -358,7 +358,7 @@ def _collect_linkables(
# Get all potential linkable targets
linkables = depth_first_traversal_by(
linkable_graph_node_map,
roots,
list(roots),
get_potential_linkables,
)

Expand All @@ -372,7 +372,7 @@ def get_filtered_labels_to_links_map(
link_group_mappings: [dict[Label, str], None],
link_group_preferred_linkage: dict[Label, Linkage],
link_strategy: LinkStrategy,
roots: list[Label],
roots: set[Label],
pic_behavior: PicBehavior,
executable_label: Label | None,
is_executable_link: bool = False,
Expand Down Expand Up @@ -645,16 +645,16 @@ def _find_all_relevant_roots(
specs: list[LinkGroupLibSpec],
link_group_mappings: dict[Label, str], # target label to link group name
roots: list[Label],
linkable_graph_node_map: dict[Label, LinkableNode]) -> dict[str, list[Label]]:
linkable_graph_node_map: dict[Label, LinkableNode]) -> dict[str, set[Label]]:
relevant_roots = {}
link_groups_for_full_traversal = set() # list[str]

for spec in specs:
if spec.root != None:
relevant_roots[spec.group.name] = spec.root.deps
relevant_roots[spec.group.name] = set(spec.root.deps)
else:
roots_from_mappings, has_empty_root = _get_roots_from_mappings(spec, linkable_graph_node_map)
relevant_roots[spec.group.name] = roots_from_mappings
relevant_roots[spec.group.name] = set(roots_from_mappings)
if has_empty_root:
link_groups_for_full_traversal.add(spec.group.name)

Expand All @@ -668,9 +668,9 @@ def _find_all_relevant_roots(
if node_link_group == MATCH_ALL_LABEL:
# Add node into the list of roots for all link groups
for link_group in relevant_roots.keys():
relevant_roots[link_group].append(node_target)
relevant_roots[link_group].add(node_target)
elif node_link_group in link_groups_for_full_traversal and node_link_group != NO_MATCH_LABEL:
relevant_roots[node_link_group].append(node_target)
relevant_roots[node_link_group].add(node_target)
return node.all_deps

depth_first_traversal_by(
Expand Down Expand Up @@ -741,7 +741,7 @@ _CreatedLinkGroup = record(
def _create_link_group(
ctx: AnalysisContext,
spec: LinkGroupLibSpec,
roots: list[Label],
roots: set[Label],
link_strategy: LinkStrategy,
executable_label: Label | None,
public_nodes: set[Label] = set(),
Expand Down
4 changes: 2 additions & 2 deletions prelude/haskell/haskell.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1037,13 +1037,13 @@ def haskell_binary_impl(ctx: AnalysisContext) -> list[Provider]:
for name, lib in link_group_libs.items()
},
link_strategy = link_strategy,
roots = (
roots = set(
[
d.linkable_graph.nodes.value.label
for d in link_deps
if d.linkable_graph != None
] +
link_group_relevant_roots
link_group_relevant_roots,
),
executable_label = ctx.label,
is_executable_link = True,
Expand Down
2 changes: 1 addition & 1 deletion prelude/rust/link_info.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ def inherited_rust_cxx_link_group_info(
for name, lib in link_group_libs.items()
},
link_strategy = link_strategy,
roots = executable_deps,
roots = set(executable_deps),
executable_label = ctx.label,
is_executable_link = True,
prefer_stripped = False,
Expand Down

0 comments on commit 5af67b0

Please sign in to comment.