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

gcc: deduplicate top-level expressions #243607

Merged
1 commit merged into from Jul 28, 2023
Merged

gcc: deduplicate top-level expressions #243607

1 commit merged into from Jul 28, 2023

Conversation

ghost
Copy link

@ghost ghost commented Jul 15, 2023

This commit does not affect eval (no drv-hash changes).

Description of changes

This commit deduplicates the copy-pasted gcc mess in pkgs/top-level/all-packages.txt, replacing it with a single expression that branches based on the chosen version.

This exposed several bizzare behaviors in our historical gcc expressions (these bullet points are repeated below alongside the code they refer to):

  1. The ISL version we are using jumps backward from 0.14 on gcc48 to 0.11 on gcc49, then forward again at gcc6. If gcc49 cannot use isl 0.14 why is gcc48 able to? I doubt this is right, but if it is there should be an explanatory comment, and I found none.

  2. gcc6 bumps to isl 0.17 only if compiling for RedoxOS. This probably means that gcc6 is able to use isl 0.17 everywhere. If not, there should have been a comment explaining why RedoxOS is special here.

  3. gcc49 on Darwin uses gccStdenv because "build fails on Darwin with clang"; surely if that is the case then that is true for gcc48 as well, no?

  4. gcc49 overrides cloog to v0.18.0, but gcc48 doesn't. Again, very weird, probably somebody meant to override gcc 4.9 and all older versions, not just that one particular version.

  5. when cross-compiling, gcc6,7,8 override stdenv to gcc7Stdenv because "gcc 10 is too strict to cross compile gcc <= 8" yet this override was not applied to any other versions of gcc which are "<= 8". It's also odd that gcc7Stdenv is used rather than gcc8Stdenv.

The best part about switch-on-version form is that oversights like the above make the code more verbose so they stand out. Fixing these likely-bugs will make the code simpler and shorter. In copy-paste-duplicated style the opposite is true: you get shorter code by forgetting to apply changes to all the versions that need the change! That's a perverse incentive.

This PR does not attempt to change or fix any of these behaviors. I have confirmed that it does not affect eval (same drv-hash) for all gcc versions on both x86_64-linux and x86_64-darwin.

Things done
  • no change to eval on:
    • x86_64-linux
    • aarch64-linux

Copy link
Author

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Below are the same bullet points found in the commit message, next to the (post-refactoring) code they refer to. This is probably easier to read.

Comment on lines 15429 to 15431
else if atLeast "6" then (if stdenv.targetPlatform.isRedox then isl_0_17 else isl_0_14)
else if atLeast "4.9" then isl_0_11
else /* "4.8" */ isl_0_14;
Copy link
Author

Choose a reason for hiding this comment

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

The ISL version we are using jumps backward from 0.14 on gcc48 to 0.11 on gcc49, then forward again at gcc6. If gcc49 cannot use isl 0.14 why is gcc48 able to? I doubt this is right, but if it is there should be an explanatory comment, and I found none.

Comment on lines 15428 to 15429
else if atLeast "7" then isl_0_17
else if atLeast "6" then (if stdenv.targetPlatform.isRedox then isl_0_17 else isl_0_14)
Copy link
Author

Choose a reason for hiding this comment

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

gcc6 bumps to isl 0.17 only if compiling for RedoxOS. This probably means that gcc6 is able to use isl 0.17 everywhere. If not, there should have been a comment explaining why RedoxOS is special here.

Comment on lines 15435 to 15436
# Build fails on Darwin with clang
stdenv = if stdenv.isDarwin then gccStdenv else stdenv;
Copy link
Author

Choose a reason for hiding this comment

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

gcc49 on Darwin uses gccStdenv because "build fails on Darwin with clang"; surely if that is the case then that is true for gcc48 as well, no?

Comment on lines 15440 to 15441
else if atLeast "4.9" then cloog_0_18_0
else /* 4.8 */ cloog;
Copy link
Author

Choose a reason for hiding this comment

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

gcc49 overrides cloog to v0.18.0, but gcc48 doesn't. Again, very weird, probably somebody meant to override gcc 4.9 and all older versions, not just that one particular version.

@ghost

This comment was marked as resolved.

@ghost ghost marked this pull request as ready for review July 15, 2023 09:53
Comment on lines 15442 to 15444
} // lib.optionalAttrs (atLeast "6" && !(atLeast "9")) {
# gcc 10 is too strict to cross compile gcc <= 8
stdenv = if (stdenv.targetPlatform != stdenv.buildPlatform) && stdenv.cc.isGNU then gcc7Stdenv else stdenv;
Copy link
Author

Choose a reason for hiding this comment

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

when cross-compiling, gcc6,7,8 override stdenv to gcc7Stdenv because "gcc 10 is too strict to cross compile gcc <= 8" yet this override was not applied to any other versions of gcc which are "<= 8". It's also odd that gcc7Stdenv is used rather than gcc8Stdenv.

Copy link
Contributor

@tjni tjni left a comment

Choose a reason for hiding this comment

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

I like the new pattern. LGTM.

This commit deduplicates the copy-pasted gcc mess in
pkgs/top-level/all-packages.txt, replacing it with a single
expression that branches based on the chosen version.

This refactoring has exposed several bizzare behaviors in our
historical gcc expressions.  These are almost certainly a result of
people reaching back and making a change only to the version they
care about, and neglecting adjacent versions.  These oddities went
un-noticed because in copy-paste-duplicated form it is nearly
impossible to notice what has happened.

When refactored into branch-on-version form, the irregularities jump
out at you:

1. The ISL version we are using jumps *backward* from 0.14 on gcc48
   to 0.11 on gcc49, then forward again at gcc6.  If gcc49 cannot
   use isl 0.14 why is gcc48 able to?  I doubt this is right, but if
   it is there should be an explanatory comment, and I found none.

2. gcc6 bumps to isl 0.17 only if compiling for RedoxOS. This
   probably means that gcc6 is able to use isl 0.17 everywhere. If
   not, there should have been a comment explaining why RedoxOS is
   special here.

3. gcc49 on Darwin uses gccStdenv because "build fails on Darwin
   with clang"; surely if that is the case then that is true for
   gcc48 as well, no?

4. gcc49 overrides cloog to v0.18.0, but gcc48 doesn't.  Again, very
   weird, probably somebody meant to override gcc 4.9 *and all older
   versions*, not just that one particular version.

5. when cross-compiling, gcc6,7,8 override stdenv to gcc7Stdenv
   because "gcc 10 is too strict to cross compile gcc <= 8" yet this
   override was not applied to any other versions of gcc which are
   "<= 8".  It's also odd that gcc7Stdenv is used rather than
   gcc8Stdenv.

The best part about switch-on-version form is that oversights like
the above *make the code more verbose* so they stand out.  Fixing
these likely-bugs will make the code simpler and shorter.  In
copy-paste-duplicated style the opposite is true: you get shorter
code by *forgetting* to apply changes to all the versions that need
the change!  That's a very perverse incentive.

This PR does not attempt to change or fix any of these behaviors.  I
have confirmed that it does not affect eval (same drv-hash) for all
gcc versions on both x86_64-linux and x86_64-darwin.
@ghost
Copy link
Author

ghost commented Jul 28, 2023

Fixed merge conflict.

@ghost ghost merged commit 0174928 into NixOS:master Jul 28, 2023
6 of 8 checks passed
@ghost ghost deleted the pr/gcc/toplevel branch August 14, 2023 12:10
@ghost ghost mentioned this pull request Aug 17, 2023
1 task
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant