@@ -8,7 +8,7 @@ Inline Assembly
8
8
9
9
10
10
You can interleave Solidity statements with inline assembly in a language close
11
- to the one of the Ethereum virtual machine . This gives you more fine-grained control,
11
+ to the one of the Ethereum Virtual Machine . This gives you more fine-grained control,
12
12
which is especially useful when you are enhancing the language by writing libraries.
13
13
14
14
The language used for inline assembly in Solidity is called :ref: `Yul <yul >`
@@ -126,15 +126,15 @@ You can access Solidity variables and other identifiers by using their name.
126
126
Local variables of value type are directly usable in inline assembly.
127
127
They can both be read and assigned to.
128
128
129
- Local variables that refer to memory evaluate to the address of the variable in memory not the value itself.
129
+ Local variables that refer to memory evaluate to the address of the variable in memory, not the value itself.
130
130
Such variables can also be assigned to, but note that an assignment will only change the pointer and not the data
131
131
and that it is your responsibility to respect Solidity's memory management.
132
132
See :ref: `Conventions in Solidity <conventions-in-solidity >`.
133
133
134
134
Similarly, local variables that refer to statically-sized calldata arrays or calldata structs
135
135
evaluate to the address of the variable in calldata, not the value itself.
136
- The variable can also be assigned a new offset, but note that no validation to ensure that
137
- the variable will not point beyond ``calldatasize() `` is performed .
136
+ The variable can also be assigned a new offset, but note that no validation is performed to ensure that
137
+ the variable will not point beyond ``calldatasize() ``.
138
138
139
139
For external function pointers the address and the function selector can be
140
140
accessed using ``x.address `` and ``x.selector ``.
@@ -205,7 +205,7 @@ Local Solidity variables are available for assignments, for example:
205
205
``assembly { signextend(<num_bytes_of_x_minus_one>, x) } ``
206
206
207
207
208
- Since Solidity 0.6.0 the name of a inline assembly variable may not
208
+ Since Solidity 0.6.0, the name of a inline assembly variable may not
209
209
shadow any declaration visible in the scope of the inline assembly block
210
210
(including variable, contract and function declarations).
211
211
@@ -253,7 +253,7 @@ starting from where this pointer points at and update it.
253
253
There is no guarantee that the memory has not been used before and thus
254
254
you cannot assume that its contents are zero bytes.
255
255
There is no built-in mechanism to release or free allocated memory.
256
- Here is an assembly snippet you can use for allocating memory that follows the process outlined above
256
+ Here is an assembly snippet you can use for allocating memory that follows the process outlined above:
257
257
258
258
.. code-block :: yul
259
259
@@ -276,7 +276,7 @@ first slot of the array and followed by the array elements.
276
276
277
277
.. warning ::
278
278
Statically-sized memory arrays do not have a length field, but it might be added later
279
- to allow better convertibility between statically- and dynamically-sized arrays, so
279
+ to allow better convertibility between statically and dynamically-sized arrays; so,
280
280
do not rely on this.
281
281
282
282
Memory Safety
@@ -290,7 +290,7 @@ perform additional memory optimizations, if it can rely on certain assumptions a
290
290
While we recommend to always respect Solidity's memory model, inline assembly allows you to use memory
291
291
in an incompatible way. Therefore, moving stack variables to memory and additional memory optimizations are,
292
292
by default, disabled in the presence of any inline assembly block that contains a memory operation or assigns
293
- to solidity variables in memory.
293
+ to Solidity variables in memory.
294
294
295
295
However, you can specifically annotate an assembly block to indicate that it in fact respects Solidity's memory
296
296
model as follows:
@@ -346,7 +346,7 @@ If the memory operations use a length of zero, it is also fine to just use any o
346
346
}
347
347
348
348
Note that not only memory operations in inline assembly itself can be memory-unsafe, but also assignments to
349
- solidity variables of reference type in memory. For example the following is not memory-safe:
349
+ Solidity variables of reference type in memory. For example the following is not memory-safe:
350
350
351
351
.. code-block :: solidity
352
352
@@ -356,17 +356,16 @@ solidity variables of reference type in memory. For example the following is not
356
356
}
357
357
x[0x20] = 0x42;
358
358
359
- Inline assembly that neither involves any operations that access memory nor assigns to any solidity variables
359
+ Inline assembly that neither involves any operations that access memory nor assigns to any Solidity variables
360
360
in memory is automatically considered memory-safe and does not need to be annotated.
361
361
362
362
.. warning ::
363
363
It is your responsibility to make sure that the assembly actually satisfies the memory model. If you annotate
364
364
an assembly block as memory-safe, but violate one of the memory assumptions, this **will ** lead to incorrect and
365
365
undefined behaviour that cannot easily be discovered by testing.
366
366
367
- The annotation was introduced in version 0.8.13 and is not supported by older compilers.
368
367
In case you are developing a library that is meant to be compatible across multiple versions
369
- of Solidity, you can use a special Natspec comment that has the same effect but is ignored in older versions :
368
+ of Solidity, you can use a special comment to annotate an assembly block as memory-safe :
370
369
371
370
.. code-block :: solidity
372
371
@@ -375,5 +374,5 @@ of Solidity, you can use a special Natspec comment that has the same effect but
375
374
...
376
375
}
377
376
378
- Note that we will disallow the annotation via comment in a future breaking release, so if you are not concerned with
377
+ Note that we will disallow the annotation via comment in a future breaking release; so, if you are not concerned with
379
378
backwards-compatibility with older compiler versions, prefer using the dialect string.
0 commit comments