fixes #3112
This commit is contained in:
parent
c02db2ff9b
commit
e5d8988175
2 changed files with 45 additions and 11 deletions
|
|
@ -90,6 +90,7 @@ type
|
||||||
allowMetaTypes*: bool # allow types such as seq[Number]
|
allowMetaTypes*: bool # allow types such as seq[Number]
|
||||||
# i.e. the result contains unresolved generics
|
# i.e. the result contains unresolved generics
|
||||||
skipTypedesc*: bool # wether we should skip typeDescs
|
skipTypedesc*: bool # wether we should skip typeDescs
|
||||||
|
recursionLimit: int
|
||||||
|
|
||||||
proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType
|
proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType
|
||||||
proc replaceTypeVarsS(cl: var TReplTypeVars, s: PSym): PSym
|
proc replaceTypeVarsS(cl: var TReplTypeVars, s: PSym): PSym
|
||||||
|
|
@ -365,6 +366,19 @@ proc propagateFieldFlags(t: PType, n: PNode) =
|
||||||
else: discard
|
else: discard
|
||||||
|
|
||||||
proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType =
|
proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType =
|
||||||
|
template bailout =
|
||||||
|
if cl.recursionLimit > 100:
|
||||||
|
# bail out, see bug #2509. But note this caching is in general wrong,
|
||||||
|
# look at this example where TwoVectors should not share the generic
|
||||||
|
# instantiations (bug #3112):
|
||||||
|
|
||||||
|
# type
|
||||||
|
# Vector[N: static[int]] = array[N, float64]
|
||||||
|
# TwoVectors[Na, Nb: static[int]] = (Vector[Na], Vector[Nb])
|
||||||
|
result = PType(idTableGet(cl.localCache, t))
|
||||||
|
if result != nil: return result
|
||||||
|
inc cl.recursionLimit
|
||||||
|
|
||||||
result = t
|
result = t
|
||||||
if t == nil: return
|
if t == nil: return
|
||||||
|
|
||||||
|
|
@ -420,8 +434,7 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType =
|
||||||
result = t
|
result = t
|
||||||
|
|
||||||
of tyGenericInst:
|
of tyGenericInst:
|
||||||
result = PType(idTableGet(cl.localCache, t))
|
bailout()
|
||||||
if result != nil: return result
|
|
||||||
result = instCopyType(cl, t)
|
result = instCopyType(cl, t)
|
||||||
idTablePut(cl.localCache, t, result)
|
idTablePut(cl.localCache, t, result)
|
||||||
for i in 1 .. <result.sonsLen:
|
for i in 1 .. <result.sonsLen:
|
||||||
|
|
@ -431,8 +444,7 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType =
|
||||||
else:
|
else:
|
||||||
if containsGenericType(t):
|
if containsGenericType(t):
|
||||||
#if not cl.allowMetaTypes:
|
#if not cl.allowMetaTypes:
|
||||||
result = PType(idTableGet(cl.localCache, t))
|
bailout()
|
||||||
if result != nil: return result
|
|
||||||
result = instCopyType(cl, t)
|
result = instCopyType(cl, t)
|
||||||
result.size = -1 # needs to be recomputed
|
result.size = -1 # needs to be recomputed
|
||||||
#if not cl.allowMetaTypes:
|
#if not cl.allowMetaTypes:
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,39 @@
|
||||||
|
discard """
|
||||||
|
output: '''0
|
||||||
|
0
|
||||||
|
2
|
||||||
|
100'''
|
||||||
|
"""
|
||||||
|
|
||||||
type
|
type
|
||||||
RectArray*[R, C: static[int], T] = distinct array[R * C, T]
|
RectArray*[R, C: static[int], T] = distinct array[R * C, T]
|
||||||
|
|
||||||
StaticMatrix*[R, C: static[int], T] = object
|
StaticMatrix*[R, C: static[int], T] = object
|
||||||
elements*: RectArray[R, C, T]
|
elements*: RectArray[R, C, T]
|
||||||
|
|
||||||
StaticVector*[N: static[int], T] = StaticMatrix[N, 1, T]
|
StaticVector*[N: static[int], T] = StaticMatrix[N, 1, T]
|
||||||
|
|
||||||
proc foo*[N, T](a: StaticVector[N, T]): T = 0.T
|
proc foo*[N, T](a: StaticVector[N, T]): T = 0.T
|
||||||
proc foobar*[N, T](a, b: StaticVector[N, T]): T = 0.T
|
proc foobar*[N, T](a, b: StaticVector[N, T]): T = 0.T
|
||||||
|
|
||||||
|
|
||||||
var a: StaticVector[3, int]
|
var a: StaticVector[3, int]
|
||||||
|
|
||||||
echo foo(a) # OK
|
echo foo(a) # OK
|
||||||
echo foobar(a, a) # <--- hangs compiler
|
echo foobar(a, a) # <--- hangs compiler
|
||||||
|
|
||||||
|
# bug #3112
|
||||||
|
|
||||||
|
type
|
||||||
|
Vector[N: static[int]] = array[N, float64]
|
||||||
|
TwoVectors[Na, Nb: static[int]] = tuple
|
||||||
|
a: Vector[Na]
|
||||||
|
b: Vector[Nb]
|
||||||
|
|
||||||
|
when isMainModule:
|
||||||
|
var v: TwoVectors[2, 100]
|
||||||
|
echo v[0].len
|
||||||
|
echo v[1].len
|
||||||
|
#let xx = 50
|
||||||
|
v[1][50] = 0.0
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue