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
This commit is contained in:
ringabout
2023-04-01 23:08:45 +08:00
committed by GitHub
parent 1c7fd71720
commit a80f1a324f
4 changed files with 21 additions and 6 deletions

View File

@@ -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

View File

@@ -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..<g.methods.len:
var relevantCols = initIntSet()
@@ -282,4 +286,4 @@ proc generateMethodDispatchers*(g: ModuleGraph): PNode =
# if multi-methods are not enabled, we are interested only in the first field
break
sortBucket(g.methods[bucket].methods, relevantCols)
result.add newSymNode(genDispatcher(g, g.methods[bucket].methods, relevantCols))
result.add newSymNode(genDispatcher(g, g.methods[bucket].methods, relevantCols, idgen))

View File

@@ -2855,7 +2855,7 @@ proc wholeCode(graph: ModuleGraph; m: BModule): Rope =
var p = newInitProc(globals, m)
attachProc(p, prc)
var disp = generateMethodDispatchers(graph)
var disp = generateMethodDispatchers(graph, m.idgen)
for i in 0..<disp.len:
let prc = disp[i].sym
if not globals.generatedSyms.containsOrIncl(prc.id):

View File

@@ -597,3 +597,14 @@ block: # bug #19857
let res = v.toF()
foo()
import std/options
type Event* = object
code*: string
type App* = ref object of RootObj
id*: string
method process*(self: App): Option[Event] {.base.} =
raise Exception.new_exception("not impl")