Skip to content

Commit

Permalink
Merge branch 'devel' into add-gcc-14-compatibility-job
Browse files Browse the repository at this point in the history
  • Loading branch information
zerbina committed Aug 7, 2024
2 parents 1ad756c + 7309115 commit b6b4c05
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 6 deletions.
2 changes: 1 addition & 1 deletion compiler/backend/ccgexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1638,7 +1638,7 @@ proc useData(p: BProc, x: ConstId, typ: PType): string =

proc expr(p: BProc, n: CgNode, d: var TLoc) =
when defined(nimCompilerStacktraceHints):
frameMsg(p.config, n)
frameMsg(p.config, n.info)
p.currLineInfo = n.info

case n.kind
Expand Down
9 changes: 9 additions & 0 deletions compiler/backend/cgirgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ import std/options as std_options
from compiler/ast/ast import newSym, newType, rawAddSon
from compiler/sem/semdata import makeVarType

when defined(nimCompilerStacktraceHints):
import compiler/utils/debugutils

type
TranslateCl = object
graph: ModuleGraph
Expand Down Expand Up @@ -557,6 +560,9 @@ proc stmtToIr(tree: MirBody, env: MirEnv, cl: var TranslateCl,
let n {.cursor.} = tree.get(cr)
let info = cr.info ## the source information of `n`

when defined(nimCompilerStacktraceHints):
frameMsg(cl.graph.config, info)

template to(kind: CgNodeKind, args: varargs[untyped]) =
stmts.add newStmt(kind, info, args)

Expand Down Expand Up @@ -683,6 +689,9 @@ proc exprToIr(tree: MirBody, cl: var TranslateCl,
let n {.cursor.} = get(tree, cr)
let info = cr.info

when defined(nimCompilerStacktraceHints):
frameMsg(cl.graph.config, info)

template op(kind: CgNodeKind, e: CgNode): CgNode =
newOp(kind, info, cl.map(n.typ), e)

Expand Down
3 changes: 3 additions & 0 deletions compiler/sem/sighashes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) =
c.hashTree(t.n, {})
of tyTuple:
c &= char(t.kind)
# add the length so that (int, int) and ((int,), int) have different
# representations
c &= t.len
if t.n != nil and CoType notin flags:
assert(t.n.len == t.len)
for i in 0..<t.n.len:
Expand Down
8 changes: 4 additions & 4 deletions compiler/utils/debugutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -636,13 +636,13 @@ template frameMsg*(c: ConfigRef, n: PNode) =
$n.info.line,
$n.info.col]

template frameMsg*(c: ConfigRef, n: CgNode) =
template frameMsg*(c: ConfigRef, info: TLineInfo) =
{.line.}:
setFrameMsg "$1 $2($3, $4)" % [
$n.kind,
c.toFullPath(n.info.fileIndex),
$n.info.line,
$n.info.col]
c.toFullPath(info.fileIndex),
$info.line,
$info.col]

const locOffset = -2

Expand Down
2 changes: 1 addition & 1 deletion compiler/vm/vmgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2998,7 +2998,7 @@ proc binaryArith(c: var TCtx, e, x, y: CgNode, dest: var TDest,

proc gen(c: var TCtx; n: CgNode; dest: var TDest) =
when defined(nimCompilerStacktraceHints):
frameMsg c.config, n
frameMsg c.config, n.info

case n.kind
of cnkProc:
Expand Down
30 changes: 30 additions & 0 deletions tests/lang_objects/destructor/ttuple_hook_synthesis_issue.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
discard """
description: '''
Ensure that hook synthesis considers ``(A, (B, C))`` different from
``(A, (B,), C)``.
'''
output: "3\n4\n1\n2\n"
knownIssue.js vm: "seq destructors don't work yet"
"""

type Object = object
val: int

proc `=destroy`(x: var Object) =
echo x.val

# a seq is only used for testing purposes, since it caused misbehaviour at
# run-time. Using ``(Object, (Object,) Object)`` and
# ``(Object, (Object, Object))`` also led to the same issue, but ran
# "correctly" due to both types having the same in-memory layout
type
Tup1 = (seq[(Object,)], Object)
Tup2 = (seq[(Object, Object)],)

proc test() =
var x: Tup1 = (@[(Object(val: 1),)], Object(val: 2))
var y: Tup2 = (@[(Object(val: 3), Object(val: 4))],)
# both locations were treated as having type `Tup1` by the called
# destructor, resulting in either crashes or the wrong output being produced

test()

0 comments on commit b6b4c05

Please sign in to comment.