handle one of the `ProveField` warnings (#5013)

* handle one of the `ProveField` warnings

When assigning between `ForkyHashedBeaconState`, suppress `ProveField`
warning, as `tgt.kind == src.kind` was already checked, but compiler
doesn't understand that (as we only `case tgt.kind`).

* Update beacon_chain/spec/forks.nim

* Update beacon_chain/spec/forks.nim
This commit is contained in:
Etan Kissling 2023-06-02 03:25:49 +02:00 committed by GitHub
parent d7890ac013
commit 005a35597f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 11 deletions

View File

@ -578,6 +578,21 @@ template withState*(x: ForkedHashedBeaconState, body: untyped): untyped =
template forkyState: untyped {.inject, used.} = x.phase0Data
body
template forky(
x: ForkedHashedBeaconState, kind: static ConsensusFork): untyped =
when kind == ConsensusFork.Deneb:
x.denebData
elif kind == ConsensusFork.Capella:
x.capellaData
elif kind == ConsensusFork.Bellatrix:
x.bellatrixData
elif kind == ConsensusFork.Altair:
x.altairData
elif kind == ConsensusFork.Phase0:
x.phase0Data
else:
static: raiseAssert "Unreachable"
template withEpochInfo*(x: ForkedEpochInfo, body: untyped): untyped =
case x.kind
of EpochInfoFork.Phase0:
@ -609,17 +624,10 @@ template withEpochInfo*(
func assign*(tgt: var ForkedHashedBeaconState, src: ForkedHashedBeaconState) =
if tgt.kind == src.kind:
case tgt.kind
of ConsensusFork.Deneb:
assign(tgt.denebData, src.denebData):
of ConsensusFork.Capella:
assign(tgt.capellaData, src.capellaData):
of ConsensusFork.Bellatrix:
assign(tgt.bellatrixData, src.bellatrixData):
of ConsensusFork.Altair:
assign(tgt.altairData, src.altairData):
of ConsensusFork.Phase0:
assign(tgt.phase0Data, src.phase0Data):
withState(tgt):
{.push warning[ProveField]: off.}
assign(forkyState, src.forky(consensusFork))
{.pop.}
else:
# Ensure case object and discriminator get updated simultaneously, even
# with nimOldCaseObjects. This is infrequent.