diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2023-12-04 23:20:19 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-04 16:20:19 +0100 |
commit | 202e21daba1424762cf330effb52220c6f1d5772 (patch) | |
tree | 16881772d2d3344f42d5c86051abcaa83305edd7 | |
parent | 618ccb6b6a60f9a315997f95cbbd81be9e9d7f53 (diff) | |
download | Nim-202e21daba1424762cf330effb52220c6f1d5772.tar.gz |
forbides adding sons for `PType` (#23030)
I image `add` for `PType` to be used everythere
-rw-r--r-- | compiler/ast.nim | 7 | ||||
-rw-r--r-- | compiler/ic/ic.nim | 4 | ||||
-rw-r--r-- | compiler/semexprs.nim | 3 | ||||
-rw-r--r-- | compiler/semtypes.nim | 9 |
4 files changed, 7 insertions, 16 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index 8a71522e6..e25ce42dd 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 b12db194c..0085ea748 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 96904f0dd..82ff000a7 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 e234c6b1f..be33114f5 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}: |