diff --git a/compiler/backend/cgirgen.nim b/compiler/backend/cgirgen.nim index 6ddc7297b2..c41d129696 100644 --- a/compiler/backend/cgirgen.nim +++ b/compiler/backend/cgirgen.nim @@ -166,18 +166,6 @@ proc newDefaultCall(info: TLineInfo, typ: PType): CgNode = ## Produces the tree for a ``default`` magic call. newExpr(cnkCall, info, typ, [newMagicNode(mDefault, info)]) -proc wrapInHiddenAddr(cl: TranslateCl, n: CgNode): CgNode = - ## Restores the ``cnkHiddenAddr`` around lvalue expressions passed to ``var`` - ## parameters. The code-generators operating on ``CgNode``-IR depend on the - ## hidden addr to be present - if n.typ.skipTypes(abstractInst).kind != tyVar: - newOp(cnkHiddenAddr, n.info, makeVarType(cl.owner, n.typ, cl.idgen), n) - else: - # XXX: is this case ever reached? It should not be. Raw ``var`` values - # must never be passed directly to ``var`` parameters at the MIR - # level - n - proc genObjConv(n: CgNode, to: PType, info: TLineInfo): CgNode = ## Depending on the type relationship between `n` and `to`, wraps `n` in ## either an up- or down-conversion. Returns `nil` if no up- or down- @@ -419,7 +407,10 @@ proc callToIr(tree: MirBody, cl: var TranslateCl, n: MirNode, # XXX: prevent this case from happening arg = newOp(cnkDerefView, arg.info, arg.typ.base, arg) elif mutable: - arg = wrapInHiddenAddr(cl, arg) + # much like in PNode AST, the CGIR AST also needs a ``cnkHiddenAddr`` + # tree wrapped around expressions in var argument positions + arg = newOp(cnkHiddenAddr, arg.info, + makeVarType(cl.owner, arg.typ, cl.idgen), arg) result.add arg diff --git a/compiler/backend/cgmeth.nim b/compiler/backend/cgmeth.nim index 1d3396f40c..4ee32287aa 100644 --- a/compiler/backend/cgmeth.nim +++ b/compiler/backend/cgmeth.nim @@ -284,6 +284,15 @@ proc genDispatcher(g: ModuleGraph; methods: seq[PSym], relevantCols: IntSet) = if param.typ.skipTypes(abstractInst).kind in {tyRef, tyPtr}: nilchecks.add newTree(nkCall, newSymNode(getCompilerProc(g, "chckNilDisp")), newSymNode(param)) + + proc param(s: PSym): PNode {.nimcall.} = + if s.typ.kind == tyVar: + newTreeIT(nkHiddenAddr, s.info, s.typ, + newTreeIT(nkHiddenDeref, s.info, s.typ.base, + newSymNode(s))) + else: + newSymNode(s) + for meth in 0..high(methods): var curr = methods[meth] # generate condition: var cond: PNode = nil @@ -291,8 +300,7 @@ proc genDispatcher(g: ModuleGraph; methods: seq[PSym], relevantCols: IntSet) = if contains(relevantCols, col): var isn = newNodeIT(nkCall, base.info, boolType) isn.add newSymNode(iss) - let param = base.typ.n[col].sym - isn.add newSymNode(param) + isn.add param(base.typ.n[col].sym) isn.add newNodeIT(nkType, base.info, curr.typ[col]) if cond != nil: var a = newNodeIT(nkCall, base.info, boolType) @@ -306,8 +314,8 @@ proc genDispatcher(g: ModuleGraph; methods: seq[PSym], relevantCols: IntSet) = let call = newNodeIT(nkCall, base.info, retTyp) call.add newSymNode(curr) for col in 1..