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

Remove Concat_or_split #849

Merged
merged 23 commits into from
Jun 6, 2018
Merged

Conversation

rgrinberg
Copy link
Member

Thie property will now be determined from the context

Signed-off-by: Rudi Grinberg rudi.grinberg@gmail.com

@rgrinberg
Copy link
Member Author

Putting this up separately and I'm a bit surprised this doesn't break any tests. I guess we don't have a test suite for this?

@rgrinberg rgrinberg requested a review from a user June 4, 2018 10:48
src/action.ml Outdated
| Paths (_, Concat) | Strings (_, Concat) -> false
| Paths [_] -> false
| Strings [_] -> false
| _ -> false
Copy link

Choose a reason for hiding this comment

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

shouldn't this be true?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, why is that? If we only have 1 value then we aren't multivalued.

Copy link

Choose a reason for hiding this comment

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

Currently this function is the same as this one:

let is_multivalued _ = false

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah yes. Oops.

@ghost
Copy link

ghost commented Jun 4, 2018

I think some of the cases we could represent with the previous types didn't make much sense in practice, so there probably never appear.

BTW, the error messages in strings_with_vars need to be updated. What about:

Variable <var> expands to <N> values, however a single value is expected here. Please quote this atom.

@rgrinberg
Copy link
Member Author

@diml I've added the length to the error message, though I'm not sure the boilerplate necessary to do it is worth it.

@ghost
Copy link

ghost commented Jun 4, 2018

What about getting rid of is_multivalued and keeping only length? Then it should be the same amount of boilerplate as before.

@rgrinberg
Copy link
Member Author

is_multivalued can be faster than length. I suppose it doesn't matter much here.

@ghost
Copy link

ghost commented Jun 4, 2018

I don't think it matters indeed since it's only going to be slow in error cases.

@rgrinberg
Copy link
Member Author

Why's that? we checked for multivalued-ness for every valid substitution.

@rgrinberg
Copy link
Member Author

I've implemented the desired behavior for actions by adding a ~allow_multivalue flag to the expansion function. The alternative is to check if the result is an Expansion. But this is a bit annoying as we don't have access to the same error message anymore.

@ghost
Copy link

ghost commented Jun 5, 2018

Why's that? we checked for multivalued-ness for every valid substitution.

the only place where we call is_multivalued is the following:

    if not t.quoted && V.is_multivalued x then
      Loc.fail t.loc ...

We can only go in the error case if the list is not of length 1. And if the list is of length 1, then V.length x is as fast as V.is_multivalued.

@ghost
Copy link

ghost commented Jun 5, 2018

String_with_vars.Expand_to is now applied only once, and String_with_vars.{,partial_}expand are never used. At this point it is no longer necessary to keep the separation between string_with_vars and variable expansions.

I propose the following API for String_with_vars (without functors):

module Mode : sig
  type 'a t =
    | Single : Value.t t
    | Many   : Value.t list t
end

val expand
  :  t
  -> mode:'a Mode.t
  -> dir:Path.t
  -> f:(Loc.t -> string -> Value.t list option)
  -> 'a

module Expand_partial : sig
  type nonrec 'a t =
    | Expansion  of 'a
    | Unexpanded of t
end

val partial_expand 
  :  t
  -> mode:'a Mode.t
  -> dir:Path.t
  -> f:(Loc.t -> string -> Value.t list option)
  -> 'a Expand_partial.t

where Value is a new module with this API:

type t =
  | String of string
  | Path of Path.t

and later we'll add Version of string to Value.t.

Overall this will simplify the code and implement the desired semantic in a more obvious way.

@rgrinberg
Copy link
Member Author

@diml that looks good, I will work towards that. Is it desirable that Value.t list supports returning a mix of strings and paths? While I can imagine that being useful, we don't actually have any instances of that in the codebase.

@ghost
Copy link

ghost commented Jun 5, 2018

One case I was thinking of is program and arguments: we want the first element to be a path but the rest to be strings.

@rgrinberg
Copy link
Member Author

@diml have a look

src/action.ml Outdated
| Strings (s :: l, Split) ->
(P.of_string ~dir s, l)
end
let var_expansion_to_prog_and_args p ~dir =
Copy link

Choose a reason for hiding this comment

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

what about prog_and_args_of_values?

| Text s :: items -> loop (s :: acc_text) acc items
| Var (syntax, v) as it :: items ->
begin match f t.loc v with
| Some (([] | _::_) as e) when not t.quoted ->
Copy link

Choose a reason for hiding this comment

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

Should be _::_::_. BTW, I suggest to use the same branches in expand and partial_expand. I was a bit surprised at first that there were different.

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, this is ugly. I'll try to factor it out as well.

@@ -3,3 +3,5 @@
type ('a, 'b) t =
| Left of 'a
| Right of 'b

val either : ('a, 'b) t -> l:('a -> 'c) -> r:('b -> 'c) -> 'c
Copy link

Choose a reason for hiding this comment

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

I would call this function map

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure. Though this function is called either in Haskell for example.

@ghost
Copy link

ghost commented Jun 5, 2018

@rgrinberg looks good. It's much cleaner than master.

I suggest that we also add Value.Dir, so that we can directly add ROOT and SCOPE_ROOT to the vars field of Super_context.t.

@ghost
Copy link

ghost commented Jun 5, 2018

The misc test looks broken, it must have been broken during the renaming of the jbuild file to dune. Looking at it, it seems like once fixed, it is broken by this PR because it expects that (echo ${^}) behaves the same as (echo "${^}"). This case might happen in existing projects as well.

I suggest that we simply change echo to be variadic. I don't think the other actions are affected.

@rgrinberg
Copy link
Member Author

@diml btw, another way to make the code more DRY would be to implement expansion in terms of partial expansion. I'm thinking that we can just try a partial expansion and modify f to simply return string_of_var in the missing cases. The only problem with that is f doesn't have access to the variable's syntax. Perhaps it's worth adding this parameter in an internal implementation of partial_expand?

@rgrinberg
Copy link
Member Author

I suggest that we also add Value.Dir, so that we can directly add ROOT and SCOPE_ROOT to the vars field of Super_context.t.

I might be missing something here, why can't we just add them vars as Value.Path (like other directories).

@rgrinberg
Copy link
Member Author

@diml the misc tests are fixed.

@rgrinberg
Copy link
Member Author

I suggest that we also add Value.Dir, so that we can directly add ROOT and SCOPE_ROOT to the vars field of Super_context.t.

How would this work for SCOPE_ROOT? This variable depends on the scope where the variable is expanded.

rgrinberg and others added 21 commits June 6, 2018 23:41
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Thie property will now be determined from the context

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Since it's used more than once

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This is useful for an error message that includes the number of items we've
expanded to.

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
These variables can occur outside actions so such expansions shouldn't live
under Var_expansion.

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Multivalues are no longer allowed when unquoted, and paths are no longer
needlessly converted.

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Make it expand only to Value.t since the string only version wasn't really used.
Variable expansions are now Value.t list. Which also gives the flexibility for a
value to expand to a collection of more than 1 value.

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
The partial expansion had a bug in its condition for a 1 element value list.
This fixes the bug by implementing the condition once and for all.

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Jeremie Dimino <jdimino@janestreet.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
@rgrinberg
Copy link
Member Author

@diml done. this PR seems to build bin_prot (and the rest of the workspace) just fine.

@rgrinberg rgrinberg merged commit c724144 into ocaml:master Jun 6, 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