mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge remote-tracking branch 'origin/develop' into breaking
This commit is contained in:
+4
-2
@@ -313,7 +313,8 @@ Furthermore, if the assembly block assigns to Solidity variables in memory, you
|
||||
the Solidity variables only access these memory ranges.
|
||||
|
||||
Since this is mainly about the optimizer, these restrictions still need to be followed, even if the assembly block
|
||||
reverts or terminates. As an example, the following assembly snippet is not memory safe:
|
||||
reverts or terminates. As an example, the following assembly snippet is not memory safe, because the value of
|
||||
``returndatasize()`` may exceed the 64 byte scratch space:
|
||||
|
||||
.. code-block:: solidity
|
||||
|
||||
@@ -322,7 +323,8 @@ reverts or terminates. As an example, the following assembly snippet is not memo
|
||||
revert(0, returndatasize())
|
||||
}
|
||||
|
||||
But the following is:
|
||||
On the other hand, the following code *is* memory safe, because memory beyond the location pointed to by the
|
||||
free memory pointer can safely be used as temporary scratch space:
|
||||
|
||||
.. code-block:: solidity
|
||||
|
||||
|
||||
@@ -6,12 +6,15 @@
|
||||
Abstract Contracts
|
||||
******************
|
||||
|
||||
Contracts need to be marked as abstract when at least one of their functions is not implemented.
|
||||
Contracts may be marked as abstract even though all functions are implemented.
|
||||
Contracts must be marked as abstract when at least one of their functions is not implemented or when
|
||||
they do not provide arguments for all of their base contract constructors.
|
||||
Even if this is not the case, a contract may still be marked abstract, such as when you do not intend
|
||||
for the contract to be created directly. Abstract contracts are similar to :ref:`interfaces` but an
|
||||
interface is more limited in what it can declare.
|
||||
|
||||
This can be done by using the ``abstract`` keyword as shown in the following example. Note that this contract needs to be
|
||||
defined as abstract, because the function ``utterance()`` was defined, but no implementation was
|
||||
provided (no implementation body ``{ }`` was given).
|
||||
An abstract contract is declared using the ``abstract`` keyword as shown in the following example.
|
||||
Note that this contract needs to be defined as abstract, because the function ``utterance()`` is declared,
|
||||
but no implementation was provided (no implementation body ``{ }`` was given).
|
||||
|
||||
.. code-block:: solidity
|
||||
|
||||
|
||||
@@ -76,9 +76,9 @@ Details are given in the following example.
|
||||
}
|
||||
|
||||
|
||||
// Multiple inheritance is possible. Note that `owned` is
|
||||
// Multiple inheritance is possible. Note that `Owned` is
|
||||
// also a base class of `Destructible`, yet there is only a single
|
||||
// instance of `owned` (as for virtual inheritance in C++).
|
||||
// instance of `Owned` (as for virtual inheritance in C++).
|
||||
contract Named is Owned, Destructible {
|
||||
constructor(bytes32 name) {
|
||||
Config config = Config(0xD5f9D8D94886E70b06E474c3fB14Fd43E2f23970);
|
||||
@@ -443,7 +443,7 @@ cannot be assigned valid values from outside but only through the constructors o
|
||||
``internal`` or ``public``.
|
||||
|
||||
|
||||
.. index:: ! base;constructor
|
||||
.. index:: ! base;constructor, inheritance list, contract;abstract, abstract contract
|
||||
|
||||
Arguments for Base Constructors
|
||||
===============================
|
||||
@@ -467,11 +467,20 @@ derived contracts need to specify all of them. This can be done in two ways:
|
||||
constructor() {}
|
||||
}
|
||||
|
||||
// or through a "modifier" of the derived constructor.
|
||||
// or through a "modifier" of the derived constructor...
|
||||
contract Derived2 is Base {
|
||||
constructor(uint y) Base(y * y) {}
|
||||
}
|
||||
|
||||
// or declare abstract...
|
||||
abstract contract Derived3 is Base {
|
||||
}
|
||||
|
||||
// and have the next concrete derived contract initialize it.
|
||||
contract DerivedFromDerived is Derived3 {
|
||||
constructor() Base(10 + 10) {}
|
||||
}
|
||||
|
||||
One way is directly in the inheritance list (``is Base(7)``). The other is in
|
||||
the way a modifier is invoked as part of
|
||||
the derived constructor (``Base(y * y)``). The first way to
|
||||
@@ -484,7 +493,12 @@ inheritance list or in modifier-style in the derived constructor.
|
||||
Specifying arguments in both places is an error.
|
||||
|
||||
If a derived contract does not specify the arguments to all of its base
|
||||
contracts' constructors, it will be abstract.
|
||||
contracts' constructors, it must be declared abstract. In that case, when
|
||||
another contract derives from it, that other contract's inheritance list
|
||||
or constructor must provide the necessary parameters
|
||||
for all base classes that haven't had their parameters specified (otherwise,
|
||||
that other contract must be declared abstract as well). For example, in the above
|
||||
code snippet, see ``Derived3`` and ``DerivedFromDerived``.
|
||||
|
||||
.. index:: ! inheritance;multiple, ! linearization, ! C3 linearization
|
||||
|
||||
|
||||
@@ -475,7 +475,7 @@ For example ``pragma solidity >=0.4.0 <0.9.0;``.
|
||||
Running Documentation Tests
|
||||
---------------------------
|
||||
|
||||
Make sure your contributions pass our documentation tests by running ``./scripts/docs.sh`` that installs dependencies
|
||||
Make sure your contributions pass our documentation tests by running ``./docs/docs.sh`` that installs dependencies
|
||||
needed for documentation and checks for any problems such as broken links or syntax issues.
|
||||
|
||||
Solidity Language Design
|
||||
|
||||
@@ -283,7 +283,7 @@ which only need to be created if there is a dispute.
|
||||
salt,
|
||||
keccak256(abi.encodePacked(
|
||||
type(D).creationCode,
|
||||
arg
|
||||
abi.encode(arg)
|
||||
))
|
||||
)))));
|
||||
|
||||
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Bash script to build the Solidity Sphinx documentation locally.
|
||||
#
|
||||
# The documentation for solidity is hosted at:
|
||||
#
|
||||
# https://docs.soliditylang.org
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
# This file is part of solidity.
|
||||
#
|
||||
# solidity is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# solidity is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with solidity. If not, see <http://www.gnu.org/licenses/>
|
||||
#
|
||||
# (c) 2016 solidity contributors.
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
script_dir="$(dirname "$0")"
|
||||
|
||||
cd "${script_dir}"
|
||||
pip3 install -r requirements.txt --upgrade --upgrade-strategy eager
|
||||
sphinx-build -nW -b html -d _build/doctrees . _build/html
|
||||
@@ -396,27 +396,34 @@ returns that code when executed.
|
||||
Gas
|
||||
===
|
||||
|
||||
Upon creation, each transaction is charged with a certain amount of **gas**,
|
||||
whose purpose is to limit the amount of work that is needed to execute
|
||||
the transaction and to pay for this execution at the same time. While the EVM executes the
|
||||
Upon creation, each transaction is charged with a certain amount of **gas**
|
||||
that has to be paid for by the originator of the transaction (``tx.origin``).
|
||||
While the EVM executes the
|
||||
transaction, the gas is gradually depleted according to specific rules.
|
||||
|
||||
The **gas price** is a value set by the creator of the transaction, who
|
||||
has to pay ``gas_price * gas`` up front from the sending account.
|
||||
If some gas is left after the execution, it is refunded to the creator in the same way.
|
||||
|
||||
If the gas is used up at any point (i.e. it would be negative),
|
||||
an out-of-gas exception is triggered, which reverts all modifications
|
||||
an out-of-gas exception is triggered, which ends execution and reverts all modifications
|
||||
made to the state in the current call frame.
|
||||
|
||||
This mechanism incentivizes economical use of EVM execution time
|
||||
and also compensates EVM executors (i.e. miners / stakers) for their work.
|
||||
Since each block has a maximum amount of gas, it also limits the amount
|
||||
of work needed to validate a block.
|
||||
|
||||
The **gas price** is a value set by the originator of the transaction, who
|
||||
has to pay ``gas_price * gas`` up front to the EVM executor.
|
||||
If some gas is left after execution, it is refunded to the transaction originator.
|
||||
In case of an exception that reverts changes, already used up gas is not refunded.
|
||||
|
||||
Since EVM executors can choose to include a transaction or not,
|
||||
transaction senders cannot abuse the system by setting a low gas price.
|
||||
|
||||
.. index:: ! storage, ! memory, ! stack
|
||||
|
||||
Storage, Memory and the Stack
|
||||
=============================
|
||||
|
||||
The Ethereum Virtual Machine has three areas where it can store data-
|
||||
storage, memory and the stack, which are explained in the following
|
||||
paragraphs.
|
||||
The Ethereum Virtual Machine has three areas where it can store data:
|
||||
storage, memory and the stack.
|
||||
|
||||
Each account has a data area called **storage**, which is persistent between function calls
|
||||
and transactions.
|
||||
@@ -504,7 +511,7 @@ Delegatecall / Callcode and Libraries
|
||||
|
||||
There exists a special variant of a message call, named **delegatecall**
|
||||
which is identical to a message call apart from the fact that
|
||||
the code at the target address is executed in the context of the calling
|
||||
the code at the target address is executed in the context (i.e. at the address) of the calling
|
||||
contract and ``msg.sender`` and ``msg.value`` do not change their values.
|
||||
|
||||
This means that a contract can dynamically load code from a different
|
||||
|
||||
@@ -119,7 +119,7 @@ Iterable Mappings
|
||||
You cannot iterate over mappings, i.e. you cannot enumerate their keys.
|
||||
It is possible, though, to implement a data structure on
|
||||
top of them and iterate over that. For example, the code below implements an
|
||||
``IterableMapping`` library that the ``User`` contract then adds data too, and
|
||||
``IterableMapping`` library that the ``User`` contract then adds data to, and
|
||||
the ``sum`` function iterates over to sum all the values.
|
||||
|
||||
.. code-block:: solidity
|
||||
|
||||
@@ -463,7 +463,7 @@ There is no additional semantic meaning added to a number literal containing und
|
||||
the underscores are ignored.
|
||||
|
||||
Number literal expressions retain arbitrary precision until they are converted to a non-literal type (i.e. by
|
||||
using them together with anything else than a number literal expression (like boolean literals) or by explicit conversion).
|
||||
using them together with anything other than a number literal expression (like boolean literals) or by explicit conversion).
|
||||
This means that computations do not overflow and divisions do not truncate
|
||||
in number literal expressions.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user