Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alias0.dir is always in build_dir #746

Merged
merged 5 commits into from
May 9, 2018

Conversation

rgrinberg
Copy link
Member

@rgrinberg rgrinberg commented May 7, 2018

This is useful to catch bugs in implementing #744

The 2nd commit feels a bit heavy handed but it's nice to have the extra safety of this. Another approach to help maintain this invariant would be to have some phantom types for paths to distinguish build vs. otherwise.

@rgrinberg rgrinberg requested a review from a user May 7, 2018 14:59
((struct
type t = { dir : Path.t; name : string }
let make name ~dir =
assert (not (String.contains name '/'));
Copy link

Choose a reason for hiding this comment

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

We can include this assert in the condition below

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@@ -222,19 +236,13 @@ module Alias0 = struct
if not (Path.is_in_build_dir path) then
Copy link

Choose a reason for hiding this comment

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

I believe this test is no longer needed

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, but then we're changing the user error message in die into something more opaque. I think it's still possible for the user to provide an invalid path here (though I'm not sure).

Copy link

Choose a reason for hiding this comment

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

Maybe when writing (alias /foo/bar)? Alias.of_path seems to be only used for that. I suggest to change of_path to of_path_written_by_user : loc:Loc.t -> ... and make it raise a properly located error.

Copy link

Choose a reason for hiding this comment

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

This is not directly related to this PR, but we might as well fix it once and for all

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that's a good idea - though i think this is not a trivial change. The only way I can see how to do this is to change Dep_conf.t to preserve the locs. If it's that big, I might as well make it its own PR.

Copy link

Choose a reason for hiding this comment

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

The argument of Dep_conf.Alias is a String_with_vars.t which already contain a location

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that wasn't too hard. Added a test for this error message too.

Copy link

Choose a reason for hiding this comment

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

Ok, looks good. One last thing: the checks done by M.make are redundant here since we already check that the path is in the build directory and Path.basename x is guaranted not to contain /. Can you move of_user_writen_path in M and create the t value directly?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@@ -212,7 +212,21 @@ module File_spec = struct
end

module Alias0 = struct
type t = { dir : Path.t; name : string }
include
Copy link

Choose a reason for hiding this comment

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

I find this syntax slightly heavy. What about module M : sig ... end = struct ... end include M?

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay. I'll use T over M since that's what we do elsewhere as well.

@ghost
Copy link

ghost commented May 8, 2018

I think using phantom types for types would be a bit heavy. After #744 we could change the type of Alias.make to take a Path.In_build_dir.t, so that it's up to the caller to do this check.

@rgrinberg rgrinberg force-pushed the alias0-build-dir branch 2 times, most recently from 22e2f24 to 7050d06 Compare May 8, 2018 15:30
rgrinberg added 4 commits May 9, 2018 08:05
the directory must always be inside the build dir, so we make sure that any way
to create the record validates this invariant
And add a loc argument for correct error messages
@rgrinberg rgrinberg force-pushed the alias0-build-dir branch from 7050d06 to ee97911 Compare May 9, 2018 01:10
This is done to avoid double check of the path being in build dir
@rgrinberg rgrinberg force-pushed the alias0-build-dir branch from ee97911 to 78612e0 Compare May 9, 2018 01:10
@rgrinberg rgrinberg merged commit 5112c23 into ocaml:master May 9, 2018
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.

1 participant