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

extend/ENV/super: allow O{1,0} to accept a block #11666

Merged
merged 4 commits into from Jul 8, 2021

Conversation

carlocab
Copy link
Member

@carlocab carlocab commented Jul 6, 2021

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

This makes ENV.O{1,0} behave like ENV.deparallelize.

This should also allow us to build libgcrypt's jitter entropy collector,
which we currently disable because it interacts poorly with our compiler
shims. See #11201 for a previous attempt at this.

@BrewTestBot
Copy link
Member

Review period will end on 2021-07-07 at 23:59:03 UTC.

@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label Jul 6, 2021

if block
begin
block.call
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure why yield doesn't work, but I don't really get Ruby metaprogramming.

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Makes sense to me. I'd love to see more of these methods take block forms to be used in a more finely-grained manner (and perhaps even deprecate the non-block for of deparallelize). with_env may be a cleaner solution to this?

@carlocab
Copy link
Member Author

carlocab commented Jul 7, 2021

with_env may be a cleaner solution to this?

with_env would work if we change these methods to only accept blocks. I don't see a way of making it work if you want the environment change to persist until the end of the install method, but maybe I just don't understand with_env.

@carlocab carlocab enabled auto-merge July 7, 2021 14:55
@MikeMcQuaid
Copy link
Member

with_env would work if we change these methods to only accept blocks. I don't see a way of making it work if you want the environment change to persist until the end of the install method, but maybe I just don't understand with_env.

I was thinking maybe just for the block case?

@carlocab
Copy link
Member Author

carlocab commented Jul 7, 2021

So you mean something like

  %w[O1 O0].each do |opt|
    define_method opt do |&block|
      if block
        with_env(HOMEBREW_OPTIMIZATION_LEVEL: opt) { block.call }
      else
        send(:[]=, "HOMEBREW_OPTIMIZATION_LEVEL", opt)
      end
    end
  end

?

@carlocab carlocab disabled auto-merge July 7, 2021 18:38
@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label Jul 8, 2021
@BrewTestBot
Copy link
Member

Review period ended.

@MikeMcQuaid
Copy link
Member

@carlocab Yeh, that looks nice to me 👍🏻

This makes `ENV.O{1,0}` behave like `ENV.deparallelize`.

This should also allow us to build libgcrypt's jitter entropy collector,
which we currently disable because it interacts poorly with our compiler
shims. See Homebrew#11201.
@MikeMcQuaid MikeMcQuaid added the critical Critical change which should be shipped as soon as possible. label Jul 8, 2021
@carlocab
Copy link
Member Author

carlocab commented Jul 8, 2021

Oops. Sorbet really does not like the new version:

❯ brew typecheck
extend/ENV/super.rb:343: This code is unreachable https://srb.help/7006
     343 |        with_env(HOMEBREW_OPTIMIZATION_LEVEL: opt) { block.call }
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    extend/ENV/super.rb:342: This condition was always falsy (NilClass)
     342 |      if block
                   ^^^^^
  Got NilClass originating from:
    extend/ENV/super.rb:341:
     341 |    define_method opt do |&block|
                                     ^^^^^

@MikeMcQuaid
Copy link
Member

@carlocab Given there's now only two of these methods: I'd suggest avoiding define_method and defining them normally.

@carlocab
Copy link
Member Author

carlocab commented Jul 8, 2021

Ah, just saw your comment. Convincing Sorbet that block can occasionally not be nil isn't too much more code. Would you still rather these two methods be defined separately?

@MikeMcQuaid
Copy link
Member

@carlocab Sorry, yeh, I think it'd be nicer.

@carlocab
Copy link
Member Author

carlocab commented Jul 8, 2021

Sure, that's fine. I've pushed the changes.

%w[O1 O0].each do |opt|
define_method opt do
send(:[]=, "HOMEBREW_OPTIMIZATION_LEVEL", opt)
# rubocop: disable Naming/MethodName
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment here explaining why? Thanks!

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Thanks, sorry for all the back and forth 🙇🏻

@carlocab carlocab enabled auto-merge July 8, 2021 18:21
@carlocab
Copy link
Member Author

carlocab commented Jul 8, 2021

The apology is appreciated but very much unnecessary 🙂

@carlocab carlocab merged commit 805f0ba into Homebrew:master Jul 8, 2021
@carlocab carlocab deleted the optim-block branch July 8, 2021 18:42
carlocab added a commit to carlocab/homebrew-core that referenced this pull request Jul 9, 2021
This enables the jent module, which is included in the default build
configuration. The jent module provides an additional source of entropy
generated from CPU time jitter [1] and should help increase the security
of users who make use of `libgcrypt` particularly in virtualised
environments, server systems, or modern computers which lack spinning
hard disks that can be used as an entropy source.

We previously disabled this because the jent module must be built without
optimisations [2], but our compiler shims provided limited support for
selectively relaxing the optimisation level. This was resolved by
Homebrew/brew#11666.

[1] https://www.chronox.de/jent/doc/CPU-Jitter-NPTRNG.html
[2] Homebrew#15750
BrewTestBot pushed a commit to Homebrew/homebrew-core that referenced this pull request Jul 12, 2021
This enables the jent module, which is included in the default build
configuration. The jent module provides an additional source of entropy
generated from CPU time jitter [1] and should help increase the security
of users who make use of `libgcrypt` particularly in virtualised
environments, server systems, or modern computers which lack spinning
hard disks that can be used as an entropy source.

We previously disabled this because the jent module must be built without
optimisations [2], but our compiler shims provided limited support for
selectively relaxing the optimisation level. This was resolved by
Homebrew/brew#11666.

[1] https://www.chronox.de/jent/doc/CPU-Jitter-NPTRNG.html
[2] #15750

Closes #80839.

Signed-off-by: Nanda H Krishna <me@nandahkrishna.com>
Signed-off-by: BrewTestBot <1589480+BrewTestBot@users.noreply.github.com>
@github-actions github-actions bot added the outdated PR was locked due to age label Aug 8, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
critical Critical change which should be shipped as soon as possible. outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants