Merge remote-tracking branch 'origin/develop' into breaking

This commit is contained in:
chriseth committed 2020-12-01 10:50:13 +01:00
commit 6de7eaba95
81 files changed
+1740 -775

No files matched your search

+17 -17
View File
@@ -1098,10 +1098,9 @@ string YulUtilFunctions::extractByteArrayLengthFunction()
});
}
std::string YulUtilFunctions::resizeDynamicArrayFunction(ArrayType const& _type)
std::string YulUtilFunctions::resizeArrayFunction(ArrayType const& _type)
{
solAssert(_type.location() == DataLocation::Storage, "");
solAssert(_type.isDynamicallySized(), "");
solUnimplementedAssert(_type.baseType()->storageBytes() <= 32, "...");
if (_type.isByteArray())
@@ -1117,8 +1116,10 @@ std::string YulUtilFunctions::resizeDynamicArrayFunction(ArrayType const& _type)
let oldLen := <fetchLength>(array)
// Store new length
sstore(array, newLen)
<?isDynamic>
// Store new length
sstore(array, newLen)
</isDynamic>
// Size was reduced, clear end of array
if lt(newLen, oldLen) {
@@ -1139,6 +1140,7 @@ std::string YulUtilFunctions::resizeDynamicArrayFunction(ArrayType const& _type)
("functionName", functionName)
("panic", panicFunction(PanicCode::ResourceError))
("fetchLength", arrayLengthFunction(_type))
("isDynamic", _type.isDynamicallySized())
("convertToSize", arrayConvertLengthToSize(_type))
("dataPosition", arrayDataAreaFunction(_type))
("clearStorageRange", clearStorageRangeFunction(*_type.baseType()))
@@ -1523,7 +1525,7 @@ string YulUtilFunctions::clearStorageArrayFunction(ArrayType const& _type)
)")
("functionName", functionName)
("dynamic", _type.isDynamicallySized())
("resizeArray", _type.isDynamicallySized() ? resizeDynamicArrayFunction(_type) : "")
("resizeArray", _type.isDynamicallySized() ? resizeArrayFunction(_type) : "")
(
"clearRange",
clearStorageRangeFunction(
@@ -1595,6 +1597,9 @@ string YulUtilFunctions::copyArrayToStorageFunction(ArrayType const& _fromType,
*_fromType.copyForLocation(_toType.location(), _toType.isPointer()) == dynamic_cast<ReferenceType const&>(_toType),
""
);
if (!_toType.isDynamicallySized())
solAssert(!_fromType.isDynamicallySized() && _fromType.length() <= _toType.length(), "");
if (_fromType.isByteArray())
return copyByteArrayToStorageFunction(_fromType, _toType);
if (_fromType.dataStoredIn(DataLocation::Storage) && _toType.baseType()->isValueType())
@@ -1606,9 +1611,8 @@ string YulUtilFunctions::copyArrayToStorageFunction(ArrayType const& _fromType,
function <functionName>(slot, value<?isFromDynamicCalldata>, len</isFromDynamicCalldata>) {
<?fromStorage> if eq(slot, value) { leave } </fromStorage>
let length := <arrayLength>(value<?isFromDynamicCalldata>, len</isFromDynamicCalldata>)
<?isToDynamic>
<resizeArray>(slot, length)
</isToDynamic>
<resizeArray>(slot, length)
let srcPtr := <srcDataLocation>(value)
@@ -1662,7 +1666,6 @@ string YulUtilFunctions::copyArrayToStorageFunction(ArrayType const& _fromType,
bool fromMemory = _fromType.dataStoredIn(DataLocation::Memory);
templ("fromMemory", fromMemory);
templ("fromCalldata", fromCalldata);
templ("isToDynamic", _toType.isDynamicallySized());
templ("srcDataLocation", arrayDataAreaFunction(_fromType));
if (fromCalldata)
{
@@ -1671,8 +1674,7 @@ string YulUtilFunctions::copyArrayToStorageFunction(ArrayType const& _fromType,
if (_fromType.baseType()->isDynamicallyEncoded())
templ("accessCalldataTail", accessCalldataTailFunction(*_fromType.baseType()));
}
if (_toType.isDynamicallySized())
templ("resizeArray", resizeDynamicArrayFunction(_toType));
templ("resizeArray", resizeArrayFunction(_toType));
templ("arrayLength",arrayLengthFunction(_fromType));
templ("isValueType", _fromType.baseType()->isValueType());
templ("dstDataLocation", arrayDataAreaFunction(_toType));
@@ -1791,6 +1793,8 @@ string YulUtilFunctions::copyValueArrayStorageToStorageFunction(ArrayType const&
solAssert(_fromType.dataStoredIn(DataLocation::Storage) && _toType.baseType()->isValueType(), "");
solAssert(_toType.dataStoredIn(DataLocation::Storage), "");
solUnimplementedAssert(_fromType.storageStride() == _toType.storageStride(), "");
string functionName = "copy_array_to_storage_from_" + _fromType.identifier() + "_to_" + _toType.identifier();
return m_functionCollector.createFunction(functionName, [&](){
Whiskers templ(R"(
@@ -1799,9 +1803,7 @@ string YulUtilFunctions::copyValueArrayStorageToStorageFunction(ArrayType const&
let length := <arrayLength>(src)
// Make sure array length is sane
if gt(length, 0xffffffffffffffff) { <panic>() }
<?isToDynamic>
<resizeArray>(dst, length)
</isToDynamic>
<resizeArray>(dst, length)
let srcPtr := <srcDataLocation>(src)
@@ -1821,9 +1823,7 @@ string YulUtilFunctions::copyValueArrayStorageToStorageFunction(ArrayType const&
if (_fromType.dataStoredIn(DataLocation::Storage))
solAssert(!_fromType.isValueType(), "");
templ("functionName", functionName);
templ("isToDynamic", _toType.isDynamicallySized());
if (_toType.isDynamicallySized())
templ("resizeArray", resizeDynamicArrayFunction(_toType));
templ("resizeArray", resizeArrayFunction(_toType));
templ("arrayLength",arrayLengthFunction(_fromType));
templ("panic", panicFunction(PanicCode::ResourceError));
templ("srcDataLocation", arrayDataAreaFunction(_fromType));