From dfb5cb3c5d9c3981cd02d3fa27221e0b7f5af1e8 Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Mon, 19 Aug 2013 01:26:37 +0300 Subject: remerge "Fixes #267" --- compiler/ast.nim | 15 ++--- compiler/semdata.nim | 5 ++ compiler/seminst.nim | 103 +++++++++++++++++++++++++++------ compiler/semtypes.nim | 156 ++++++++++++++++++++++++++++---------------------- compiler/types.nim | 2 + 5 files changed, 184 insertions(+), 97 deletions(-) (limited to 'compiler') diff --git a/compiler/ast.nim b/compiler/ast.nim index 514ab6a7c..4be931c8d 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -366,12 +366,8 @@ type tfFromGeneric, # type is an instantiation of a generic; this is needed # because for instantiations of objects, structural # type equality has to be used - tfInstantiated, # XXX: used to mark generic params after instantiation. - # if the concrete type happens to be an implicit generic - # this can lead to invalid proc signatures in the second - # pass of semProcTypeNode performed after instantiation. - # this won't be needed if we don't perform this redundant - # second pass (stay tuned). + tfUnresolved, # marks unresolved typedesc params: e.g. + # proc foo(T: typedesc, list: seq[T]): var T tfRetType, # marks return types in proc (used to detect type classes # used as return types for return type inference) tfAll, # type class requires all constraints to be met (default) @@ -1053,8 +1049,8 @@ proc NewType(kind: TTypeKind, owner: PSym): PType = result.size = - 1 result.align = 2 # default alignment result.id = getID() - when debugIds: - RegisterId(result) + when debugIds: + RegisterId(result) #if result.id < 2000 then # MessageOut(typeKindToStr[kind] & ' has id: ' & toString(result.id)) @@ -1091,7 +1087,6 @@ proc copyType(t: PType, owner: PSym, keepId: bool): PType = if keepId: result.id = t.id else: - result.id = getID() when debugIds: RegisterId(result) result.sym = t.sym # backend-info should not be copied @@ -1364,7 +1359,7 @@ proc isGenericRoutine*(s: PSym): bool = of skProc, skTemplate, skMacro, skIterator, skMethod, skConverter: result = s.ast != nil and s.ast[genericParamsPos].kind != nkEmpty else: nil - + proc isRoutine*(s: PSym): bool {.inline.} = result = s.kind in {skProc, skTemplate, skMacro, skIterator, skMethod, skConverter} diff --git a/compiler/semdata.nim b/compiler/semdata.nim index 72d5a5fef..b9c32a680 100644 --- a/compiler/semdata.nim +++ b/compiler/semdata.nim @@ -207,6 +207,11 @@ proc makeTypeDesc*(c: PContext, typ: PType): PType = proc newTypeS(kind: TTypeKind, c: PContext): PType = result = newType(kind, getCurrOwner()) +proc newTypeWithSons*(c: PContext, kind: TTypeKind, + sons: seq[PType]): PType = + result = newType(kind, getCurrOwner()) + result.sons = sons + proc errorType*(c: PContext): PType = ## creates a type representing an error state result = newTypeS(tyError, c) diff --git a/compiler/seminst.nim b/compiler/seminst.nim index 9dc99d173..35ed00965 100644 --- a/compiler/seminst.nim +++ b/compiler/seminst.nim @@ -38,7 +38,6 @@ proc instantiateGenericParamList(c: PContext, n: PNode, pt: TIdTable, #t = instGenericContainer(c, a, t) t = generateTypeInstance(c, pt, a, t) #t = ReplaceTypeVarsT(cl, t) - t.flags.incl tfInstantiated s.typ = t addDecl(c, s) entry.concreteTypes[i] = t @@ -84,11 +83,28 @@ proc freshGenSyms(n: PNode, owner: PSym, symMap: var TIdTable) = else: for i in 0 ..