From 005a35597f70c7f97491899daf8744c595da2b15 Mon Sep 17 00:00:00 2001 From: Etan Kissling Date: Fri, 2 Jun 2023 03:25:49 +0200 Subject: [PATCH] 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 --- beacon_chain/spec/forks.nim | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/beacon_chain/spec/forks.nim b/beacon_chain/spec/forks.nim index b1dbc97d6..cf79cf4e3 100644 --- a/beacon_chain/spec/forks.nim +++ b/beacon_chain/spec/forks.nim @@ -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.