Compare commits

...

4 Commits

Author SHA1 Message Date
xflywind
d274b56256 ignore noinit pragma 2022-06-29 18:43:13 +08:00
xflywind
dd6833297f add warnings if noinit is ignored 2022-06-29 15:54:45 +08:00
xflywind
e885d89f63 FIX AGAIN 2022-06-29 10:48:00 +08:00
xflywind
2b53216152 initial commit for #16253 2022-06-28 19:20:47 +08:00
3 changed files with 63 additions and 1 deletions

View File

@@ -1064,9 +1064,11 @@ proc genProcAux(m: BModule, prc: PSym) =
# the 'unsureAsgn' is a nop. If it points to a global variable the
# global is either 'nil' or points to valid memory and so the RC operation
# succeeds without touching not-initialized memory.
if sfNoInit in prc.flags: discard
if sfNoInit in prc.flags and p.config.selectedGC notin {gcArc, gcOrc}: discard
elif allPathsAsgnResult(procBody) == InitSkippable: discard
else:
if sfNoInit in prc.flags and p.config.selectedGC in {gcArc, gcOrc}:
message(m.config, resNode.info, warnNoInitIgnored, "")
resetLoc(p, res.loc)
if skipTypes(res.typ, abstractInst).kind == tyArray:
#incl(res.loc.flags, lfIndirect)

View File

@@ -78,6 +78,7 @@ type
warnAnyEnumConv = "AnyEnumConv",
warnHoleEnumConv = "HoleEnumConv",
warnCstringConv = "CStringConv",
warnNoInitIgnored = "NoInitIgnored"
warnEffect = "Effect",
warnUser = "User",
# hints
@@ -170,6 +171,7 @@ const
warnAnyEnumConv: "$1",
warnHoleEnumConv: "$1",
warnCstringConv: "$1",
warnNoInitIgnored: "noinit pragma is ignored",
warnEffect: "$1",
warnUser: "$1",
hintSuccess: "operation successful: $#",

58
tests/arc/t16253.nim Normal file
View File

@@ -0,0 +1,58 @@
discard """
matrix: "--gc:arc"
"""
import sequtils
type
CpuStorage*[T] = ref CpuStorageObj[T]
CpuStorageObj[T] = object
size*: int
raw_buffer*: ptr UncheckedArray[T]
Tensor[T] = object
buf*: CpuStorage[T]
proc `=destroy`[T](s: var CpuStorageObj[T]) =
s.raw_buffer.deallocShared()
s.size = 0
s.raw_buffer = nil
proc `=`[T](a: var CpuStorageObj[T]; b: CpuStorageObj[T]) {.error.}
proc allocCpuStorage[T](s: var CpuStorage[T], size: int) =
new(s)
s.raw_buffer = cast[ptr UncheckedArray[T]](allocShared0(sizeof(T) * size))
s.size = size
proc newTensor[T](size: int): Tensor[T] =
allocCpuStorage(result.buf, size)
proc `[]`[T](t: Tensor[T], idx: int): T = t.buf.raw_buffer[idx]
proc `[]=`[T](t: Tensor[T], idx: int, val: T) = t.buf.raw_buffer[idx] = val
func size[T](t: Tensor[T]): int = t.buf.size
proc toTensor[T](s: seq[T]): Tensor[T] =
result = newTensor[T](s.len)
for i, x in s:
result[i] = x
type
Column* = ref object # works if normal object
fCol: Tensor[float]
proc asType*(t: Tensor[float]): Tensor[float] {.noInit.} = # works if `noInit` removed
result = t
proc toColumn*(t: Tensor[float]): Column =
result = Column(fCol: t.asType())
# works with regular contruction of ref object:
#result = new Column
#result.fCol = t.asType()
proc theBug =
# replacing toSeq.mapIt by a for loop makes it go away
# broken starting from `32252` on my machine, toSeq(0 .. 32251).mapIt(it.float).toTensor() works
let occ = toSeq(0 .. 32252).mapIt(it.float).toTensor()
let c = toColumn occ
theBug()