`ProveField` cleanups in `forks` (#5049)

* `ProveField` cleanups in `forks`

Some more cleanup for `ProveField` warnings in `forks` module.
Note that `ProveField` is disabled by default in makefile, but sometimes
these pop up when doing a regular `nim c`, and cleaning these may allow
enabling the warning in some future.

* use syntax that works if passed to multiple args of call
This commit is contained in:
Etan Kissling 2023-06-12 14:03:59 +02:00 committed by GitHub
parent 22208836b1
commit 40415ab86c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 9 deletions

View File

@ -622,16 +622,18 @@ template withEpochInfo*(
template info: untyped {.inject.} = x.altairData template info: untyped {.inject.} = x.altairData
body body
{.push warning[ProveField]:off.}
func assign*(tgt: var ForkedHashedBeaconState, src: ForkedHashedBeaconState) = func assign*(tgt: var ForkedHashedBeaconState, src: ForkedHashedBeaconState) =
if tgt.kind == src.kind: if tgt.kind == src.kind:
withState(tgt): withState(tgt):
{.push warning[ProveField]: off.} template forkyTgt: untyped = forkyState
assign(forkyState, src.forky(consensusFork)) template forkySrc: untyped = src.forky(consensusFork)
{.pop.} assign(forkyTgt, forkySrc)
else: else:
# Ensure case object and discriminator get updated simultaneously, even # Ensure case object and discriminator get updated simultaneously, even
# with nimOldCaseObjects. This is infrequent. # with nimOldCaseObjects. This is infrequent.
tgt = src tgt = src
{.pop.}
template getStateField*(x: ForkedHashedBeaconState, y: untyped): untyped = template getStateField*(x: ForkedHashedBeaconState, y: untyped): untyped =
# The use of `unsafeAddr` avoids excessive copying in certain situations, e.g., # The use of `unsafeAddr` avoids excessive copying in certain situations, e.g.,
@ -639,18 +641,16 @@ template getStateField*(x: ForkedHashedBeaconState, y: untyped): untyped =
# for index, validator in getStateField(stateData.data, validators): # for index, validator in getStateField(stateData.data, validators):
# ``` # ```
# Without `unsafeAddr`, the `validators` list would be copied to a temporary variable. # Without `unsafeAddr`, the `validators` list would be copied to a temporary variable.
(case x.kind (block:
of ConsensusFork.Deneb: unsafeAddr x.denebData.data.y withState(x): unsafeAddr forkyState.data.y)[]
of ConsensusFork.Capella: unsafeAddr x.capellaData.data.y
of ConsensusFork.Bellatrix: unsafeAddr x.bellatrixData.data.y
of ConsensusFork.Altair: unsafeAddr x.altairData.data.y
of ConsensusFork.Phase0: unsafeAddr x.phase0Data.data.y)[]
func getStateRoot*(x: ForkedHashedBeaconState): Eth2Digest = func getStateRoot*(x: ForkedHashedBeaconState): Eth2Digest =
withState(x): forkyState.root withState(x): forkyState.root
{.push warning[ProveField]:off.} # https://github.com/nim-lang/Nim/issues/22060
func setStateRoot*(x: var ForkedHashedBeaconState, root: Eth2Digest) = func setStateRoot*(x: var ForkedHashedBeaconState, root: Eth2Digest) =
withState(x): forkyState.root = root withState(x): forkyState.root = root
{.pop.}
func consensusForkAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): ConsensusFork = func consensusForkAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): ConsensusFork =
## Return the current fork for the given epoch. ## Return the current fork for the given epoch.