fixes strictdefs warnings for stdlibs [part two] (#24514)

After some cleanups for stdlibs, then we should enable warningaserror
for all tests

(cherry picked from commit c0861142f8)
This commit is contained in:
ringabout
2024-12-06 12:40:48 +08:00
committed by narimiran
parent 94a6b85538
commit 2d470c9afd
44 changed files with 162 additions and 92 deletions

View File

@@ -13,6 +13,9 @@
# Note: Only add new enum values at the end to ensure binary compatibility with
# other Nim compiler versions!
when defined(nimPreviewSlimSystem):
import std/assertions
type
SingleValueSetting* {.pure.} = enum ## \
## settings resulting in a single string value
@@ -54,6 +57,7 @@ proc querySetting*(setting: SingleValueSetting): string {.
##
runnableExamples:
const nimcache = querySetting(SingleValueSetting.nimcacheDir)
raiseAssert "implemented in the vmops"
proc querySettingSeq*(setting: MultipleValueSetting): seq[string] {.
compileTime, noSideEffect.} =
@@ -64,3 +68,4 @@ proc querySettingSeq*(setting: MultipleValueSetting): seq[string] {.
## * `compileOption <system.html#compileOption,string,string>`_ for enum options
runnableExamples:
const nimblePaths = querySettingSeq(MultipleValueSetting.nimblePaths)
raiseAssert "implemented in the vmops"

View File

@@ -114,7 +114,7 @@ proc editDistance*(a, b: string): int {.noSideEffect.} =
iCurrentA = iStart
var
char2pI = -1
char2pPrev: int
char2pPrev: int = 0
for i in 1 .. (len1 - 1):
iNextA = iCurrentA
a.fastRuneAt(iNextA, runeA)

View File

@@ -16,11 +16,14 @@
import std/macros
proc getRaisesListImpl(n: NimNode): NimNode = discard "see compiler/vmops.nim"
proc getTagsListImpl(n: NimNode): NimNode = discard "see compiler/vmops.nim"
proc getForbidsListImpl(n: NimNode): NimNode = discard "see compiler/vmops.nim"
proc isGcSafeImpl(n: NimNode): bool = discard "see compiler/vmops.nim"
proc hasNoSideEffectsImpl(n: NimNode): bool = discard "see compiler/vmops.nim"
when defined(nimPreviewSlimSystem):
import std/assertions
proc getRaisesListImpl(n: NimNode): NimNode = raiseAssert "see compiler/vmops.nim"
proc getTagsListImpl(n: NimNode): NimNode = raiseAssert "see compiler/vmops.nim"
proc getForbidsListImpl(n: NimNode): NimNode = raiseAssert "see compiler/vmops.nim"
proc isGcSafeImpl(n: NimNode): bool = raiseAssert "see compiler/vmops.nim"
proc hasNoSideEffectsImpl(n: NimNode): bool = raiseAssert "see compiler/vmops.nim"
proc getRaisesList*(fn: NimNode): NimNode =
## Extracts the `.raises` list of the func/proc/etc `fn`.

View File

@@ -11,6 +11,9 @@
## The `std/envvars` module implements environment variable handling.
import std/oserrors
when defined(nimPreviewSlimSystem):
import std/assertions
type
ReadEnvEffect* = object of ReadIOEffect ## Effect that denotes a read
## from an environment variable.
@@ -200,7 +203,7 @@ when not defined(nimscript):
let p = find(kv, '=')
yield (substr(kv, 0, p-1), substr(kv, p+1))
proc envPairsImplSeq(): seq[tuple[key, value: string]] = discard # vmops
proc envPairsImplSeq(): seq[tuple[key, value: string]] = raiseAssert "implemented in the vmops" # vmops
iterator envPairs*(): tuple[key, value: string] {.tags: [ReadEnvEffect].} =
## Iterate over all `environments variables`:idx:.

View File

@@ -98,7 +98,7 @@ proc getMonoTime*(): MonoTime {.tags: [TimeEffect].} =
result = MonoTime(ticks: (ticks * 1_000_000_000).int64)
elif defined(macosx):
let ticks = mach_absolute_time()
var machAbsoluteTimeFreq: MachTimebaseInfoData
var machAbsoluteTimeFreq: MachTimebaseInfoData = default(MachTimebaseInfoData)
mach_timebase_info(machAbsoluteTimeFreq)
result = MonoTime(ticks: ticks * machAbsoluteTimeFreq.numer div
machAbsoluteTimeFreq.denom)
@@ -106,15 +106,15 @@ proc getMonoTime*(): MonoTime {.tags: [TimeEffect].} =
let ticks = k_ticks_to_ns_floor64(k_uptime_ticks())
result = MonoTime(ticks: ticks)
elif defined(posix):
var ts: Timespec
var ts: Timespec = default(Timespec)
discard clock_gettime(CLOCK_MONOTONIC, ts)
result = MonoTime(ticks: ts.tv_sec.int64 * 1_000_000_000 +
ts.tv_nsec.int64)
elif defined(windows):
var ticks: uint64
var ticks: uint64 = 0'u64
QueryPerformanceCounter(ticks)
var freq: uint64
var freq: uint64 = 0'u64
QueryPerformanceFrequency(freq)
let queryPerformanceCounterFreq = 1_000_000_000'u64 div freq
result = MonoTime(ticks: (ticks * queryPerformanceCounterFreq).int64)

View File

@@ -88,6 +88,7 @@ proc rsGetPosition(s: Stream): int =
return s.pos
proc rsPeekData(s: Stream, buffer: pointer, bufLen: int): int =
result = 0
let s = ReadSocketStream(s)
if bufLen > 0:
let oldLen = s.buf.len

View File

@@ -1,13 +1,16 @@
## This module implements path handling like os module but works at only compile-time.
## This module works even when cross compiling to OS that is not supported by os module.
when defined(nimPreviewSlimSystem):
import std/assertions
proc staticFileExists*(filename: string): bool {.compileTime.} =
## Returns true if `filename` exists and is a regular file or symlink.
##
## Directories, device files, named pipes and sockets return false.
discard
raiseAssert "implemented in the vmops"
proc staticDirExists*(dir: string): bool {.compileTime.} =
## Returns true if the directory `dir` exists. If `dir` is a file, false
## is returned. Follows symlinks.
discard
raiseAssert "implemented in the vmops"

View File

@@ -287,6 +287,7 @@ else:
discard posix.close(fd)
proc urandomInternalImpl(dest: var openArray[byte]): int {.inline.} =
result = 0
when batchImplOS:
batchImpl(result, dest, getRandomImpl)
else:

View File

@@ -156,6 +156,7 @@ proc createTempFile*(prefix, suffix: string, dir = ""): tuple[cfile: File, path:
assert readFile(path) == "foo"
removeFile(path)
# xxx why does above work without `cfile.flushFile` ?
result = default(tuple[cfile: File, path: string])
let dir = getTempDirImpl(dir)
for i in 0 ..< maxRetry:
result.path = genTempPath(prefix, suffix, dir)

View File

@@ -107,10 +107,10 @@ proc writeVu64*(z: var openArray[byte], x: uint64): int =
varintWrite32(toOpenArray(z, 5, 8), y)
return 9
proc sar(a, b: int64): int64 =
proc sar(a, b: int64): int64 {.noinit.} =
{.emit: [result, " = ", a, " >> ", b, ";"].}
proc sal(a, b: int64): int64 =
proc sal(a, b: int64): int64 {.noinit.} =
{.emit: [result, " = ", a, " << ", b, ";"].}
proc encodeZigzag*(x: int64): uint64 {.inline.} =

View File

@@ -61,10 +61,11 @@ proc finalize(n: NimNode, lhs: NimNode, level: int): NimNode =
result = quote: (let `lhs` = `n`)
proc process(n: NimNode, lhs: NimNode, label: NimNode, level: int): NimNode =
result = nil
var n = n.copyNimTree
var it = n
let addr2 = bindSym"addr"
var old: tuple[n: NimNode, index: int]
var old: tuple[n: NimNode, index: int] = (nil, 0)
while true:
if it.len == 0:
result = finalize(n, lhs, level)