Compare commits

..

3 Commits

Author SHA1 Message Date
ringabout
317fcf93f2 progress 2026-05-29 12:16:48 +08:00
ringabout
4c5ae4d1fc fixes #25591; error with capture in closure iterator 2026-05-28 22:27:49 +08:00
ringabout
8771451701 closes #25294; adds a test case (#25833)
closes #25294
2026-05-22 10:32:14 +08:00
11 changed files with 58 additions and 36 deletions

View File

@@ -974,7 +974,9 @@ proc cow(p: BProc; n: PNode) {.inline.} =
if n.kind == nkHiddenAddr: cowBracket(p, n[0])
template ignoreConv(e: PNode): bool =
sameBackendTypePickyAliases(e.typ, e[1].typ)
let destType = e.typ.skipTypes({tyVar, tyLent, tyGenericInst, tyAlias, tySink})
let srcType = e[1].typ.skipTypes({tyVar, tyLent, tyGenericInst, tyAlias, tySink})
sameBackendTypePickyAliases(destType, srcType)
proc genAddr(p: BProc, e: PNode, d: var TLoc) =
# careful 'addr(myptrToArray)' needs to get the ampersand:

View File

@@ -520,6 +520,8 @@ proc detectCapturedVars(n: PNode; owner: PSym; c: var DetectionPass) =
of nkLambdaKinds, nkIteratorDef:
if n.typ != nil:
detectCapturedVars(n[namePos], owner, c)
of nkClosure:
detectCapturedVars(n[1], owner, c)
of nkReturnStmt:
detectCapturedVars(n[0], owner, c)
of nkIdentDefs:
@@ -769,6 +771,8 @@ proc liftCapturedVars(n: PNode; owner: PSym; d: var DetectionPass;
let oldInContainer = c.inContainer
c.inContainer = 0
var body = transformBody(d.graph, d.idgen, s, {})
if not d.processed.containsOrIncl(s.id):
detectCapturedVars(body, s, d)
body = liftCapturedVars(body, s, d, c)
if c.envVars.getOrDefault(s.id).isNil:
s.transformedBody = body

View File

@@ -578,14 +578,7 @@ proc isOpImpl(c: PContext, n: PNode, flags: TExprFlags): PNode =
if efExplain in flags:
m.diagnostics = @[]
m.diagnosticsEnabled = true
let rel = typeRel(m, t2, t1)
res = rel >= isSubtype # isNone
if res and rel == isEqual and
not compareTypes(t1, t2,
flags = {ExactTypeDescValues,
PickyCAliases,
PickyBackendAliases}):
res = false
res = typeRel(m, t2, t1) >= isSubtype # isNone
# `res = sameType(t1, t2)` would be wrong, e.g. for `int is (int|float)`
result = newIntNode(nkIntLit, ord(res))

View File

@@ -81,8 +81,7 @@ proc sameInstantiation(a, b: TInstantiation): bool =
if not compareTypes(a.concreteTypes[i], b.concreteTypes[i],
flags = {ExactTypeDescValues,
ExactGcSafety,
PickyCAliases,
PickyBackendAliases}): return
PickyCAliases}): return
result = true
else:
result = false

View File

@@ -52,8 +52,7 @@ proc searchInstTypes*(g: ModuleGraph; key: PType): PType =
for j in FirstGenericParamAt..<key.kidsLen:
# XXX sameType is not really correct for nested generics?
if not compareTypes(inst[j], key[j],
flags = {ExactGenericParams, PickyCAliases,
PickyBackendAliases}):
flags = {ExactGenericParams, PickyCAliases}):
break matchType
return inst

View File

@@ -897,11 +897,7 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
c.flags = oldFlags
if x == y: return true
let aliasSkipSet = maybeSkipRange(
if PickyBackendAliases in c.flags:
{tyInferred}
else:
{tyAlias, tyInferred})
let aliasSkipSet = maybeSkipRange({tyAlias, tyInferred})
var a = skipTypes(x, aliasSkipSet)
while a.kind == tyUserTypeClass and tfResolved in a.flags:
a = skipTypes(a.last, aliasSkipSet)
@@ -1074,8 +1070,6 @@ proc sameBackendTypeIgnoreRange*(x, y: PType): bool =
result = sameTypeAux(x, y, c)
proc sameBackendTypePickyAliases*(x, y: PType): bool =
let x = x.skipTypes({tyVar, tyLent, tySink, tyOwned})
let y = y.skipTypes({tyVar, tyLent, tySink, tyOwned})
var c = initSameTypeClosure()
c.flags.incl {IgnoreTupleFields, IgnoreRangeShallow, PickyCAliases, PickyBackendAliases}
c.cmp = dcEqIgnoreDistinct

View File

@@ -0,0 +1,13 @@
template a(T: type): int =
when T is uint64: 1 else: 2
type
M*[T] = object
data*: seq[T]
b: seq[int]
indices*: array[a(T), int64]
U = distinct uint64
D* = object
c: M[U]
v: array[180000, int64]
g*: M[uint64]

View File

@@ -0,0 +1,5 @@
import ./c
proc p*(): D =
let c = M[uint64](data: @[0], indices: [1])
result = D(g: c)

18
tests/ccgbugs2/t25294.nim Normal file
View File

@@ -0,0 +1,18 @@
discard """
matrix: "--mm:refc; --mm:orc"
"""
import ./m25294/[c, t]
block:
let a = new D
a[] = p()
discard a[]
block:
let a = new D
a[] = p()
discard a[]
block:
let a = new D
a[] = p()
discard a[]

View File

@@ -75,19 +75,3 @@ block: # importc type inheritance
doAssert(cast[cint](b) == 123)
var c = foo(b)
doAssert(cast[cint](c) == 123)
# bug #23765
type
X11[T, E] = object
m: T
B = X11[culonglong, cstring]
S = ref object of RootObj
proc j[T, E](m: X11[T, E]): T = discard
proc n(T: typedesc[SomeUnsignedInt]): X11[T, cstring] = discard
method call(client: S): uint64 {.base.} =
discard j(n(uint64))
var s = S()
discard s.call()

View File

@@ -239,6 +239,17 @@ block t2023_objiter:
var o = init()
echo(o.iter())
block: # bug #25591
iterator h(): int =
let n = 0
(proc() = discard n)()
yield 0
proc a() =
iterator m(): int {.closure.} = (for _ in h(): discard)
let _ = m
a()
block:
# bug #13739