remove {.inline.} pragmas (#2033)

* remove {.inline.} pragmas

* re-add inline on bitseqs functions and tweak inlining threshold

* remove macOS/LLVM inlining setting; revert non-init/module-local/tests inline pragma removal
This commit is contained in:
tersec 2020-11-20 11:00:22 +01:00 committed by GitHub
parent 883e18da81
commit 1d7fb2ed0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 38 additions and 36 deletions

View File

@ -770,7 +770,7 @@ proc start(m: Eth1Monitor, delayBeforeStart: Duration) =
fatal "Fatal exception reached", err = runFut.error.msg
quit 1
proc start*(m: Eth1Monitor) {.inline.} =
proc start*(m: Eth1Monitor) =
m.start(0.seconds)
proc waitGenesis*(m: Eth1Monitor): Future[BeaconStateRef] {.async.} =

View File

@ -343,7 +343,7 @@ proc updateScore*(peer: Peer, score: int) {.inline.} =
if peer.score > PeerScoreHighLimit:
peer.score = PeerScoreHighLimit
proc calcThroughput(dur: Duration, value: uint64): float {.inline.} =
proc calcThroughput(dur: Duration, value: uint64): float =
let secs = float(chronos.seconds(1).nanoseconds)
if isZero(dur):
0.0

View File

@ -117,7 +117,7 @@ proc fail*(blk: SyncBlock, error: BlockError) =
if blk.resfut != nil:
blk.resfut.complete(Result[void, BlockError].err(error))
proc complete*(blk: SyncBlock, res: Result[void, BlockError]) {.inline.} =
proc complete*(blk: SyncBlock, res: Result[void, BlockError]) =
## Send signal to [Sync/Request]Manager about result ``res`` of block ``blk``
## verification.
if blk.resfut != nil:

View File

@ -55,7 +55,7 @@ template unsafeGet*[K, V](table: Table[K, V], key: K): V =
except KeyError as exc:
raiseAssert(exc.msg)
func `[]`(nodes: ProtoNodes, idx: Index): Option[ProtoNode] {.inline.} =
func `[]`(nodes: ProtoNodes, idx: Index): Option[ProtoNode] =
## Retrieve a ProtoNode at "Index"
if idx < nodes.offset:
return none(ProtoNode)
@ -64,10 +64,10 @@ func `[]`(nodes: ProtoNodes, idx: Index): Option[ProtoNode] {.inline.} =
return none(ProtoNode)
return some(nodes.buf[i])
func len*(nodes: ProtoNodes): int {.inline.} =
func len*(nodes: ProtoNodes): int =
nodes.buf.len
func add(nodes: var ProtoNodes, node: ProtoNode) {.inline.} =
func add(nodes: var ProtoNodes, node: ProtoNode) =
nodes.buf.add node
# Forward declarations

View File

@ -156,7 +156,7 @@ type
StrRes[T] = Result[T, string]
func `==`*(a, b: ENRFieldPair): bool {.inline.} =
func `==`(a, b: ENRFieldPair): bool =
result = (a.eth2 == b.eth2)
func hasTCP(a: PeerInfo): bool =
@ -181,7 +181,7 @@ chronicles.formatIt seq[PeerInfo]:
"[" & res.join(", ") & "]"
func getTopics(forkDigest: ForkDigest,
filter: TopicFilter): seq[string] {.inline.} =
filter: TopicFilter): seq[string] =
case filter
of TopicFilter.Blocks:
let topic = getBeaconBlocksTopic(forkDigest)
@ -289,8 +289,8 @@ proc loadBootstrapNodes(conf: InspectorConf): seq[BootstrapAddress] =
if res.isSome():
result.add(res.get())
proc init*(p: typedesc[PeerInfo],
maddr: MultiAddress): StrRes[PeerInfo] {.inline.} =
proc init(p: typedesc[PeerInfo],
maddr: MultiAddress): StrRes[PeerInfo] =
## Initialize PeerInfo using address which includes PeerID.
if IPFS.match(maddr):
let peerid = ? protoAddress(? maddr[2])
@ -298,7 +298,7 @@ proc init*(p: typedesc[PeerInfo],
? (PeerID.init(peerid).mapErr(proc (v: cstring): string = $v)),
[(? maddr[0]) & (? maddr[1])]))
proc init*(p: typedesc[PeerInfo],
proc init(p: typedesc[PeerInfo],
enraddr: enr.Record): StrRes[PeerInfo] =
var trec: enr.TypedRecord
try:
@ -367,10 +367,10 @@ proc connectToNetwork(switch: Switch, nodes: seq[PeerInfo],
result = res
proc connectLoop*(switch: Switch,
peerQueue: AsyncQueue[PeerInfo],
peerTable: TableRef[PeerID, PeerInfo],
timeout: Duration): Future[void] {.async.} =
proc connectLoop(switch: Switch,
peerQueue: AsyncQueue[PeerInfo],
peerTable: TableRef[PeerID, PeerInfo],
timeout: Duration): Future[void] {.async.} =
var addresses = newSeq[PeerInfo]()
trace "Starting connection loop", queue_size = len(peerQueue),
table_size = len(peerTable),
@ -387,7 +387,7 @@ proc connectLoop*(switch: Switch,
for item in infos:
peerTable[item.peerId] = item
func toIpAddress*(ma: MultiAddress): Option[ValidIpAddress] =
func toIpAddress(ma: MultiAddress): Option[ValidIpAddress] =
if IP4.match(ma):
let addressRes = ma.protoAddress()
let address = if addressRes.isOk: addressRes.get
@ -481,8 +481,8 @@ proc logEnrAddress(address: string) =
else:
info "ENR bootstrap address is wrong or incomplete", enr_uri = address
func init*(p: typedesc[PeerInfo],
enruri: EnrUri): Option[PeerInfo] {.inline.} =
func init(p: typedesc[PeerInfo],
enruri: EnrUri): Option[PeerInfo] =
var rec: enr.Record
if fromURI(rec, enruri):
logEnrAddress(rec.toUri())

View File

@ -65,7 +65,7 @@ proc `<`*(a, b: PeerIndex): bool =
a.cmp(b, a)
proc fireNotEmptyEvent[A, B](pool: PeerPool[A, B],
item: PeerItem[A]) {.inline.} =
item: PeerItem[A]) =
case item.peerType:
of PeerType.Incoming:
pool.incNotEmptyEvent.fire()
@ -73,7 +73,7 @@ proc fireNotEmptyEvent[A, B](pool: PeerPool[A, B],
pool.outNotEmptyEvent.fire()
proc fireNotFullEvent[A, B](pool: PeerPool[A, B],
item: PeerItem[A]) {.inline.} =
item: PeerItem[A]) =
case item.peerType:
of PeerType.Incoming:
pool.incNotFullEvent.fire()
@ -269,12 +269,12 @@ proc checkPeerScore*[A, B](pool: PeerPool[A, B], peer: A): bool {.inline.} =
else:
true
proc peerCountChanged[A, B](pool: PeerPool[A, B]) {.inline.} =
proc peerCountChanged[A, B](pool: PeerPool[A, B]) =
## Call callback when number of peers changed.
if not(isNil(pool.peerCounter)):
pool.peerCounter()
proc peerDeleted[A, B](pool: PeerPool[A, B], peer: A) {.inline.} =
proc peerDeleted[A, B](pool: PeerPool[A, B], peer: A) =
## Call callback when peer is leaving PeerPool.
if not(isNil(pool.onDeletePeer)):
pool.onDeletePeer(peer)

View File

@ -205,25 +205,25 @@ proc getFullMap*[T](req: SyncRequest[T],
result = mapIt(data, $it.message.slot).join(", ")
proc init*[T](t1: typedesc[SyncRequest], t2: typedesc[T], slot: Slot,
count: uint64): SyncRequest[T] {.inline.} =
count: uint64): SyncRequest[T] =
result = SyncRequest[T](slot: slot, count: count, step: 1'u64)
proc init*[T](t1: typedesc[SyncRequest], t2: typedesc[T], start: Slot,
finish: Slot): SyncRequest[T] {.inline.} =
finish: Slot): SyncRequest[T] =
let count = finish - start + 1'u64
result = SyncRequest[T](slot: start, count: count, step: 1'u64)
proc init*[T](t1: typedesc[SyncRequest], t2: typedesc[T], slot: Slot,
count: uint64, item: T): SyncRequest[T] {.inline.} =
count: uint64, item: T): SyncRequest[T] =
result = SyncRequest[T](slot: slot, count: count, item: item, step: 1'u64)
proc init*[T](t1: typedesc[SyncRequest], t2: typedesc[T], start: Slot,
finish: Slot, item: T): SyncRequest[T] {.inline.} =
finish: Slot, item: T): SyncRequest[T] =
let count = finish - start + 1'u64
result = SyncRequest[T](slot: start, count: count, step: 1'u64, item: item)
proc init*[T](t1: typedesc[SyncFailure], kind: SyncFailureKind,
peer: T): SyncFailure[T] {.inline.} =
peer: T): SyncFailure[T] =
result = SyncFailure[T](kind: kind, peer: peer, stamp: now(chronos.Moment))
proc empty*[T](t: typedesc[SyncRequest],
@ -334,7 +334,7 @@ proc updateLastSlot*[T](sq: SyncQueue[T], last: Slot) {.inline.} =
$sq.lastSlot & " <= " & $last)
sq.lastSlot = last
proc wakeupWaiters[T](sq: SyncQueue[T], flag = true) {.inline.} =
proc wakeupWaiters[T](sq: SyncQueue[T], flag = true) =
## Wakeup one or all blocked waiters.
for item in sq.waiters:
if not(item.future.finished()):
@ -416,7 +416,7 @@ proc getLastNonEmptySlot*[T](sr: SyncResult[T]): Slot {.inline.} =
else:
sr.data[^1].message.slot
proc toDebtsQueue[T](sq: SyncQueue[T], sr: SyncRequest[T]) {.inline.} =
proc toDebtsQueue[T](sq: SyncQueue[T], sr: SyncRequest[T]) =
sq.debtsQueue.push(sr)
sq.debtsCount = sq.debtsCount + sr.count

View File

@ -226,7 +226,7 @@ proc updateStatus*(peer: Peer): Future[bool] {.async.} =
else:
return false
proc getHeadSlot*(peer: Peer): Slot {.inline.} =
proc getHeadSlot*(peer: Peer): Slot =
## Returns head slot for specific peer ``peer``.
result = peer.state(BeaconSync).statusMsg.headSlot

View File

@ -13,6 +13,8 @@ if defined(release) and not defined(disableLTO):
elif defined(linux):
switch("passC", "-flto=auto")
switch("passL", "-flto=auto")
switch("passC", "-finline-limit=100000")
switch("passL", "-finline-limit=100000")
else:
# On windows, LTO needs more love and attention so "gcc-ar" and "gcc-ranlib" are
# used for static libraries.

View File

@ -5,6 +5,6 @@
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.
func round_multiple_down*(x: uint64, n: uint64): uint64 {.inline.} =
func round_multiple_down*(x: uint64, n: uint64): uint64 =
## Round the input to the previous multiple of "n"
x - x mod n

View File

@ -110,13 +110,13 @@ proc mockAttestationImpl(
proc mockAttestation*(
state: BeaconState,
flags: UpdateFlags = {}): Attestation {.inline.}=
flags: UpdateFlags = {}): Attestation =
mockAttestationImpl(state, state.slot, flags)
proc mockAttestation*(
state: BeaconState,
slot: Slot,
flags: UpdateFlags = {}): Attestation {.inline.}=
flags: UpdateFlags = {}): Attestation =
mockAttestationImpl(state, slot, flags)
func fillAggregateAttestation*(state: BeaconState, attestation: var Attestation) =

View File

@ -28,7 +28,7 @@ export # Workaround:
# #######################
# JSON deserialization
proc readValue*(r: var JsonReader, a: var seq[byte]) {.inline.} =
proc readValue*(r: var JsonReader, a: var seq[byte]) =
## Custom deserializer for seq[byte]
a = hexToSeqByte(r.readValue(string))

View File

@ -39,7 +39,7 @@ type
input*: seq[ValidatorPubKey]
output*: ValidatorPubKey
proc readValue*(r: var JsonReader, a: var Domain) {.inline.} =
proc readValue*(r: var JsonReader, a: var Domain) =
## Custom deserializer for Domain
# Furthermore Nim parseHex doesn't support uint
# until https://github.com/nim-lang/Nim/pull/11067

View File

@ -5,7 +5,7 @@ import
../beacon_chain/[ssz, merkle_minimal],
mocking/mock_deposits
func round_step_down(x: Natural, step: static Natural): int {.inline.} =
func round_step_down(x: Natural, step: static Natural): int =
## Round the input to the previous multiple of "step"
when (step and (step - 1)) == 0:
# Step is a power of 2. (If compiler cannot prove that x>0 it does not make the optim)