Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove Nim 1.2 workarounds and TODOs #4533

Merged
merged 4 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions beacon_chain/beacon_chain_db.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1115,8 +1115,6 @@ proc getStateOnlyMutableValidators(
## not found at all, rollback will not be called
# TODO rollback is needed to deal with bug - use `noRollback` to ignore:
# https://github.com/nim-lang/Nim/issues/14126
# TODO RVO is inefficient for large objects:
# https://github.com/nim-lang/Nim/issues/13879

case store.getSnappySSZ(key, toBeaconStateNoImmutableValidators(output))
of GetResult.found:
Expand Down Expand Up @@ -1156,8 +1154,6 @@ proc getStateOnlyMutableValidators(
## not found at all, rollback will not be called
# TODO rollback is needed to deal with bug - use `noRollback` to ignore:
# https://github.com/nim-lang/Nim/issues/14126
# TODO RVO is inefficient for large objects:
# https://github.com/nim-lang/Nim/issues/13879

case store.getSZSSZ(key, toBeaconStateNoImmutableValidators(output))
of GetResult.found:
Expand Down Expand Up @@ -1195,8 +1191,6 @@ proc getStateOnlyMutableValidators(
## not found at all, rollback will not be called
# TODO rollback is needed to deal with bug - use `noRollback` to ignore:
# https://github.com/nim-lang/Nim/issues/14126
# TODO RVO is inefficient for large objects:
# https://github.com/nim-lang/Nim/issues/13879

case store.getSZSSZ(key, toBeaconStateNoImmutableValidators(output))
of GetResult.found:
Expand Down Expand Up @@ -1257,8 +1251,6 @@ proc getState*(
## not found at all, rollback will not be called
# TODO rollback is needed to deal with bug - use `noRollback` to ignore:
# https://github.com/nim-lang/Nim/issues/14126
# TODO RVO is inefficient for large objects:
# https://github.com/nim-lang/Nim/issues/13879
type T = type(output)

if not getStateOnlyMutableValidators(
Expand All @@ -1280,8 +1272,6 @@ proc getState*(
## not found at all, rollback will not be called
# TODO rollback is needed to deal with bug - use `noRollback` to ignore:
# https://github.com/nim-lang/Nim/issues/14126
# TODO RVO is inefficient for large objects:
# https://github.com/nim-lang/Nim/issues/13879
type T = type(output)
getStateOnlyMutableValidators(
db.immutableValidators, db.statesNoVal[T.toFork], key.data, output,
Expand Down
6 changes: 1 addition & 5 deletions beacon_chain/consensus_object_pools/attestation_pool.nim
Original file line number Diff line number Diff line change
Expand Up @@ -664,11 +664,7 @@ proc getAttestationsForBlock*(pool: var AttestationPool,
# Fast path for when all remaining candidates fit
if candidates.lenu64 < MAX_ATTESTATIONS: candidates.len - 1
else: maxIndex(candidates)
# TODO slot not used; replace with _ when
# https://github.com/nim-lang/Nim/issues/15972 and
# https://github.com/nim-lang/Nim/issues/16217 are
# fixed in Status's Nim.
(_, slot, entry, j) = candidates[candidate]
(_, _, entry, j) = candidates[candidate]

candidates.del(candidate) # careful, `del` reorders candidates

Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/eth1/eth1_monitor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ proc forkchoiceUpdated*(
withdrawals: mapIt(withdrawals.get, it.asEngineWithdrawal))))

# TODO can't be defined within exchangeTransitionConfiguration
proc `==`(x, y: Quantity): bool {.borrow, noSideEffect.}
func `==`(x, y: Quantity): bool {.borrow.}

type
EtcStatus {.pure.} = enum
Expand Down
48 changes: 23 additions & 25 deletions beacon_chain/spec/beacon_time.nim
Original file line number Diff line number Diff line change
Expand Up @@ -50,46 +50,44 @@ const

NANOSECONDS_PER_SLOT = SECONDS_PER_SLOT * 1_000_000_000'u64

# TODO when https://github.com/nim-lang/Nim/issues/14440 lands in Status's Nim,
# switch proc {.noSideEffect.} to func.
template ethTimeUnit*(typ: type) {.dirty.} =
proc `+`*(x: typ, y: uint64): typ {.borrow, noSideEffect.}
proc `-`*(x: typ, y: uint64): typ {.borrow, noSideEffect.}
proc `-`*(x: uint64, y: typ): typ {.borrow, noSideEffect.}
func `+`*(x: typ, y: uint64): typ {.borrow.}
func `-`*(x: typ, y: uint64): typ {.borrow.}
func `-`*(x: uint64, y: typ): typ {.borrow.}

# Not closed over type in question (Slot or Epoch)
proc `mod`*(x: typ, y: uint64): uint64 {.borrow, noSideEffect.}
proc `div`*(x: typ, y: uint64): uint64 {.borrow, noSideEffect.}
proc `div`*(x: uint64, y: typ): uint64 {.borrow, noSideEffect.}
proc `-`*(x: typ, y: typ): uint64 {.borrow, noSideEffect.}
func `mod`*(x: typ, y: uint64): uint64 {.borrow.}
func `div`*(x: typ, y: uint64): uint64 {.borrow.}
func `div`*(x: uint64, y: typ): uint64 {.borrow.}
func `-`*(x: typ, y: typ): uint64 {.borrow.}

iterator countdown*(a, b: typ, step: Positive = 1): typ =
# otherwise we use the signed version that breaks at the boundary
for i in countdown(distinctBase(a), distinctBase(b), step):
yield typ(i)

proc `*`*(x: typ, y: uint64): uint64 {.borrow, noSideEffect.}
func `*`*(x: typ, y: uint64): uint64 {.borrow.}

proc `+=`*(x: var typ, y: typ) {.borrow, noSideEffect.}
proc `+=`*(x: var typ, y: uint64) {.borrow, noSideEffect.}
proc `-=`*(x: var typ, y: typ) {.borrow, noSideEffect.}
proc `-=`*(x: var typ, y: uint64) {.borrow, noSideEffect.}
func `+=`*(x: var typ, y: typ) {.borrow.}
func `+=`*(x: var typ, y: uint64) {.borrow.}
func `-=`*(x: var typ, y: typ) {.borrow.}
func `-=`*(x: var typ, y: uint64) {.borrow.}

# Comparison operators
proc `<`*(x: typ, y: typ): bool {.borrow, noSideEffect.}
proc `<`*(x: typ, y: uint64): bool {.borrow, noSideEffect.}
proc `<`*(x: uint64, y: typ): bool {.borrow, noSideEffect.}
proc `<=`*(x: typ, y: typ): bool {.borrow, noSideEffect.}
proc `<=`*(x: typ, y: uint64): bool {.borrow, noSideEffect.}
proc `<=`*(x: uint64, y: typ): bool {.borrow, noSideEffect.}
func `<`*(x: typ, y: typ): bool {.borrow.}
func `<`*(x: typ, y: uint64): bool {.borrow.}
func `<`*(x: uint64, y: typ): bool {.borrow.}
func `<=`*(x: typ, y: typ): bool {.borrow.}
func `<=`*(x: typ, y: uint64): bool {.borrow.}
func `<=`*(x: uint64, y: typ): bool {.borrow.}

proc `==`*(x: typ, y: typ): bool {.borrow, noSideEffect.}
proc `==`*(x: typ, y: uint64): bool {.borrow, noSideEffect.}
proc `==`*(x: uint64, y: typ): bool {.borrow, noSideEffect.}
func `==`*(x: typ, y: typ): bool {.borrow.}
func `==`*(x: typ, y: uint64): bool {.borrow.}
func `==`*(x: uint64, y: typ): bool {.borrow.}

# Nim integration
proc `$`*(x: typ): string {.borrow, noSideEffect.}
proc hash*(x: typ): Hash {.borrow, noSideEffect.}
func `$`*(x: typ): string {.borrow.}
func hash*(x: typ): Hash {.borrow.}

template asUInt64*(v: typ): uint64 = distinctBase(v)
template shortLog*(v: typ): auto = distinctBase(v)
Expand Down
3 changes: 1 addition & 2 deletions beacon_chain/spec/helpers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,8 @@ func compute_domain*(
genesis_validators_root: Eth2Digest = ZERO_HASH): Eth2Domain =
## Return the domain for the ``domain_type`` and ``fork_version``.
#
# TODO Can't be used as part of a const/static expression:
# TODO toOpenArray can't be used from JavaScript backend
# https://github.com/nim-lang/Nim/issues/15952
# https://github.com/nim-lang/Nim/issues/19969
let fork_data_root =
compute_fork_data_root(fork_version, genesis_validators_root)
result[0..3] = domain_type.data
Expand Down