This commit is contained in:
Andreas Rumpf 2020-09-16 17:26:13 +02:00 • committed by GitHub
commit ae4ede6b00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 144 additions and 4 deletions

View file

@ -891,6 +891,9 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
processOnOffSwitchG(conf, {optProfileVM}, arg, pass, info)
of "sinkinference":
processOnOffSwitch(conf, {optSinkInference}, arg, pass, info)
of "cursorinference":
# undocumented, for debugging purposes only:
processOnOffSwitch(conf, {optCursorInference}, arg, pass, info)
of "panics":
processOnOffSwitchG(conf, {optPanics}, arg, pass, info)
if optPanics in conf.globalOptions:

View file

@ -1006,7 +1006,8 @@ proc injectDestructorCalls*(g: ModuleGraph; owner: PSym; n: PNode): PNode =
echoCfg(c.g)
echo n
computeCursors(owner, n, g.config)
if optCursorInference in g.config.options:
computeCursors(owner, n, g.config)
var scope: Scope
let body = p(n, c, scope, normal)

View file

@ -41,6 +41,7 @@ type # please make sure we have under 32 options
optMemTracker,
optNilSeqs,
optSinkInference # 'sink T' inference
optCursorInference
TOptions* = set[TOption]
@ -372,7 +373,7 @@ const
DefaultOptions* = {optObjCheck, optFieldCheck, optRangeCheck,
optBoundsCheck, optOverflowCheck, optAssert, optWarns, optRefCheck,
optHints, optStackTrace, optLineTrace, # consider adding `optStackTraceMsgs`
optTrMacros, optStyleCheck}
optTrMacros, optStyleCheck, optCursorInference}
DefaultGlobalOptions* = {optThreadAnalysis,
optExcessiveStackTrace, optListFullPaths}

View file

@ -392,9 +392,18 @@ proc deps(c: var Partitions; dest, src: PNode) =
analyseAsgn(c, c.s[vid], src)
# do not borrow from a different local variable, this is easier
# than tracking reassignments, consider 'var cursor = local; local = newNode()'
if src.kind == nkSym and (src.sym.kind in {skVar, skResult, skTemp} or
if src.kind == nkSym:
if (src.sym.kind in {skVar, skResult, skTemp} or
(src.sym.kind in {skLet, skParam, skForVar} and hasDisabledAsgn(src.sym.typ))):
c.s[vid].flags.incl preventCursor
c.s[vid].flags.incl preventCursor
elif src.sym.kind in {skVar, skResult, skTemp, skLet, skForVar}:
# XXX: we need to compute variable alive ranges before doing anything else:
let srcid = variableId(c, src.sym)
if srcid >= 0 and preventCursor in c.s[srcid].flags:
# you cannot borrow from a local that lives shorter than 'vid':
if c.s[srcid].aliveStart > c.s[vid].aliveStart or
c.s[srcid].aliveEnd < c.s[vid].aliveEnd:
c.s[vid].flags.incl preventCursor
if src.kind == nkSym and hasDestructor(src.typ):
rhsIsSink(c, src)