Open nmattia opened 1 week ago
Hi @nmattia -- thanks for filing this issue!
I don't think we will remove the paths altogether -- let me explain a bit more why. We emit these paths in the generated Rust code to help us debug and to see where rule-matching cases are defined in the original source. It was an explicit design goal for the output of the ISLE metacompiler to be relatively comprehensible to humans. The ability to refer back to source locations is useful for this.
That said, I'd be happy to review a PR that makes the paths relative to the source root (your option 3).
I'm also a bit curious about your use-case. You say "more correct caching" -- do you mean, higher cache hit-rate for a cache shared across many builds at different paths? We have not made it an explicit design goal to avoid, e.g., absolute paths in comments, though we do take care to ensure the final built code is semantically deterministic (i.e. our only variances should be in comments). I think it'd be reasonable to aim for this tighter intermediate-textual-form definition of determinism, just want to clarify the exact requirement.
FWIW, I think we do (or did at one point do) this kind of prefix removal in cranelift's build script or the meta crate.
We emit these paths in the generated Rust code to help us debug
That makes complete sense!
I'd be happy to review a PR that makes the paths relative to the source root
I'll prepare something and send it your way then :)
higher cache hit-rate for a cache shared across many builds at different paths?
Yes, that's right! Some build systems read and hash inputs to see if any of the outputs that depend on said inputs need to be rebuilt -- unlike Make for instance, which uses mtime. So when some of those inputs (generated code with changing comments) change, the previously built outputs are discarded and need to be rebuilt, even though the changed comments should not have an impact on the actual built code.
Feature
It would be great to avoid printing full paths of source files in the generated code.
Benefit
This would allow for better or more correct caching in third party build systems like Bazel or Nix.
Implementation
CARGO_MANIFEST_DIR
; alternatively only thebasename
of the source file could be retained and written to the generated files.Not very familiar with the crate so can't make an educated decision! But this would be a nice improvement in the way of system-independent reproducible builds.