diff --git a/gitlab-pages/docs/advanced/inline.md b/gitlab-pages/docs/advanced/inline.md new file mode 100644 index 000000000..ca61468b5 --- /dev/null +++ b/gitlab-pages/docs/advanced/inline.md @@ -0,0 +1,68 @@ +--- +id: inline +title: Inlining +--- + +import Syntax from '@theme/Syntax'; + +When compiling a contract in LIGO some functions get inlined in the place where +they are used and some are not. Inlining a function often results in larger +contracts and is therefore not aggressively done. + +In some cases you might want to override the default behaviour of LIGO and +force inlining. + + +## Inline attribute + +To force inlining you can use the inline attribute. + + + +```pascaligo +function fst(const p : nat * nat) : nat is p.0; attributes ["inline"] ; + +function main(const p : nat * nat; const s : nat * nat) : list(operation) * (nat * nat) is + ((list end : list(operation)), (fst(p.0,p.1), fst(s.1,s.0))) +``` + + + + +```cameligo +let fst (p: (nat * nat)) : nat = p.0 [@@inline] + +let main (p : (nat * nat)) (s : (nat * nat)) : (operation list * (nat * nat)) = + (([]: operation list), (fst (p.0, p.1), fst (s.1, s.0))) +``` + + + + +```reasonligo +[@inline] +let fst = (p: (nat, nat)) : nat => p[0] + +let main = (p : (nat, nat), s : (nat, nat)) : (list(operation), (nat, nat)) => + (([]: list(operation)), (fst((p[0], p[1])), fst((s[1], s[0])))) +``` + + + +Now if we measure the difference between inlining and without inlining, using +`ligo measure-contract name_of_contract.ligo `, we see the +following results: + + + + + + + + +
With inlining66 bytes
Without inlining170 bytes
+ +:::info +Note that these results can change due to ongoing work to optimize output of +the LIGO compiler. +::: \ No newline at end of file diff --git a/gitlab-pages/website/sidebars.json b/gitlab-pages/website/sidebars.json index 36cff21e1..9359599ec 100644 --- a/gitlab-pages/website/sidebars.json +++ b/gitlab-pages/website/sidebars.json @@ -19,7 +19,8 @@ "advanced/entrypoints-contracts", "advanced/include", "advanced/first-contract", - "advanced/michelson-and-ligo" + "advanced/michelson-and-ligo", + "advanced/inline" ], "Reference": [ "api/cli-commands", diff --git a/src/test/md_file_tests.ml b/src/test/md_file_tests.ml index 6114e9126..9e301919b 100644 --- a/src/test/md_file_tests.ml +++ b/src/test/md_file_tests.ml @@ -122,6 +122,7 @@ let md_files = [ "/gitlab-pages/docs/advanced/first-contract.md"; "/gitlab-pages/docs/advanced/entrypoints-contracts.md"; "/gitlab-pages/docs/advanced/timestamps-addresses.md"; + "/gitlab-pages/docs/advanced/inline.md"; "/gitlab-pages/docs/api/cli-commands.md"; "/gitlab-pages/docs/api/cheat-sheet.md"; "/gitlab-pages/docs/reference/list.md";