Debugger inverts BUILD_PATH_PREFIX_MAP before loading paths stored in cm?#14055
Debugger inverts BUILD_PATH_PREFIX_MAP before loading paths stored in cm?#14055gasche merged 4 commits intoocaml:trunkfrom
Conversation
|
We could decide to use this as a heuristic rather than a hard rule: look at the inverted path first, but look at the provided path if that fails. This would make the new system trivially compatible with what the current compiler today, but also more complex. I'm willing to make the bet that this complexity is not necessary -- that BUILD_PATH_PREFIX_MAP should always be inverted by the debugger, never ignored -- but others might disagree, and this is an option we have for later if compatibility turns out to be an issue. |
gasche
left a comment
There was a problem hiding this comment.
I made a code review, assuming that we are okay with the change of behavior as previously mentioned. This looks fine overall, with nitpick comments.
utils/build_path_prefix_map.ml
Outdated
| | Some { target; source } -> | ||
| let is_prefix = | ||
| String.length target <= String.length path | ||
| && String.equal target (String.sub path 0 (String.length target)) in |
There was a problem hiding this comment.
This is now in the stdlib! String.starts_with ~prefix:target path.
There was a problem hiding this comment.
(I see that this is reused from code above. Maybe you could factor out some has_prefix ~prefix str and replace_prefix ~prefix ~new_prefix str auxiliary helper functions?)
There was a problem hiding this comment.
So, I used String.starts_with but I didn't refactored more because make_target is dead code that I'm willing to erased if it is still unused once we are happy with the behaviors around BUILD_PATH_PREFIX_MAP so I don't want to touch it (as long as it is not used).
| else s) | ||
| s | ||
| (Misc.revert_build_path_prefix_map abs_e)) | ||
| !dirs (input_value ic) |
There was a problem hiding this comment.
This is getting a bit complex and I think it could go to an auxiliary function, if you don't mind.
There was a problem hiding this comment.
Indeed, done (and actually I took that opportunity to give to the auxiliary function a better semantic (in my opinion))
utils/build_path_prefix_map.mli
Outdated
| it just returns [path]. *) | ||
|
|
||
| val revert_all : map -> path -> path list | ||
| (** [revert_all map path] finds all targets in [map] |
There was a problem hiding this comment.
Should we use the word "invert" (as in your PR description) or "revert" (as in the code)? I'm fine with either options. I find that "invert" (so here I guess invert_all?) makes some sense in relation to the mathematical notion (inverse map, inverse of a relation, etc.).
There was a problem hiding this comment.
Yes, "invert" everywhere it is...
utils/misc.mli
Outdated
| val revert_build_path_prefix_map: string -> string list | ||
| (** Returns the potential pathes from which the given path can | ||
| originate from before rewrite using [BUILD_PATH_PREFIX_MAP] | ||
| environment variable. *) |
There was a problem hiding this comment.
pathes -> paths. Also it would be nice to indicate the order of the result in this doc string.
4ec815b to
a62923c
Compare
I'm not sure it "adds anything" but it certainly doesn't hurt and the added complexity is OK (once the machinery put in an auxiliary function) therefore... Done! |
877f0e8 to
0e80bb3
Compare
|
I don't understand what is the next action to be done here and who has to do it. And, as it has been stalled for 3 months now. I fear it's on me, is it? |
gasche
left a comment
There was a problem hiding this comment.
The ping is mostly what was required. Can we do a quick recap of where this PR stands, though? If I understand correctly, it started as a PR that would change the debugger behavior, but in the end you removed that part of the change and the PR only adds the ability to invert prefix-map paths. Right? So presumably other behavior changes are coming later?
I'm fine with the current state, and/but I think it would be nice to have an accurate summary of the PR before we merge.
utils/misc.mli
Outdated
| variable. *) | ||
|
|
||
| val invert_build_path_prefix_map: string -> string list | ||
| (** Returns the potential paths (in decreasing order of priority) from |
There was a problem hiding this comment.
I would use "in priority order" as in build_path_prefix_map.mli, the notion of increasing/decreasing priority tends to be confusing and subject to opposite conventions.
0e80bb3 to
ab592af
Compare
|
Attempt to clarify what this PR does: Before, the debugger was simply ignoring (so breakages occur when 1/ This PR will not have any direct follow-up in the repository. It's potential follow-up would be in |
|
Thanks for the summary! Merging. (There is a transient testsuite failure in |
The whole purpose of
BUILD_PATH_PREFIX_MAPis to be able to rewrite prefixes of absolute paths written into compilation unit.ocamldebugreads these paths. But, when it is launched in the folder where the sources have been compiled, theses prefixes don't make sense. This is whyocamldebugcurrently fails to find any information (sources/printers/...) about programs compiled bydune.This patch makes the hypothesis that when it launched while
BUILD_PATH_PREFIX_MAPis set, it means that it is launched from the repository in which sources have been built using this value for the environment variable. Therefore, it "inverts" it to find files on disk.This restores the usability of
ocamldebugin "the setting it used to work" before dune 3.0.