From 202e21daba1424762cf330effb52220c6f1d5772 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Mon, 4 Dec 2023 23:20:19 +0800 Subject: [PATCH] forbides adding sons for `PType` (#23030) I image `add` for `PType` to be used everythere --- compiler/ast.nim | 7 ------- compiler/ic/ic.nim | 4 +++- compiler/semexprs.nim | 3 +-- compiler/semtypes.nim | 9 +++------ 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/compiler/ast.nim b/compiler/ast.nim index 8a71522e60..e25ce42dd1 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -1567,10 +1567,6 @@ when false: result = prev result.sons = sons -proc addSon*(father, son: PType) = - # todo fixme: in IC, `son` might be nil - father.sons.add(son) - proc mergeLoc(a: var TLoc, b: TLoc) = if a.k == low(typeof(a.k)): a.k = b.k if a.storage == low(typeof(a.storage)): a.storage = b.storage @@ -1713,9 +1709,6 @@ proc rawAddSon*(father, son: PType; propagateHasAsgn = true) = father.sons.add(son) if not son.isNil: propagateToOwner(father, son, propagateHasAsgn) -proc rawAddSonNoPropagationOfTypeFlags*(father, son: PType) = - father.sons.add(son) - proc addSonNilAllowed*(father, son: PNode) = father.sons.add(son) diff --git a/compiler/ic/ic.nim b/compiler/ic/ic.nim index b12db194cd..0085ea7485 100644 --- a/compiler/ic/ic.nim +++ b/compiler/ic/ic.nim @@ -994,8 +994,10 @@ proc typeBodyFromPacked(c: var PackedDecoder; g: var PackedModuleGraph; for op, item in pairs t.attachedOps: result.attachedOps[op] = loadSym(c, g, si, item) result.typeInst = loadType(c, g, si, t.typeInst) + var sons = newSeq[PType]() for son in items t.types: - result.addSon loadType(c, g, si, son) + sons.add loadType(c, g, si, son) + result.setSons(sons) loadAstBody(t, n) when false: for gen, id in items t.methods: diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 96904f0dd3..82ff000a74 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -345,10 +345,9 @@ proc semConv(c: PContext, n: PNode; flags: TExprFlags = {}, expectedType: PType if targetType.kind in {tySink, tyLent} or isOwnedSym(c, n[0]): let baseType = semTypeNode(c, n[1], nil).skipTypes({tyTypeDesc}) - let t = newTypeS(targetType.kind, c) + let t = newTypeS(targetType.kind, c, @[baseType]) if targetType.kind == tyOwned: t.flags.incl tfHasOwned - t.rawAddSonNoPropagationOfTypeFlags baseType result = newNodeI(nkType, n.info) result.typ = makeTypeDesc(c, t) return diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index e234c6b1fd..be33114f58 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -424,10 +424,9 @@ proc semArray(c: PContext, n: PNode, prev: PType): PType = typeToString(indxB.skipTypes({tyRange}))) base = semTypeNode(c, n[2], nil) # ensure we only construct a tyArray when there was no error (bug #3048): - result = newOrPrevType(tyArray, prev, c) # bug #6682: Do not propagate initialization requirements etc for the # index type: - rawAddSonNoPropagationOfTypeFlags(result, indx) + result = newOrPrevType(tyArray, prev, c, @[indx]) addSonSkipIntLit(result, base, c.idgen) else: localError(c.config, n.info, errArrayExpectsTwoTypeParams) @@ -1019,13 +1018,11 @@ proc semAnyRef(c: PContext; n: PNode; kind: TTypeKind; prev: PType): PType = case wrapperKind of tyOwned: if optOwnedRefs in c.config.globalOptions: - let t = newTypeS(tyOwned, c) + let t = newTypeS(tyOwned, c, @[result]) t.flags.incl tfHasOwned - t.rawAddSonNoPropagationOfTypeFlags result result = t of tySink: - let t = newTypeS(tySink, c) - t.rawAddSonNoPropagationOfTypeFlags result + let t = newTypeS(tySink, c, @[result]) result = t else: discard if result.kind == tyRef and c.config.selectedGC in {gcArc, gcOrc, gcAtomicArc}: