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

[RFC] replace action field of alias stanza by alias field in rule stanza #2681

Closed
ghost opened this issue Sep 30, 2019 · 18 comments
Closed

[RFC] replace action field of alias stanza by alias field in rule stanza #2681

ghost opened this issue Sep 30, 2019 · 18 comments
Assignees

Comments

@ghost
Copy link

ghost commented Sep 30, 2019

Right now, when one writes:

(alias
 (name blah)
 (deps x)
 (action (run foo)))

It's not entirely clear whether x is a dependency of the action or the alias. In particular, Dune and Jenga (inside Jane Street) accidentally made two different choices which indicates that the semantic is not obvious. In Jenga, x is a dependency of the action but not the alias, and in Dune x is a dependency of both.

Additionally, it always a bit annoying when the action produces something as aliases are not supposed to have targets.

To clarify all this, I propose the following change in the 2.x version of the language:

  • we remove the action field from the alias stanza
  • we add an alias field to the rule stanza

adding (alias foo) to a rule would basically add the targets as dependency of the alias, even if the rule has no targets.

@aalekseyev
Copy link
Collaborator

aalekseyev commented Oct 9, 2019

First, I want to say that "dependency of the alias" sounds ambiguous to me because alias has two kinds of dependencies and we should try to clarify that terminology.

Consider a rule like this:

(rule (target x) (dep (alias foo))) (action ...))

Let's call the set of files whose changes cause the rebuild of "x" an "expansion" of the alias foo. (similar to expansion of a variable, as @rgrinberg suggested)

Where @diml mentions dependencies of the alias above he clearly means the expansion of the alias.

The second idea of dependencies is the set of actions that contribute to the build result (transitively or directly) when you ask dune to build an alias. I like to call those "dependencies", but for clarity here let's call them "transitive dependencies" (for avoidance of doubt, transitive deps are not obtained by transitively closing over expansions).

When the rule is assigned to the alias it should absolutely become the "transitive dependency" of the alias, but I'm much less convinced that its targets should become a part of alias "expansion". In fact I would expect the rule to contribute nothing at all to the alias expansion.

In the meeting we also discussed that the idea of alias expansions should be eventually deprecated in favor of variables. I like that idea and if we're moving that way I think it makes sense to avoid adding more things to the expansions.

Other than that, I very much support the idea and on top of simplifying aliases (which is a win already) it makes a common idiom shorter.

Instead of writing

(rule
  (targets foo)
  ...
)
(alias (name DEFAULT) (deps foo))

you just write:

(rule
  (targets foo)
  (alias DEFAULT)
  ...
)

One implementation detail that could be annoying is to add support for rules with an empty set of targets. Maybe it's not too difficult though.

@ghost
Copy link
Author

ghost commented Oct 9, 2019

I thought more about this and I agree that we shouldn't add the targets to the expansion of the alias. So happy to drop that part.

Regarding rules with an empty set of targets, we can do something similar to what we do now for aliases with actions, i.e. replace <action> by (progn <action> (create-file <stamp-file>)) and add the stamp file as a transitive dependency of the alias. We can do that whether the rules has targets or not.

@aalekseyev
Copy link
Collaborator

That sounds like it should work.

@ghost ghost added this to the 2.0.0 milestone Oct 10, 2019
@ghost ghost assigned rgrinberg Oct 10, 2019
@nojb
Copy link
Collaborator

nojb commented Oct 19, 2019

This looks like a good idea. A small thing that would be useful as well is to make sure that rules with an (alias ...) field are not attached to the all alias by default. Currently all user-defined rules are attached to all. This is inconvenient when one uses the common idiom mentioned by @aalekseyev above to build a testsuite, as it results in the output-producing part of the testsuite running when you do dune build.

@nojb
Copy link
Collaborator

nojb commented Oct 19, 2019

Regarding rules with an empty set of targets,

Just to understand better, can you show me an example of such a rule?

@aalekseyev
Copy link
Collaborator

can you show me an example of such a rule [with an empty set of targets]

Such rules are not currently supported. The idea is that they will replace the action field of aliases. For example where we currently write:

(alias
 (name runtest)
 (action
  (run ./some_tests.exe)))

We would instead write:

(rule
 (alias runtest)
 (action
  (run ./some_tests.exe)))

@aalekseyev
Copy link
Collaborator

aalekseyev commented Oct 21, 2019

I'm not particularly excited about the idea of removing things from the @all alias. It does say "all" in its name, after all.

@nojb
Copy link
Collaborator

nojb commented Oct 21, 2019

I'm not particularly excited about the idea of removing things from the @all alias. It does say "all" in its name, after all.

My issue is not with the all alias but with dune build which should not in my view trigger all user-defined rules. The case I have in mind when you have a generated testsuite that may consist of several hundreds of rules producing test output, and triggering them dune build is a bit unexpected.

@nojb
Copy link
Collaborator

nojb commented Oct 21, 2019

(but this is more or less orthogonal to the issue at hand, so let's discuss this elsewhere)

@rgrinberg
Copy link
Member

While working on this I found that we the current alias stanza with action is slightly more flexible than this proposal. It allows for a package field to be set to allow one to attach aliases to packages (particularly useful for tests). I think we need a similar field for rules.

@ghost ghost removed this from the 2.0.0 milestone Oct 28, 2019
@ghost
Copy link
Author

ghost commented Oct 28, 2019

Removed from the 2.0.0 milestone, it feels like a too big change at this point.

@rgrinberg
Copy link
Member

rgrinberg commented Oct 28, 2019 via email

@rgrinberg
Copy link
Member

I still need the 2nd part of this issue: deprecate the action field for the alias stanza. Do we need to add an intermediate deprecation message somewhere? Or is it sufficient that we simply disallow action in for >= 2.0?

@ghost
Copy link
Author

ghost commented Nov 4, 2019

Whether we disallow or deprecate the action field, the replacement needs to be fully ready. In particular, we need the package field for rules.

If we do all this for 2.0.0, then we can effectively disallow action for >= 2.0. Otherwise, it needs to be only deprecated and we'll get rid of the action field in alias in 3.0.

I'm just a bit worried that this looks like a big change close to release time. But apart from that I have no objection.

@rgrinberg
Copy link
Member

rgrinberg commented Nov 4, 2019 via email

@ghost
Copy link
Author

ghost commented Nov 4, 2019

Ok, no objection to doing the switch now and disallowing the action field in >= 2.0 then!

@rgrinberg
Copy link
Member

See this pr: #2846

@ghost
Copy link
Author

ghost commented Nov 5, 2019

This is now complete

This issue was closed.
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

No branches or pull requests

3 participants