diff options
Diffstat (limited to 'compiler/seminst.nim')
-rw-r--r-- | compiler/seminst.nim | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/compiler/seminst.nim b/compiler/seminst.nim index 370990326..abc5600c3 100644 --- a/compiler/seminst.nim +++ b/compiler/seminst.nim @@ -47,10 +47,11 @@ proc sameInstantiation(a, b: TInstantiation): bool = flags = {ExactTypeDescValues}): return result = true -proc genericCacheGet(genericSym: PSym, entry: TInstantiation): PSym = +proc genericCacheGet(genericSym: PSym, entry: TInstantiation; + id: CompilesId): PSym = if genericSym.procInstCache != nil: for inst in genericSym.procInstCache: - if sameInstantiation(entry, inst[]): + if inst.compilesId == id and sameInstantiation(entry, inst[]): return inst.sym proc removeDefaultParamValues(n: PNode) = @@ -164,7 +165,7 @@ proc instantiateProcType(c: PContext, pt: TIdTable, addDecl(c, prc) pushInfoContext(info) - var cl = initTypeVars(c, pt, info) + var cl = initTypeVars(c, pt, info, nil) var result = instCopyType(cl, prc.typ) let originalParams = result.n result.n = originalParams.shallowCopy @@ -221,6 +222,8 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable, # NOTE: for access of private fields within generics from a different module # we set the friend module: c.friendModules.add(getModule(fn)) + let oldInTypeClass = c.inTypeClass + c.inTypeClass = 0 let oldScope = c.currentScope while not isTopLevel(c): c.currentScope = c.currentScope.parent result = copySym(fn, false) @@ -244,14 +247,18 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable, inc i pushProcCon(c, result) instantiateProcType(c, pt, result, info) + if tfTriggersCompileTime in result.typ.flags: + incl(result.flags, sfCompileTime) n.sons[genericParamsPos] = ast.emptyNode - var oldPrc = genericCacheGet(fn, entry[]) + var oldPrc = genericCacheGet(fn, entry[], c.compilesContextId) if oldPrc == nil: # we MUST not add potentially wrong instantiations to the caching mechanism. # This means recursive instantiations behave differently when in # a ``compiles`` context but this is the lesser evil. See # bug #1055 (tevilcompiles). - if c.inCompilesContext == 0: fn.procInstCache.safeAdd(entry) + #if c.compilesContextId == 0: + entry.compilesId = c.compilesContextId + fn.procInstCache.safeAdd(entry) c.generics.add(makeInstPair(fn, entry)) if n.sons[pragmasPos].kind != nkEmpty: pragma(c, result, n.sons[pragmasPos], allRoutinePragmas) @@ -269,4 +276,5 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable, c.currentScope = oldScope discard c.friendModules.pop() dec(c.instCounter) + c.inTypeClass = oldInTypeClass if result.kind == skMethod: finishMethod(c, result) |