From fee5a668443fd6d55b4eefcf8b456a8bac7bcd51 Mon Sep 17 00:00:00 2001 From: zerbina <100542850+zerbina@users.noreply.github.com> Date: Thu, 20 Jul 2023 14:47:38 +0000 Subject: [PATCH] internal: remove obsolete `nkExprColonExpr` detection Summary ======= Remove detection of `nkExprColonExpr` nodes in the context of tuple, array, and object construction expressions in the code generators. The ASTs reaching the code generators are expected to have a specific shape; violations thereof need to be treated as internal errors and should not be silently supported. Details ======= The AST coming out of `astgen` does not contain `nkExprColonExpr` nodes in `nkTupleConstr` trees, so the detection for them in `ccgexprs.genTupleConstr` and `vmgen.genTupleConstr` is obsolete and thus removed. Since `jsgen.genTupleConstr` is used for both normal procedure-level code and constant initializers, it cannot have the detection removed, as constant initializers do use `nkExprColonExpr` nodes for named tuple constructions (`nkTupleConstr`). In addition, the constant initializer AST that comes out of both `semfold` or `vmcompilerserdes`: - doesn't have `nkExprColonExpr` nodes in `nkBracket` (array construction) trees - always has `nkExprColonExpr` nodes in `nkObjConstr` trees Therefore, `ccgexprs.getNullValueAux` (code generation for constant object constructions) can depend on the presence of `nkExprColonExpr` nodes and `ccgexprs.genConstSimpleList` (code generation for constant array constructions) on their absence. --- compiler/backend/ccgexprs.nim | 25 ++++++++----------------- compiler/vm/vmgen.nim | 15 ++++----------- 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/compiler/backend/ccgexprs.nim b/compiler/backend/ccgexprs.nim index d1b0a13bd69..563b1fc4c63 100644 --- a/compiler/backend/ccgexprs.nim +++ b/compiler/backend/ccgexprs.nim @@ -1995,9 +1995,7 @@ proc genTupleConstr(p: BProc, n: PNode, d: var TLoc) = let t = n.typ discard getTypeDesc(p.module, t) # so that any fields are initialized if d.k == locNone: getTemp(p, t, d) - for i in 0.. 0: result.add ",\n" - if it.kind == nkExprColonExpr: result.add genBracedInit(p, it[1], isConst, it[0].typ) - else: result.add genBracedInit(p, it, isConst, it.typ) + result.add genBracedInit(p, it, isConst, it.typ) result.add("}\n") proc genConstTuple(p: BProc, n: PNode; isConst: bool; tup: PType): Rope = diff --git a/compiler/vm/vmgen.nim b/compiler/vm/vmgen.nim index 9115ef0d0e0..5f48b1c255c 100644 --- a/compiler/vm/vmgen.nim +++ b/compiler/vm/vmgen.nim @@ -2957,17 +2957,10 @@ proc genTupleConstr(c: var TCtx, n: PNode, dest: var TDest) = if n.typ.kind != tyTypeDesc: c.gABx(n, opcLdNull, dest, c.genType(n.typ)) # XXX x = (x.old, 22) produces wrong code ... stupid self assignments - for i in 0..