mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-31 19:03:42 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
317fcf93f2 | ||
|
|
4c5ae4d1fc | ||
|
|
8771451701 |
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
13
tests/ccgbugs2/m25294/c.nim
Normal file
13
tests/ccgbugs2/m25294/c.nim
Normal 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]
|
||||
5
tests/ccgbugs2/m25294/t.nim
Normal file
5
tests/ccgbugs2/m25294/t.nim
Normal 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
18
tests/ccgbugs2/t25294.nim
Normal 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[]
|
||||
@@ -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()
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user