From 6152eb3be3610654cd57fae67fd07559a8f928f9 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 23 Dec 2019 13:05:30 +0100 Subject: [PATCH] a better bugfix --- compiler/ccgexprs.nim | 63 ++++++++++++++++++++++--------------------- compiler/cgen.nim | 6 ++--- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 9fca9604d..44a9b794b 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -2876,44 +2876,47 @@ proc genBracedInit(p: BProc, n: PNode; isConst: bool): Rope = case n.kind of nkHiddenStdConv, nkHiddenSubConv: result = genBracedInit(p, n[1], isConst) - of nkCurly: - var cs: TBitSet - toBitSet(p.config, n, cs) - result = genRawSetData(cs, int(getSize(p.config, n.typ))) - of nkBracket, nkPar, nkTupleConstr, nkClosure: + else: var t = skipTypes(n.typ, abstractInstOwned) - if t.kind == tySequence: + case t.kind + of tySet: + var cs: TBitSet + toBitSet(p.config, n, cs) + result = genRawSetData(cs, int(getSize(p.config, n.typ))) + of tySequence: if optSeqDestructors in p.config.globalOptions: result = genConstSeqV2(p, n, n.typ, isConst) else: result = genConstSeq(p, n, n.typ, isConst) - elif t.kind == tyProc and t.callConv == ccClosure and n.len > 1 and - n[1].kind == nkNilLit: - # Conversion: nimcall -> closure. - # this hack fixes issue that nkNilLit is expanded to {NIM_NIL,NIM_NIL} - # this behaviour is needed since closure_var = nil must be - # expanded to {NIM_NIL,NIM_NIL} - # in VM closures are initialized with nkPar(nkNilLit, nkNilLit) - # leading to duplicate code like this: - # "{NIM_NIL,NIM_NIL}, {NIM_NIL,NIM_NIL}" - if n[0].kind == nkNilLit: - result = ~"{NIM_NIL,NIM_NIL}" + of tyProc: + if t.callConv == ccClosure and n.len > 1 and n[1].kind == nkNilLit: + # Conversion: nimcall -> closure. + # this hack fixes issue that nkNilLit is expanded to {NIM_NIL,NIM_NIL} + # this behaviour is needed since closure_var = nil must be + # expanded to {NIM_NIL,NIM_NIL} + # in VM closures are initialized with nkPar(nkNilLit, nkNilLit) + # leading to duplicate code like this: + # "{NIM_NIL,NIM_NIL}, {NIM_NIL,NIM_NIL}" + if n[0].kind == nkNilLit: + result = ~"{NIM_NIL,NIM_NIL}" + else: + var d: TLoc + initLocExpr(p, n[0], d) + result = "{(($1) $2),NIM_NIL}" % [getClosureType(p.module, t, clHalfWithEnv), rdLoc(d)] + else: + result = ~"NIM_NIL" + of tyArray, tyTuple, tyOpenArray, tyVarargs: + result = genConstSimpleList(p, n, isConst) + of tyObject: + result = genConstObjConstr(p, n, isConst) + of tyString, tyCString: + if optSeqDestructors in p.config.globalOptions and n.kind != nkNilLit: + result = genStringLiteralV2Const(p.module, n, isConst) else: var d: TLoc - initLocExpr(p, n[0], d) - result = "{(($1) $2),NIM_NIL}" % [getClosureType(p.module, t, clHalfWithEnv), rdLoc(d)] - else: - result = genConstSimpleList(p, n, isConst) - of nkObjConstr: - result = genConstObjConstr(p, n, isConst) - of nkStrLit..nkTripleStrLit: - if optSeqDestructors in p.config.globalOptions: - result = genStringLiteralV2Const(p.module, n, isConst) + initLocExpr(p, n, d) + result = rdLoc(d) else: var d: TLoc initLocExpr(p, n, d) result = rdLoc(d) - else: - var d: TLoc - initLocExpr(p, n, d) - result = rdLoc(d) diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 8a7b79d76..70dae5ffa 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -362,13 +362,13 @@ proc genObjectInit(p: BProc, section: TCProcSection, t: PType, a: var TLoc, linefmt(p, section, "$1.m_type = $2;$n", [r, genTypeInfo(p.module, t, a.lode.info)]) of frEmbedded: if optTinyRtti in p.config.globalOptions: - var n = newNodeIT(nkObjConstr, a.lode.info, t) - n.add newNodeIT(nkType, a.lode.info, t) if mode == constructRefObj: + var n = newNodeIT(nkObjConstr, a.lode.info, t) + n.add newNodeIT(nkType, a.lode.info, t) genObjConstr(p, n, a) else: var tmp: TLoc - rawConstExpr(p, n, tmp) + rawConstExpr(p, newNodeIT(nkType, a.lode.info, t), tmp) genAssignment(p, a, tmp, {}) else: # worst case for performance: