mirror of
https://github.com/status-im/nim-serialization.git
synced 2025-01-27 20:24:50 +00:00
readFieldIMPL workaround when orc enabled
This commit is contained in:
parent
845bed4478
commit
bc46b4c1c1
@ -1,4 +1,5 @@
|
|||||||
import
|
import
|
||||||
|
std/typetraits,
|
||||||
stew/shims/macros, stew/objects,
|
stew/shims/macros, stew/objects,
|
||||||
./errors
|
./errors
|
||||||
|
|
||||||
@ -183,10 +184,20 @@ template GetFieldType(FT: type FieldTag): type =
|
|||||||
typeof field(declval(FT.RecordType), FT.fieldName)
|
typeof field(declval(FT.RecordType), FT.fieldName)
|
||||||
|
|
||||||
template readFieldIMPL[Reader](field: type FieldTag,
|
template readFieldIMPL[Reader](field: type FieldTag,
|
||||||
reader: var Reader): untyped =
|
reader: var Reader): auto =
|
||||||
mixin readValue
|
mixin readValue
|
||||||
|
type FieldType = GetFieldType(field)
|
||||||
{.gcsafe.}: # needed by Nim-1.6
|
{.gcsafe.}: # needed by Nim-1.6
|
||||||
reader.readValue GetFieldType(field)
|
# TODO: The `FieldType` coercion below is required to deal
|
||||||
|
# with a nim bug caused by the distinct `ssz.List` type.
|
||||||
|
# It seems to break the generics cache mechanism, which
|
||||||
|
# leads to an incorrect return type being reported from
|
||||||
|
# the `readFieldIMPL` function.
|
||||||
|
|
||||||
|
# additional notes: putting the FieldType coercion in
|
||||||
|
# `makeFieldReadersTable` will cause problems when orc enabled
|
||||||
|
# hence, move it here
|
||||||
|
FieldType reader.readValue(FieldType)
|
||||||
|
|
||||||
template writeFieldIMPL*[Writer](writer: var Writer,
|
template writeFieldIMPL*[Writer](writer: var Writer,
|
||||||
fieldTag: type FieldTag,
|
fieldTag: type FieldTag,
|
||||||
@ -214,20 +225,8 @@ proc makeFieldReadersTable(RecordType, ReaderType: distinct type,
|
|||||||
when RecordType is tuple:
|
when RecordType is tuple:
|
||||||
reader.readValue obj[i]
|
reader.readValue obj[i]
|
||||||
else:
|
else:
|
||||||
# TODO: The `FieldType` coercion below is required to deal
|
|
||||||
# with a nim bug caused by the distinct `ssz.List` type.
|
|
||||||
# It seems to break the generics cache mechanism, which
|
|
||||||
# leads to an incorrect return type being reported from
|
|
||||||
# the `readFieldIMPL` function.
|
|
||||||
field(obj, realFieldName) = FieldType reader.readValue(FieldType)
|
|
||||||
|
|
||||||
when false:
|
|
||||||
# somehow this code result in crash with nim orc enabled.
|
|
||||||
# that's why we use reader.readValue
|
|
||||||
# removing FieldType coercion also prevent crash, but see above comment
|
|
||||||
type F = FieldTag[RecordType, realFieldName]
|
type F = FieldTag[RecordType, realFieldName]
|
||||||
field(obj, realFieldName) = FieldType readFieldIMPL(F, reader)
|
field(obj, realFieldName) = readFieldIMPL(F, reader)
|
||||||
|
|
||||||
except SerializationError as err:
|
except SerializationError as err:
|
||||||
raise err
|
raise err
|
||||||
except CatchableError as err:
|
except CatchableError as err:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user