From 39fbb6fc2b841951629de5c6e52b984b8f4e36c7 Mon Sep 17 00:00:00 2001 From: Ziyang Liu Date: Fri, 6 Sep 2024 17:12:34 -0700 Subject: [PATCH] Add a compiler flag for the evaluateBuiltins pass (#6450) --- .../docs/delve-deeper/plutus-tx-compiler-options.md | 3 ++- .../20240906_143413_unsafeFixIO_evaluate_builtins.md | 4 ++++ plutus-tx-plugin/src/PlutusTx/Options.hs | 11 +++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 plutus-tx-plugin/changelog.d/20240906_143413_unsafeFixIO_evaluate_builtins.md diff --git a/doc/docusaurus/docs/delve-deeper/plutus-tx-compiler-options.md b/doc/docusaurus/docs/delve-deeper/plutus-tx-compiler-options.md index e77ca77edca..ca8d48cafb6 100644 --- a/doc/docusaurus/docs/delve-deeper/plutus-tx-compiler-options.md +++ b/doc/docusaurus/docs/delve-deeper/plutus-tx-compiler-options.md @@ -20,7 +20,7 @@ For each boolean option, you can add a `no-` prefix to switch it off, such as `n |Option|Value Type|Default|Description| |-|-|-|-| -|`conservative-optimisation`|Bool|False|When conservative optimisation is used, only the optimisations that never make the program worse (in terms of cost or size) are employed. Implies `no-relaxed-float-in`, `no-inline-constants`, and `preserve-logging`.| +|`conservative-optimisation`|Bool|False|When conservative optimisation is used, only the optimisations that never make the program worse (in terms of cost or size) are employed. Implies `no-relaxed-float-in`, `no-inline-constants`, `no-simplifier-evaluate-builtins`, and `preserve-logging`.| |`context-level`|Int|1|Set context level for error messages.| |`coverage-all`|Bool|False|Add all available coverage annotations in the trace output| |`coverage-boolean`|Bool|False|Add boolean coverage annotations in the trace output| @@ -41,6 +41,7 @@ For each boolean option, you can add a `no-` prefix to switch it off, such as `n |`relaxed-float-in`|Bool|True|Use a more aggressive float-in pass, which often leads to reduced costs but may occasionally lead to slightly increased costs. Implied by `no-conservative-optimisation`.| |`remove-trace`|Bool|False|Eliminate calls to `trace` from Plutus Core| |`simplifier-beta`|Bool|True|Run a simplification pass that performs beta transformations| +|`simplifier-evaluate-builtins`|Bool|True|Run a simplification pass that evaluates fully saturated builtin applications. Implied by `no-conservative-optimisation`.| |`simplifier-inline`|Bool|True|Run a simplification pass that performs inlining| |`simplifier-remove-dead-bindings`|Bool|True|Run a simplification pass that removes dead bindings| |`simplifier-unwrap-cancel`|Bool|True|Run a simplification pass that cancels unwrap/wrap pairs| diff --git a/plutus-tx-plugin/changelog.d/20240906_143413_unsafeFixIO_evaluate_builtins.md b/plutus-tx-plugin/changelog.d/20240906_143413_unsafeFixIO_evaluate_builtins.md new file mode 100644 index 00000000000..687e1a49937 --- /dev/null +++ b/plutus-tx-plugin/changelog.d/20240906_143413_unsafeFixIO_evaluate_builtins.md @@ -0,0 +1,4 @@ + +### Added + +- A compiler flag `simplifier-evaluate-builtins` that controls whether to run the simplifier pass that evaluates fully saturated builtins at compile time. diff --git a/plutus-tx-plugin/src/PlutusTx/Options.hs b/plutus-tx-plugin/src/PlutusTx/Options.hs index 4111f0e0a04..a1eca978553 100644 --- a/plutus-tx-plugin/src/PlutusTx/Options.hs +++ b/plutus-tx-plugin/src/PlutusTx/Options.hs @@ -157,8 +157,8 @@ pluginOptions = desc = "When conservative optimisation is used, only the optimisations that \ \never make the program worse (in terms of cost or size) are employed. \ - \Implies `no-relaxed-float-in`, `no-inline-constants`, and \ - \`preserve-logging`." + \Implies `no-relaxed-float-in`, `no-inline-constants`, \ + \`no-simplifier-evaluate-builtins`, and `preserve-logging`." in ( k , PluginOption typeRep @@ -171,10 +171,12 @@ pluginOptions = , Implication (== True) posPreserveLogging True , Implication (== True) posCaseOfCaseConservative True , Implication (== True) posInlineConstants False + , Implication (== True) posDoSimplifierEvaluateBuiltins False , Implication (== False) posRelaxedFloatin True , Implication (== False) posPreserveLogging False , Implication (== False) posCaseOfCaseConservative False , Implication (== False) posInlineConstants True + , Implication (== False) posDoSimplifierEvaluateBuiltins True ] ) , let k = "context-level" @@ -230,6 +232,11 @@ pluginOptions = , let k = "simplifier-beta" desc = "Run a simplification pass that performs beta transformations" in (k, PluginOption typeRep (setTrue k) posDoSimplifierBeta desc []) + , let k = "simplifier-evaluate-builtins" + desc = + "Run a simplification pass that evaluates fully saturated builtin applications. \ + \Implied by `no-conservative-optimisation`." + in (k, PluginOption typeRep (setTrue k) posDoSimplifierEvaluateBuiltins desc []) , let k = "simplifier-inline" desc = "Run a simplification pass that performs inlining" in (k, PluginOption typeRep (setTrue k) posDoSimplifierInline desc [])