Skip to content

Commit

Permalink
fixes #21617; createTypeBoundOps with PContext in order to instantiat…
Browse files Browse the repository at this point in the history
…e generics (#21619)

* fixes #21617; createTypeBoundOps with PContext in order to instantiate generics

* keep idgen
  • Loading branch information
ringabout authored Apr 7, 2023
1 parent 814d3e6 commit a37a83c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
7 changes: 3 additions & 4 deletions compiler/cgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ proc genProcBody(p: BProc; procBody: PNode) =
proc isNoReturn(m: BModule; s: PSym): bool {.inline.} =
sfNoReturn in s.flags and m.config.exc != excGoto

proc genProcAux(m: BModule, prc: PSym) =
proc genProcAux*(m: BModule, prc: PSym) =
var p = newProc(prc, m)
var header = newRopeAppender()
genProcHeader(m, prc, header)
Expand Down Expand Up @@ -2107,7 +2107,7 @@ proc updateCachedModule(m: BModule) =
cf.flags = {CfileFlag.Cached}
addFileToCompile(m.config, cf)

proc finalCodegenActions*(graph: ModuleGraph; m: BModule; n: PNode) =
proc finalCodegenActions*(graph: ModuleGraph; m: BModule; n: PNode): PNode =
## Also called from IC.
if sfMainModule in m.module.flags:
# phase ordering problem here: We need to announce this
Expand Down Expand Up @@ -2153,8 +2153,7 @@ proc finalCodegenActions*(graph: ModuleGraph; m: BModule; n: PNode) =

if m.g.forwardedProcs.len == 0:
incl m.flags, objHasKidsValid
let disp = generateMethodDispatchers(graph, m.idgen)
for x in disp: genProcAux(m, x.sym)
result = generateMethodDispatchers(graph, m.idgen)

let mm = m
m.g.modulesClosed.add mm
Expand Down
6 changes: 1 addition & 5 deletions compiler/cgmeth.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import
intsets, options, ast, msgs, idents, renderer, types, magicsys,
sempass2, modulegraphs, lineinfos, liftdestructors
sempass2, modulegraphs, lineinfos

when defined(nimPreviewSlimSystem):
import std/assertions
Expand Down Expand Up @@ -254,10 +254,6 @@ proc genDispatcher(g: ModuleGraph; methods: seq[PSym], relevantCols: IntSet; idg
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
Expand Down
5 changes: 4 additions & 1 deletion compiler/ic/cbackend.nim
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ proc generateCodeForModule(g: ModuleGraph; m: var LoadedModule; alive: var Alive
let n = unpackTree(g, m.module.position, m.fromDisk.topLevel, p)
cgen.genTopLevelStmt(bmod, n)

finalCodegenActions(g, bmod, newNodeI(nkStmtList, m.module.info))
let disps = finalCodegenActions(g, bmod, newNodeI(nkStmtList, m.module.info))
if disps != nil:
for disp in disps:
genProcAux(bmod, disp.sym)
m.fromDisk.backendFlags = cgen.whichInitProcs(bmod)

proc replayTypeInfo(g: ModuleGraph; m: var LoadedModule; origin: FileIndex) =
Expand Down
14 changes: 12 additions & 2 deletions compiler/pipelines.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sem, cgen, modulegraphs, ast, llstream, parser, msgs,
lineinfos, reorder, options, semdata, cgendata, modules, pathutils,
packages, syntaxes, depends, vm, pragmas, idents, lookups, wordrecg
packages, syntaxes, depends, vm, pragmas, idents, lookups, wordrecg,
liftdestructors

import pipelineutils

Expand Down Expand Up @@ -176,7 +177,16 @@ proc processPipelineModule*(graph: ModuleGraph; module: PSym; idgen: IdGenerator
case graph.pipelinePass
of CgenPass:
if bModule != nil:
finalCodegenActions(graph, BModule(bModule), finalNode)
let disps = finalCodegenActions(graph, BModule(bModule), finalNode)
if disps != nil:
let ctx = preparePContext(graph, module, idgen)
for disp in disps:
let retTyp = disp.sym.typ[0]
if retTyp != nil:
# todo properly semcheck the code of dispatcher?
createTypeBoundOps(graph, ctx, retTyp, disp.info, idgen)
genProcAux(BModule(bModule), disp.sym)
discard closePContext(graph, ctx, nil)
of JSgenPass:
when not defined(leanCompiler):
discard finalJSCodeGen(graph, bModule, finalNode)
Expand Down
6 changes: 6 additions & 0 deletions tests/arc/tarcmisc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ block: # bug #19857

import std/options

# bug #21592
type Event* = object
code*: string

Expand All @@ -608,3 +609,8 @@ type App* = ref object of RootObj

method process*(self: App): Option[Event] {.base.} =
raise Exception.new_exception("not impl")

# bug #21617
type Test2 = ref object of RootObj

method bug(t: Test2): seq[float] {.base.} = discard

0 comments on commit a37a83c

Please sign in to comment.