From a80f1a324fff0b2af47c0766750b3188bcab8041 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Sat, 1 Apr 2023 23:08:45 +0800 Subject: fixes #21592; create type bound operations for calls in the method dispatcher for ORC (#21594) * fixes #21592; create type operations for the method dispatcher * add a test case --- compiler/cgen.nim | 2 +- compiler/cgmeth.nim | 12 ++++++++---- compiler/jsgen.nim | 2 +- tests/arc/tarcmisc.nim | 11 +++++++++++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/compiler/cgen.nim b/compiler/cgen.nim index cc673d082..61bdab858 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -2153,7 +2153,7 @@ proc finalCodegenActions*(graph: ModuleGraph; m: BModule; n: PNode) = if m.g.forwardedProcs.len == 0: incl m.flags, objHasKidsValid - let disp = generateMethodDispatchers(graph) + let disp = generateMethodDispatchers(graph, m.idgen) for x in disp: genProcAux(m, x.sym) let mm = m diff --git a/compiler/cgmeth.nim b/compiler/cgmeth.nim index 4940a9093..1ea34f17b 100644 --- a/compiler/cgmeth.nim +++ b/compiler/cgmeth.nim @@ -11,7 +11,7 @@ import intsets, options, ast, msgs, idents, renderer, types, magicsys, - sempass2, modulegraphs, lineinfos + sempass2, modulegraphs, lineinfos, liftdestructors when defined(nimPreviewSlimSystem): import std/assertions @@ -213,7 +213,7 @@ proc sortBucket(a: var seq[PSym], relevantCols: IntSet) = a[j] = v if h == 1: break -proc genDispatcher(g: ModuleGraph; methods: seq[PSym], relevantCols: IntSet): PSym = +proc genDispatcher(g: ModuleGraph; methods: seq[PSym], relevantCols: IntSet; idgen: IdGenerator): PSym = var base = methods[0].ast[dispatcherPos].sym result = base var paramLen = base.typ.len @@ -254,6 +254,10 @@ proc genDispatcher(g: ModuleGraph; methods: seq[PSym], relevantCols: IntSet): PS curr.typ[col], false, g.config) var ret: PNode if retTyp != nil: + createTypeBoundOps(g, nil, retTyp, base.info, idgen) + if tfHasAsgn in result.typ.flags or optSeqDestructors in g.config.globalOptions: + base.flags.incl sfInjectDestructors + var a = newNodeI(nkFastAsgn, base.info) a.add newSymNode(base.ast[resultPos].sym) a.add call @@ -272,7 +276,7 @@ proc genDispatcher(g: ModuleGraph; methods: seq[PSym], relevantCols: IntSet): PS nilchecks.flags.incl nfTransf # should not be further transformed result.ast[bodyPos] = nilchecks -proc generateMethodDispatchers*(g: ModuleGraph): PNode = +proc generateMethodDispatchers*(g: ModuleGraph, idgen: IdGenerator): PNode = result = newNode(nkStmtList) for bucket in 0..