Skip to content

Commit

Permalink
Sway Reference: Section 9 Annotations inline (FuelLabs#4636)
Browse files Browse the repository at this point in the history
  • Loading branch information
Braqzen authored Jun 6, 2023
1 parent b1f2808 commit 336720a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/reference/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
- [Storage](./documentation/language/annotations/attributes/storage.md)
- [Payable](./documentation/language/annotations/attributes/payable.md)
- [Test](./documentation/language/annotations/attributes/test.md)
- [Inline](./documentation/language/annotations/attributes/inline.md)
- [Traits](./documentation/language/traits/index.md)
- [Generics](./documentation/language/generics/index.md)
- [Style Guide](./documentation/language/style-guide/index.md)
Expand Down
10 changes: 10 additions & 0 deletions docs/reference/src/code/language/annotations/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,13 @@ fn custom_revert_code() {
revert(42);
}
// ANCHOR_END: revert_code_test

// ANCHOR: never_inline
#[inline(never)]
fn foo() {}
// ANCHOR_END: never_inline

// ANCHOR: always_inline
#[inline(always)]
fn bar() {}
// ANCHOR_END: always_inline
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Inline

When making a call the compiler may generate code to call a function where it is defined or it may copy the function code (inline) to prevent additional code generation.

The Sway compiler automatically inlines functions based on internal heuristics; however, the `inline` attribute may be used to suggest, but not require, code generation or code copying.

## Generate code

To suggest code generation use the `never` keyword.

```sway
{{#include ../../../../code/language/annotations/src/main.sw:never_inline}}
```

## Copy code

To suggest code copy use the `always` keyword.

```sway
{{#include ../../../../code/language/annotations/src/main.sw:always_inline}}
```

0 comments on commit 336720a

Please sign in to comment.