Inline true, false, and unit
Motivation and Context
This fixes a Michelson code clarity issue noticed by an auditor at Inference.
The stdlib declarations for true
, false
and unit
accidentally do not get the usual auto-inlining treatment for stdlib declarations, because (as noticed by @er433) they are actually represented as irrefutable pattern declarations at this stage (!)
This leads to slightly strange Michelson code, where PUSH bool True
happens at the beginning of the code and then DUP n
is used for each occurrence of true
.
Technically, for true
and false
this will usually be an optimization, because there are no TRUE
or FALSE
instructions and DUP n
will usually be 4 bytes while PUSH bool True
is 6 bytes. But:
- It is such a minor optimization that Michelson code clarity seems more important
- Users can implement the optimization themselves in the usual way if desired:
let shared_true = true
Here I fix the problem by just manually marking these declarations with [@inline]
...
Description
Inline true
, false
, and unit
, slightly improving clarity of generated Michelson code.
Component
-
compiler -
website -
webide -
vscode-plugin -
debugger
Types of changes
-
Bug fix (non-breaking change which fixes an issue) -
New feature (non-breaking change which adds functionality) -
Breaking change (fix or feature that would cause existing functionality to not work as expected) -
Performance improvement (non-breaking change that improves performance) -
None (change with no changelog)
Changelog
Checklist:
-
Changes follow the existing coding style (use dune @fmt
to check). -
Tests for the changes have been added (for bug fixes / feature). -
Documentation has been updated. -
Changelog description has been added (if appropriate). -
Start titles under ## Changelog
section with #### (if appropriate). -
There is no image or uploaded file in changelog -
Examples in changed behaviour have been added to the changelog (for breaking change / feature).