Adjust and clarify handling of primop effects
Fixes #17900; fixes #20195. The existing "can_fail" and "has_side_effects" primop attributes that previously governed this were used in inconsistent and confusingly-documented ways, especially with regard to raising exceptions. This patch replaces them with a single "effect" attribute, which has four possible values: NoEffect, CanFail, ThrowsException, and ReadWriteEffect. These are described in Note [Classifying primop effects]. A substantial amount of related documentation has been re-drafted for clarity and accuracy. In the process of making this attribute format change for literally every primop, several existing mis-classifications were detected and corrected. One of these mis-classifications was tagToEnum#, which is now considered CanFail; this particular fix is known to cause a regression in performance for derived Enum instances. (See #23782.) Fixing this is left as future work. New primop attributes "cheap" and "work_free" were also added, and used in the corresponding parts of GHC.Core.Utils. In view of their actual meaning and uses, `primOpOkForSideEffects` and `exprOkForSideEffects` have been renamed to `primOpOkToDiscard` and `exprOkToDiscard`, respectively. Metric Increase: T21839c
Showing
- compiler/GHC/Builtin/PrimOps.hs 274 additions, 177 deletionscompiler/GHC/Builtin/PrimOps.hs
- compiler/GHC/Builtin/primops.txt.pp 404 additions, 311 deletionscompiler/GHC/Builtin/primops.txt.pp
- compiler/GHC/Core.hs 0 additions, 3 deletionscompiler/GHC/Core.hs
- compiler/GHC/Core/Opt/ConstantFold.hs 10 additions, 20 deletionscompiler/GHC/Core/Opt/ConstantFold.hs
- compiler/GHC/Core/Opt/FloatIn.hs 31 additions, 8 deletionscompiler/GHC/Core/Opt/FloatIn.hs
- compiler/GHC/Core/Opt/SetLevels.hs 1 addition, 1 deletioncompiler/GHC/Core/Opt/SetLevels.hs
- compiler/GHC/Core/Opt/Simplify/Iteration.hs 1 addition, 2 deletionscompiler/GHC/Core/Opt/Simplify/Iteration.hs
- compiler/GHC/Core/Utils.hs 77 additions, 86 deletionscompiler/GHC/Core/Utils.hs
- compiler/GHC/Types/Demand.hs 1 addition, 1 deletioncompiler/GHC/Types/Demand.hs
- compiler/Setup.hs 3 additions, 2 deletionscompiler/Setup.hs
- hadrian/src/Rules/Generate.hs 4 additions, 3 deletionshadrian/src/Rules/Generate.hs
- hadrian/src/Rules/Lint.hs 3 additions, 2 deletionshadrian/src/Rules/Lint.hs
- hadrian/src/Settings/Builders/GenPrimopCode.hs 3 additions, 2 deletionshadrian/src/Settings/Builders/GenPrimopCode.hs
- libraries/base/Unsafe/Coerce.hs 3 additions, 1 deletionlibraries/base/Unsafe/Coerce.hs
- testsuite/tests/ghc-api/PrimOpEffect_Sanity.hs 17 additions, 0 deletionstestsuite/tests/ghc-api/PrimOpEffect_Sanity.hs
- testsuite/tests/ghc-api/all.T 1 addition, 0 deletionstestsuite/tests/ghc-api/all.T
- utils/genprimopcode/AccessOps.hs 12 additions, 12 deletionsutils/genprimopcode/AccessOps.hs
- utils/genprimopcode/Lexer.x 9 additions, 0 deletionsutils/genprimopcode/Lexer.x
- utils/genprimopcode/Main.hs 27 additions, 14 deletionsutils/genprimopcode/Main.hs
- utils/genprimopcode/Parser.y 21 additions, 0 deletionsutils/genprimopcode/Parser.y
Loading
Please register or sign in to comment