buck2 icon indicating copy to clipboard operation
buck2 copied to clipboard

Share dynamic values across dynamic_output actions

Open aherrmann opened this issue 10 months ago • 12 comments

Adds support for sharing values across dynamic_output actions.

The function given to a dynamic output action can now return a list of providers. The ctx.actions.dynamic_output function returns a handle to the future values of these providers. Another dynamic output action can take these handles in, which allows the function to resolve these handles into their resolved values. This way it is possible to share values that are obtained within a dynamic output lambda with another dynamic output lambda.

Includes a small example demo

$ cd examples/dynamic_value
$ cargo run --bin buck2 build //:target_b

The motivation comes from Haskell builds, where we want to achieve cross package module granular builds as described in https://github.com/tweag/rules_haskell/issues/1631. In that case we need to know the module dependency graph across package boundaries and track a tset for each module that captures its transitive module dependencies across package boundaries. Without this feature this is not possible without piping these module dependency graphs through the filesystem and reloading and reanalyzing them over and over again in each packaeg's dynamic output action.

  • Example using dynamic values
  • Implement dynamic values

aherrmann avatar Apr 12 '24 15:04 aherrmann

We have now successfully applied these changes on a Haskell project to achieve cross package module granular incremental builds. The dynamic value introduced here works to propagate module dependency graphs across package boundaries through tsets.

I'd like to open this up for review and discuss whether the API change is acceptable. This adds an example to test the feature. cc @cjhopman

aherrmann avatar Apr 19 '24 14:04 aherrmann

Assigning the PR to myself.

However, this week we have internal conference, and next week I'm on holidays. Can it wait two weeks @aherrmann?

stepancheg avatar Apr 24 '24 21:04 stepancheg

Hi @stepancheg, thank you for taking this on! Yes, of course, no problem if this waits two weeks. :slightly_smiling_face:

aherrmann avatar Apr 25 '24 08:04 aherrmann

@stepancheg I hope you had a good conference and vacation! Did you have a chance to take a look at this since you're back?

aherrmann avatar May 15 '24 07:05 aherrmann

@aherrmann working on it. Sorry for delay!

stepancheg avatar May 15 '24 16:05 stepancheg

No worries, I can relate. Thank you for looking into it!

aherrmann avatar May 16 '24 07:05 aherrmann

I'm working on some changes in dynamic_output API which I plan to land before taking this PR. I'll rebase this PR on top of my work.

Just FYI, this PR is not forgotten.

stepancheg avatar May 28 '24 10:05 stepancheg

@stepancheg Thanks for the update and for looking into it! Let me know if there's anything I can help with.

aherrmann avatar May 28 '24 11:05 aherrmann

Hi @stepancheg, did you have a chance to look into this? Is there anything I can do to help this along?

aherrmann avatar Jun 17 '24 09:06 aherrmann

@stepancheg has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Jun 18 '24 00:06 facebook-github-bot

Got distracted by buck2 starlark profiler needed to be fixed because many people reported the issue. This is still the top of my list. Again, sorry for delay.

stepancheg avatar Jun 18 '24 00:06 stepancheg

Fyi, we're in the process of discussing/reviewing this internally at the moment. The big open question right now is whether you should have to declare whether a dynamic_outputs lambda expects or returns dynamic values, especially in the context of the new dynamic_actions APIs. Will keep things updated

JakobDegen avatar Jul 05 '24 00:07 JakobDegen

@aherrmann we have finally merged your PR db40a075b624db1f67320a01a47ee1fc7624a1c8. Thank you, and sorry for delay.

API is not final, we plan to tweak it. Also this API is not implemented for BXL yet. But fundamentally it will stay as you proposed it.

stepancheg avatar Aug 17 '24 16:08 stepancheg

@stepancheg That's fantastic news, thank you! I look forward to trying out the new API!

aherrmann avatar Aug 19 '24 07:08 aherrmann

@stepancheg As a first test I took the example included in this PR and rebased it on the new API. I'm happy to report that it worked very well for that example, see https://github.com/facebook/buck2/pull/744.

aherrmann avatar Aug 19 '24 14:08 aherrmann

closing, this was implemented in https://github.com/facebook/buck2/commit/db40a075b624db1f67320a01a47ee1fc7624a1c8

aherrmann avatar Sep 02 '24 15:09 aherrmann