minor improvement towards tgenericshardcases

This commit is contained in:
Zahary Karadjov 2013-08-28 00:21:38 +03:00
commit 01ccb52a00
4 changed files with 42 additions and 24 deletions

View file

@ -430,11 +430,14 @@ proc debugTree(n: PNode, indent: int, maxRecDepth: int): PRope =
appf(result, ",$N$1\"info\": $2", [istr, lineInfoToStr(n.info)]) appf(result, ",$N$1\"info\": $2", [istr, lineInfoToStr(n.info)])
appf(result, "$N$1}", [spaces(indent)]) appf(result, "$N$1}", [spaces(indent)])
proc debug(n: PSym) = proc debug(n: PSym) =
#writeln(stdout, ropeToStr(symToYaml(n, 0, 1))) if n == nil:
writeln(stdout, ropeToStr(ropef("$1_$2: $3, $4", [ writeln(stdout, "null")
toRope(n.name.s), toRope(n.id), flagsToStr(n.flags), else:
flagsToStr(n.loc.flags)]))) #writeln(stdout, ropeToStr(symToYaml(n, 0, 1)))
writeln(stdout, ropeToStr(ropef("$1_$2: $3, $4", [
toRope(n.name.s), toRope(n.id), flagsToStr(n.flags),
flagsToStr(n.loc.flags)])))
proc debug(n: PType) = proc debug(n: PType) =
writeln(stdout, ropeToStr(debugType(n))) writeln(stdout, ropeToStr(debugType(n)))

View file

@ -248,7 +248,11 @@ proc semLowHigh(c: PContext, n: PNode, m: TMagic): PNode =
of tyInt..tyInt64, tyChar, tyBool, tyEnum, tyUInt8, tyUInt16, tyUInt32: of tyInt..tyInt64, tyChar, tyBool, tyEnum, tyUInt8, tyUInt16, tyUInt32:
# do not skip the range! # do not skip the range!
n.typ = n.sons[1].typ.skipTypes(abstractVar) n.typ = n.sons[1].typ.skipTypes(abstractVar)
else: LocalError(n.info, errInvalidArgForX, opToStr[m]) of tyGenericParam:
# leave it for now, it will be resolved in semtypinst
n.typ = getSysType(tyInt)
else:
LocalError(n.info, errInvalidArgForX, opToStr[m])
result = n result = n
proc semSizeof(c: PContext, n: PNode): PNode = proc semSizeof(c: PContext, n: PNode): PNode =

View file

@ -148,12 +148,13 @@ proc handleGenericInvokation(cl: var TReplTypeVars, t: PType): PType =
if result != nil: return if result != nil: return
for i in countup(1, sonsLen(t) - 1): for i in countup(1, sonsLen(t) - 1):
var x = t.sons[i] var x = t.sons[i]
if x.kind == tyGenericParam: if x.kind == tyGenericParam:
x = lookupTypeVar(cl, x) x = lookupTypeVar(cl, x)
if header == nil: header = copyType(t, t.owner, false) if header == nil: header = copyType(t, t.owner, false)
header.sons[i] = x header.sons[i] = x
propagateToOwner(header, x) propagateToOwner(header, x)
#idTablePut(cl.typeMap, body.sons[i-1], x) #idTablePut(cl.typeMap, body.sons[i-1], x)
if header != nil: if header != nil:
# search again after first pass: # search again after first pass:
result = searchInstTypes(header) result = searchInstTypes(header)
@ -200,6 +201,9 @@ proc ReplaceTypeVarsT*(cl: var TReplTypeVars, t: PType): PType =
result = lookupTypeVar(cl, t) result = lookupTypeVar(cl, t)
if result.kind == tyGenericInvokation: if result.kind == tyGenericInvokation:
result = handleGenericInvokation(cl, result) result = handleGenericInvokation(cl, result)
of tyExpr:
if t.sym != nil and t.sym.kind == skGenericParam:
result = lookupTypeVar(cl, t)
of tyGenericInvokation: of tyGenericInvokation:
result = handleGenericInvokation(cl, t) result = handleGenericInvokation(cl, t)
of tyGenericBody: of tyGenericBody:

View file

@ -619,7 +619,10 @@ proc typeRel(c: var TCandidate, f, a: PType): TTypeRelation =
else: else:
result = isNone result = isNone
else: else:
result = matchTypeClass(c, f, a) if a.kind == tyTypeClass:
result = isGeneric
else:
result = matchTypeClass(c, f, a)
if result == isGeneric: if result == isGeneric:
var concrete = concreteType(c, a) var concrete = concreteType(c, a)
@ -782,21 +785,25 @@ proc ParamTypesMatchAux(c: PContext, m: var TCandidate, f, a: PType,
if fMaybeExpr.sonsLen == 0: if fMaybeExpr.sonsLen == 0:
r = isGeneric r = isGeneric
else: else:
let match = matchTypeClass(m, fMaybeExpr, a) if a.kind == tyExpr:
if match != isGeneric: r = isNone InternalAssert a.len > 0
r = typeRel(m, f.lastSon, a.lastSon)
else: else:
# XXX: Ideally, this should happen much earlier somewhere near let match = matchTypeClass(m, fMaybeExpr, a)
# semOpAux, but to do that, we need to be able to query the if match != isGeneric: r = isNone
# overload set to determine whether compile-time value is expected else:
# for the param before entering the full-blown sigmatch algorithm. # XXX: Ideally, this should happen much earlier somewhere near
# This is related to the immediate pragma since querying the # semOpAux, but to do that, we need to be able to query the
# overload set could help there too. # overload set to determine whether compile-time value is expected
var evaluated = c.semConstExpr(c, arg) # for the param before entering the full-blown sigmatch algorithm.
if evaluated != nil: # This is related to the immediate pragma since querying the
r = isGeneric # overload set could help there too.
arg.typ = newTypeS(tyExpr, c) var evaluated = c.semConstExpr(c, arg)
arg.typ.sons = @[evaluated.typ] if evaluated != nil:
arg.typ.n = evaluated r = isGeneric
arg.typ = newTypeS(tyExpr, c)
arg.typ.sons = @[evaluated.typ]
arg.typ.n = evaluated
if r == isGeneric: if r == isGeneric:
put(m.bindings, f, arg.typ) put(m.bindings, f, arg.typ)
@ -812,7 +819,7 @@ proc ParamTypesMatchAux(c: PContext, m: var TCandidate, f, a: PType,
r = typeRel(m, f, a) r = typeRel(m, f, a)
else: else:
r = typeRel(m, f, a) r = typeRel(m, f, a)
case r case r
of isConvertible: of isConvertible:
inc(m.convMatches) inc(m.convMatches)