[refactoring] liftdestructors is now a module of its own

This commit is contained in:
Araq 2019-06-12 08:27:02 +02:00
commit c07973e313
4 changed files with 16 additions and 17 deletions

View file

@ -10,12 +10,11 @@
## This module implements lifting for type-bound operations ## This module implements lifting for type-bound operations
## (``=sink``, ``=``, ``=destroy``, ``=deepCopy``). ## (``=sink``, ``=``, ``=destroy``, ``=deepCopy``).
# included from sempass2.nim
# Todo: # Todo:
# - use openArray instead of array to avoid over-specializations # - use openArray instead of array to avoid over-specializations
import sighashes import modulegraphs, lineinfos, idents, ast, astalgo, renderer, semdata,
sighashes, lowerings, options, types, msgs, magicsys, tables
type type
TLiftCtx = object TLiftCtx = object
@ -135,8 +134,8 @@ proc considerAsgnOrSink(c: var TLiftCtx; t: PType; body, x, y: PNode;
if field != nil and sfOverriden in field.flags: if field != nil and sfOverriden in field.flags:
if sfError in op.flags: if sfError in op.flags:
incl c.fn.flags, sfError incl c.fn.flags, sfError
else: #else:
markUsed(c.graph.config, c.info, op, c.graph.usageSym) # markUsed(c.graph.config, c.info, op, c.graph.usageSym)
onUse(c.info, op) onUse(c.info, op)
body.add newAsgnCall(c.graph, op, x, y) body.add newAsgnCall(c.graph, op, x, y)
result = true result = true
@ -155,8 +154,8 @@ proc considerAsgnOrSink(c: var TLiftCtx; t: PType; body, x, y: PNode;
op = produceSym(c.c, t, c.kind, c.info) op = produceSym(c.c, t, c.kind, c.info)
if sfError in op.flags: if sfError in op.flags:
incl c.fn.flags, sfError incl c.fn.flags, sfError
else: #else:
markUsed(c.graph.config, c.info, op, c.graph.usageSym) # markUsed(c.graph.config, c.info, op, c.graph.usageSym)
onUse(c.info, op) onUse(c.info, op)
# We also now do generic instantiations in the destructor lifting pass: # We also now do generic instantiations in the destructor lifting pass:
if op.ast[genericParamsPos].kind != nkEmpty: if op.ast[genericParamsPos].kind != nkEmpty:
@ -179,7 +178,7 @@ proc addDestructorCall(c: var TLiftCtx; t: PType; body, x: PNode) =
doAssert op == t.destructor doAssert op == t.destructor
if op != nil: if op != nil:
markUsed(c.graph.config, c.info, op, c.graph.usageSym) #markUsed(c.graph.config, c.info, op, c.graph.usageSym)
onUse(c.info, op) onUse(c.info, op)
body.add destructorCall(c.graph, op, x) body.add destructorCall(c.graph, op, x)
elif useNoGc(c, t): elif useNoGc(c, t):
@ -198,7 +197,7 @@ proc considerUserDefinedOp(c: var TLiftCtx; t: PType; body, x, y: PNode): bool =
op = c.c.instTypeBoundOp(c.c, op, t.typeInst, c.info, attachedAsgn, 1) op = c.c.instTypeBoundOp(c.c, op, t.typeInst, c.info, attachedAsgn, 1)
t.attachedOps[attachedDestructor] = op t.attachedOps[attachedDestructor] = op
markUsed(c.graph.config, c.info, op, c.graph.usageSym) #markUsed(c.graph.config, c.info, op, c.graph.usageSym)
onUse(c.info, op) onUse(c.info, op)
body.add destructorCall(c.graph, op, x) body.add destructorCall(c.graph, op, x)
result = true result = true
@ -210,7 +209,7 @@ proc considerUserDefinedOp(c: var TLiftCtx; t: PType; body, x, y: PNode): bool =
of attachedDeepCopy: of attachedDeepCopy:
let op = t.attachedOps[attachedDeepCopy] let op = t.attachedOps[attachedDeepCopy]
if op != nil: if op != nil:
markUsed(c.graph.config, c.info, op, c.graph.usageSym) #markUsed(c.graph.config, c.info, op, c.graph.usageSym)
onUse(c.info, op) onUse(c.info, op)
body.add newDeepCopyCall(op, x, y) body.add newDeepCopyCall(op, x, y)
result = true result = true

View file

@ -844,6 +844,7 @@ proc afterCallActions(c: PContext; n, orig: PNode, flags: TExprFlags): PNode =
analyseIfAddressTakenInCall(c, result) analyseIfAddressTakenInCall(c, result)
if callee.magic != mNone: if callee.magic != mNone:
result = magicsAfterOverloadResolution(c, result, flags) result = magicsAfterOverloadResolution(c, result, flags)
when false:
if result.typ != nil and if result.typ != nil and
not (result.typ.kind == tySequence and result.typ.sons[0].kind == tyEmpty): not (result.typ.kind == tySequence and result.typ.sons[0].kind == tyEmpty):
liftTypeBoundOps(c, result.typ, n.info) liftTypeBoundOps(c, result.typ, n.info)
@ -1689,8 +1690,7 @@ proc semAsgn(c: PContext, n: PNode; mode=asgnNormal): PNode =
borrowCheck(c, n, lhs, rhs) borrowCheck(c, n, lhs, rhs)
n.sons[1] = fitNode(c, le, rhs, goodLineInfo(n[1])) n.sons[1] = fitNode(c, le, rhs, goodLineInfo(n[1]))
liftTypeBoundOps(c, lhs.typ, lhs.info) when false: liftTypeBoundOps(c, lhs.typ, lhs.info)
#liftTypeBoundOps(c, n.sons[0].typ, n.sons[0].info)
fixAbstractType(c, n) fixAbstractType(c, n)
asgnToResultVar(c, n, n.sons[0], n.sons[1]) asgnToResultVar(c, n, n.sons[0], n.sons[1])

View file

@ -18,7 +18,7 @@ when not defined(leanCompiler):
when defined(useDfa): when defined(useDfa):
import dfa import dfa
include liftdestructors import liftdestructors
#[ Second semantic checking pass over the AST. Necessary because the old #[ Second semantic checking pass over the AST. Necessary because the old
way had some inherent problems. Performs: way had some inherent problems. Performs:

View file

@ -493,7 +493,7 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
# this can only happen for errornous var statements: # this can only happen for errornous var statements:
if typ == nil: continue if typ == nil: continue
typeAllowedCheck(c.config, a.info, typ, symkind, if c.matchedConcept != nil: {taConcept} else: {}) typeAllowedCheck(c.config, a.info, typ, symkind, if c.matchedConcept != nil: {taConcept} else: {})
liftTypeBoundOps(c, typ, a.info) when false: liftTypeBoundOps(c, typ, a.info)
instAllTypeBoundOp(c, a.info) instAllTypeBoundOp(c, a.info)
var tup = skipTypes(typ, {tyGenericInst, tyAlias, tySink}) var tup = skipTypes(typ, {tyGenericInst, tyAlias, tySink})
if a.kind == nkVarTuple: if a.kind == nkVarTuple: