summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2023-04-01 23:08:45 +0800
committerGitHub <noreply@github.com>2023-04-01 17:08:45 +0200
commita80f1a324fff0b2af47c0766750b3188bcab8041 (patch)
tree49ba2c45bdafa566acf5fb30b0c77244431117fc
parent1c7fd717206c79be400f81a05eee771823b880ca (diff)
downloadNim-a80f1a324fff0b2af47c0766750b3188bcab8041.tar.gz
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
-rw-r--r--compiler/cgen.nim2
-rw-r--r--compiler/cgmeth.nim12
-rw-r--r--compiler/jsgen.nim2
-rw-r--r--tests/arc/tarcmisc.nim11
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..<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))
diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim
index d0a143793..a20492740 100644
--- a/compiler/jsgen.nim
+++ b/compiler/jsgen.nim
@@ -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):
diff --git a/tests/arc/tarcmisc.nim b/tests/arc/tarcmisc.nim
index 1ae1782a4..b08669774 100644
--- a/tests/arc/tarcmisc.nim
+++ b/tests/arc/tarcmisc.nim
@@ -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")
dd4a4145 ^





1159f9ec ^
dd4a4145 ^


1159f9ec ^
dd4a4145 ^


1159f9ec ^
1159f9ec ^


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159