diff options
Diffstat (limited to 'compiler/semtypinst.nim')
-rw-r--r-- | compiler/semtypinst.nim | 41 |
1 files changed, 16 insertions, 25 deletions
diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim index f643fb903..7ff33f918 100644 --- a/compiler/semtypinst.nim +++ b/compiler/semtypinst.nim @@ -14,22 +14,11 @@ import ast, astalgo, msgs, types, magicsys, semdata, renderer const tfInstClearedFlags = {tfHasMeta} -proc sharedPtrCheck(info: TLineInfo, t: PType) = - if t.kind == tyPtr and t.len > 1: - if t.sons[0].sym.magic == mShared: - incl(t.flags, tfShared) - #if t.sons[0].sym.magic == mGuarded: incl(t.flags, tfGuarded) - if tfHasGCedMem in t.flags or t.isGCedMem: - localError(info, errGenerated, - "shared memory may not refer to GC'ed thread local memory") - proc checkPartialConstructedType(info: TLineInfo, t: PType) = if tfAcyclic in t.flags and skipTypes(t, abstractInst).kind != tyObject: localError(info, errInvalidPragmaX, "acyclic") elif t.kind == tyVar and t.sons[0].kind == tyVar: localError(info, errVarVarTypeNotAllowed) - else: - sharedPtrCheck(info, t) proc checkConstructedType*(info: TLineInfo, typ: PType) = var t = typ.skipTypes({tyDistinct}) @@ -40,8 +29,6 @@ proc checkConstructedType*(info: TLineInfo, typ: PType) = localError(info, errVarVarTypeNotAllowed) elif computeSize(t) == szIllegalRecursion: localError(info, errIllegalRecursionInTypeX, typeToString(t)) - else: - sharedPtrCheck(info, t) when false: if t.kind == tyObject and t.sons[0] != nil: if t.sons[0].kind != tyObject or tfFinal in t.sons[0].flags: @@ -60,7 +47,7 @@ proc searchInstTypes*(key: PType): PType = if inst.id == key.id: return inst if inst.sons.len < key.sons.len: # XXX: This happens for prematurely cached - # types such as TChannel[empty]. Why? + # types such as Channel[empty]. Why? # See the notes for PActor in handleGenericInvocation return block matchType: @@ -75,8 +62,12 @@ proc searchInstTypes*(key: PType): PType = proc cacheTypeInst*(inst: PType) = # XXX: add to module's generics # update the refcount - let genericTyp = inst.sons[0] - genericTyp.sym.typeInstCache.safeAdd(inst) + let gt = inst.sons[0] + let t = if gt.kind == tyGenericBody: gt.lastSon else: gt + if t.kind in {tyStatic, tyGenericParam} + tyTypeClasses: + return + gt.sym.typeInstCache.safeAdd(inst) + type TReplTypeVars* {.final.} = object @@ -212,14 +203,14 @@ proc replaceTypeVarsS(cl: var TReplTypeVars, s: PSym): PSym = # symbol is not our business: if cl.owner != nil and s.owner != cl.owner: return s - result = PSym(idTableGet(cl.symMap, s)) - if result == nil: - result = copySym(s, false) - incl(result.flags, sfFromGeneric) - idTablePut(cl.symMap, s, result) - result.owner = s.owner - result.typ = replaceTypeVarsT(cl, s.typ) - result.ast = replaceTypeVarsN(cl, s.ast) + #result = PSym(idTableGet(cl.symMap, s)) + #if result == nil: + result = copySym(s, false) + incl(result.flags, sfFromGeneric) + #idTablePut(cl.symMap, s, result) + result.owner = s.owner + result.typ = replaceTypeVarsT(cl, s.typ) + result.ast = replaceTypeVarsN(cl, s.ast) proc lookupTypeVar(cl: var TReplTypeVars, t: PType): PType = result = PType(idTableGet(cl.typeMap, t)) @@ -386,7 +377,7 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType = result = t if t == nil: return - if t.kind in {tyStatic, tyGenericParam, tyIter} + tyTypeClasses: + if t.kind in {tyStatic, tyGenericParam} + tyTypeClasses: let lookup = PType(idTableGet(cl.typeMap, t)) if lookup != nil: return lookup |