Skip to content

Simplify Pkg_rules.source_files a bit#14301

Merged
Alizter merged 1 commit intoocaml:mainfrom
ElectreAAS:push-mstrszkyulwz
Apr 24, 2026
Merged

Simplify Pkg_rules.source_files a bit#14301
Alizter merged 1 commit intoocaml:mainfrom
ElectreAAS:push-mstrszkyulwz

Conversation

@ElectreAAS
Copy link
Copy Markdown
Collaborator

Just a trivial simplification in Pkg_rules.source_files, nothing changing dune behaviour.

Instead of mapping the relative part later, do it once in the partition.
This isn't particularly useful on its own, but in case of changes inside the partition function, it makes debugging a lot easier
Extracted from #13792

Signed-off-by: Ambre Austen Suhamy <ambre@tarides.com>

Signed-off-by: Ambre Austen Suhamy <ambre@tarides.com>
let acc =
Path.Local.Set.of_list_map files ~f:(Path.Local.relative path)
|> Path.Local.Set.union acc
| S_DIR -> if skip_dir name then Skip else Right relative
Copy link
Copy Markdown
Collaborator

@Alizter Alizter Apr 23, 2026

Choose a reason for hiding this comment

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

I think this if needs to be pulled out above the let releative. We always consider skipping, but we don't always need to construct relatative.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

You mean something like this:

List.rev... ->
match kind with
| S_DIR -> if skip_dir name then Skip else Right (Path.Local.relative path name)
| _ -> if skip_file name then Skip else Left (Path.Local.relative path name))

It'd go against the idea of not repeating the relative call, for what I perceive to be minimal benefit

Did you miss that skip_dir and skip_file are different functions?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

That's true, my bad.

Copy link
Copy Markdown
Collaborator

@Alizter Alizter left a comment

Choose a reason for hiding this comment

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

I've asked copilot to review in case it notices anything important.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors Pkg_rules.Pkg.source_files to compute Path.Local.relative once during directory partitioning, keeping behavior the same while simplifying downstream mapping and making future debugging inside the partition function easier.

Changes:

  • Compute relative paths once in the rev_filter_partition_map callback and carry Path.Local.t values forward.
  • Simplify accumulation by removing of_list_map and eliminating an extra relative mapping step for subdirectories.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Alizter Alizter merged commit f2bbe6a into ocaml:main Apr 24, 2026
35 checks passed
@ElectreAAS ElectreAAS deleted the push-mstrszkyulwz branch April 27, 2026 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants