revert changes

This commit is contained in:
Andrii Riabushenko 2019-07-25 23:18:20 +01:00
commit 4c73139316
12 changed files with 43 additions and 80 deletions

View file

@ -480,8 +480,7 @@ proc formatMsg*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string): s
title & title &
getMessageStr(msg, arg) getMessageStr(msg, arg)
proc liMessage(conf: ConfigRef; notes: TNoteKinds, options: TOptions, proc liMessage(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
info: TLineInfo, msg: TMsgKind, arg: string,
eh: TErrorHandling) = eh: TErrorHandling) =
var var
title: string title: string
@ -501,16 +500,15 @@ proc liMessage(conf: ConfigRef; notes: TNoteKinds, options: TOptions,
conf.m.lastError = info conf.m.lastError = info
of warnMin..warnMax: of warnMin..warnMax:
sev = Severity.Warning sev = Severity.Warning
ignoreMsg = optWarns notin options or msg notin notes ignoreMsg = optWarns notin conf.options or msg notin conf.notes
if not ignoreMsg: writeContext(conf, info) if not ignoreMsg: writeContext(conf, info)
title = WarningTitle title = WarningTitle
color = WarningColor color = WarningColor
kind = WarningsToStr[ord(msg) - ord(warnMin)] kind = WarningsToStr[ord(msg) - ord(warnMin)]
inc(conf.warnCounter) inc(conf.warnCounter)
of hintMin..hintMax: of hintMin..hintMax:
sev = Severity.Hint sev = Severity.Hint
ignoreMsg = optHints notin options or msg notin notes ignoreMsg = optHints notin conf.options or msg notin conf.notes
title = HintTitle title = HintTitle
color = HintColor color = HintColor
if msg != hintUserRaw: kind = HintsToStr[ord(msg) - ord(hintMin)] if msg != hintUserRaw: kind = HintsToStr[ord(msg) - ord(hintMin)]
@ -536,34 +534,30 @@ proc fatal*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
# this fixes bug #7080 so that it is at least obvious 'fatal' # this fixes bug #7080 so that it is at least obvious 'fatal'
# was executed. # was executed.
conf.m.errorOutputs = {eStdOut, eStdErr} conf.m.errorOutputs = {eStdOut, eStdErr}
liMessage(conf, conf.notes, conf.options, info, msg, arg, doAbort) liMessage(conf, info, msg, arg, doAbort)
proc globalError*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") = proc globalError*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
liMessage(conf, conf.notes, conf.options, info, msg, arg, doRaise) liMessage(conf, info, msg, arg, doRaise)
proc globalError*(conf: ConfigRef; info: TLineInfo, arg: string) = proc globalError*(conf: ConfigRef; info: TLineInfo, arg: string) =
liMessage(conf, conf.notes, conf.options, info, errGenerated, arg, doRaise) liMessage(conf, info, errGenerated, arg, doRaise)
proc localError*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") = proc localError*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
liMessage(conf, conf.notes, conf.options, info, msg, arg, doNothing) liMessage(conf, info, msg, arg, doNothing)
proc localError*(conf: ConfigRef; info: TLineInfo, arg: string) = proc localError*(conf: ConfigRef; info: TLineInfo, arg: string) =
liMessage(conf, conf.notes, conf.options, info, errGenerated, arg, doNothing) liMessage(conf, info, errGenerated, arg, doNothing)
proc localError*(conf: ConfigRef; info: TLineInfo, format: string, params: openArray[string]) = proc localError*(conf: ConfigRef; info: TLineInfo, format: string, params: openArray[string]) =
localError(conf, info, format % params) localError(conf, info, format % params)
proc message*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") = proc message*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
liMessage(conf, conf.notes, conf.options, info, msg, arg, doNothing) liMessage(conf, info, msg, arg, doNothing)
proc message*(conf: ConfigRef; notes: TNoteKinds, options: TOptions;
info: TLineInfo, msg: TMsgKind, arg = "") =
liMessage(conf, notes, options, info, msg, arg, doNothing)
proc internalError*(conf: ConfigRef; info: TLineInfo, errMsg: string) = proc internalError*(conf: ConfigRef; info: TLineInfo, errMsg: string) =
if conf.cmd == cmdIdeTools and conf.structuredErrorHook.isNil: return if conf.cmd == cmdIdeTools and conf.structuredErrorHook.isNil: return
writeContext(conf, info) writeContext(conf, info)
liMessage(conf, conf.notes, conf.options, info, errInternal, errMsg, doAbort) liMessage(conf, info, errInternal, errMsg, doAbort)
proc internalError*(conf: ConfigRef; errMsg: string) = proc internalError*(conf: ConfigRef; errMsg: string) =
if conf.cmd == cmdIdeTools and conf.structuredErrorHook.isNil: return if conf.cmd == cmdIdeTools and conf.structuredErrorHook.isNil: return

View file

@ -321,12 +321,8 @@ proc processNote(c: PContext, n: PNode) =
let x = c.semConstBoolExpr(c, n[1]) let x = c.semConstBoolExpr(c, n[1])
n.sons[1] = x n.sons[1] = x
if x.kind == nkIntLit and x.intVal != 0: if x.kind == nkIntLit and x.intVal != 0: incl(c.config.notes, nk)
incl(c.config.notes, nk) else: excl(c.config.notes, nk)
incl(c.optionStack[^1].notes, nk)
else:
excl(c.config.notes, nk)
excl(c.optionStack[^1].notes, nk)
else: else:
invalidPragma(c, n) invalidPragma(c, n)

View file

@ -467,7 +467,7 @@ proc semMacroExpr(c: PContext, n, nOrig: PNode, sym: PSym,
if efNoSemCheck notin flags: if efNoSemCheck notin flags:
result = semAfterMacroCall(c, n, result, sym, flags) result = semAfterMacroCall(c, n, result, sym, flags)
if c.config.macrosToExpand.hasKey(sym.name.s): if c.config.macrosToExpand.hasKey(sym.name.s):
message(c, nOrig.info, hintExpandMacro, renderTree(result)) message(c.config, nOrig.info, hintExpandMacro, renderTree(result))
result = wrapInComesFrom(nOrig.info, sym, result) result = wrapInComesFrom(nOrig.info, sym, result)
popInfoContext(c.config) popInfoContext(c.config)
@ -620,7 +620,7 @@ proc myProcess(context: PPassContext, n: PNode): PNode =
proc reportUnusedModules(c: PContext) = proc reportUnusedModules(c: PContext) =
for i in 0..high(c.unusedImports): for i in 0..high(c.unusedImports):
message(c, c.unusedImports[i][1], warnUnusedImportX, c.unusedImports[i][0].name.s) message(c.config, c.unusedImports[i][1], warnUnusedImportX, c.unusedImports[i][0].name.s)
proc myClose(graph: ModuleGraph; context: PPassContext, n: PNode): PNode = proc myClose(graph: ModuleGraph; context: PPassContext, n: PNode): PNode =
var c = PContext(context) var c = PContext(context)

View file

@ -526,7 +526,7 @@ proc semOverloadedCall(c: PContext, n, nOrig: PNode,
# this may be triggered, when the explain pragma is used # this may be triggered, when the explain pragma is used
if errors.len > 0: if errors.len > 0:
let (_, candidates) = presentFailedCandidates(c, n, errors) let (_, candidates) = presentFailedCandidates(c, n, errors)
message(c, n.info, hintUserRaw, message(c.config, n.info, hintUserRaw,
"Non-matching candidates for " & renderTree(n) & "\n" & "Non-matching candidates for " & renderTree(n) & "\n" &
candidates) candidates)
result = semResolvedCall(c, r, n, flags) result = semResolvedCall(c, r, n, flags)

View file

@ -171,9 +171,6 @@ proc popOwner*(c: PContext) =
proc lastOptionEntry*(c: PContext): POptionEntry = proc lastOptionEntry*(c: PContext): POptionEntry =
result = c.optionStack[^1] result = c.optionStack[^1]
proc message*(c: PContext, info: TLineInfo, msg: TMsgKind, arg = "") =
message(c.config, c.lastOptionEntry.notes, c.lastOptionEntry.options, info, msg, arg)
proc popProcCon*(c: PContext) {.inline.} = c.p = c.p.next proc popProcCon*(c: PContext) {.inline.} = c.p = c.p.next
proc put*(p: PProcCon; key, val: PSym) = proc put*(p: PProcCon; key, val: PSym) =

View file

@ -289,7 +289,7 @@ proc semConv(c: PContext, n: PNode): PNode =
elif op.kind in {nkPar, nkTupleConstr} and targetType.kind == tyTuple: elif op.kind in {nkPar, nkTupleConstr} and targetType.kind == tyTuple:
op = fitNode(c, targetType, op, result.info) op = fitNode(c, targetType, op, result.info)
of convNotNeedeed: of convNotNeedeed:
message(c, n.info, hintConvFromXtoItselfNotNeeded, result.typ.typeToString) message(c.config, n.info, hintConvFromXtoItselfNotNeeded, result.typ.typeToString)
of convNotLegal: of convNotLegal:
result = fitNode(c, result.typ, result.sons[1], result.info) result = fitNode(c, result.typ, result.sons[1], result.info)
if result == nil: if result == nil:
@ -2588,7 +2588,7 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
result.kind = nkCall result.kind = nkCall
result = semExpr(c, result, flags) result = semExpr(c, result, flags)
of nkBind: of nkBind:
message(c, n.info, warnDeprecated, "bind is deprecated") message(c.config, n.info, warnDeprecated, "bind is deprecated")
result = semExpr(c, n.sons[0], flags) result = semExpr(c, n.sons[0], flags)
of nkTypeOfExpr, nkTupleTy, nkTupleClassTy, nkRefTy..nkEnumTy, nkStaticTy: of nkTypeOfExpr, nkTupleTy, nkTupleClassTy, nkRefTy..nkEnumTy, nkStaticTy:
if c.matchedConcept != nil and n.len == 1: if c.matchedConcept != nil and n.len == 1:

View file

@ -305,7 +305,7 @@ proc semOf(c: PContext, n: PNode): PNode =
# | returns: `maxint` iff `a` and `b` are not compatible at all # | returns: `maxint` iff `a` and `b` are not compatible at all
if diff <= 0: if diff <= 0:
# optimize to true: # optimize to true:
message(c, n.info, hintConditionAlwaysTrue, renderTree(n)) message(c.config, n.info, hintConditionAlwaysTrue, renderTree(n))
result = newIntNode(nkIntLit, 1) result = newIntNode(nkIntLit, 1)
result.info = n.info result.info = n.info
result.typ = getSysType(c.graph, n.info, tyBool) result.typ = getSysType(c.graph, n.info, tyBool)
@ -314,7 +314,7 @@ proc semOf(c: PContext, n: PNode): PNode =
if commonSuperclass(a, b) == nil: if commonSuperclass(a, b) == nil:
localError(c.config, n.info, "'$1' cannot be of this subtype" % typeToString(a)) localError(c.config, n.info, "'$1' cannot be of this subtype" % typeToString(a))
else: else:
message(c, n.info, hintConditionAlwaysFalse, renderTree(n)) message(c.config, n.info, hintConditionAlwaysFalse, renderTree(n))
result = newIntNode(nkIntLit, 0) result = newIntNode(nkIntLit, 0)
result.info = n.info result.info = n.info
result.typ = getSysType(c.graph, n.info, tyBool) result.typ = getSysType(c.graph, n.info, tyBool)

View file

@ -221,33 +221,33 @@ else:
if not a.inEnforcedNoSideEffects: a.hasSideEffect = true if not a.inEnforcedNoSideEffects: a.hasSideEffect = true
markGcUnsafe(a, reason) markGcUnsafe(a, reason)
proc listGcUnsafety(s: PSym; onlyWarning: bool; cycleCheck: var IntSet; c: PContext) = proc listGcUnsafety(s: PSym; onlyWarning: bool; cycleCheck: var IntSet; conf: ConfigRef) =
let u = s.gcUnsafetyReason let u = s.gcUnsafetyReason
if u != nil and not cycleCheck.containsOrIncl(u.id): if u != nil and not cycleCheck.containsOrIncl(u.id):
let msgKind = if onlyWarning: warnGcUnsafe2 else: errGenerated let msgKind = if onlyWarning: warnGcUnsafe2 else: errGenerated
case u.kind case u.kind
of skLet, skVar: of skLet, skVar:
message(c, s.info, msgKind, message(conf, s.info, msgKind,
("'$#' is not GC-safe as it accesses '$#'" & ("'$#' is not GC-safe as it accesses '$#'" &
" which is a global using GC'ed memory") % [s.name.s, u.name.s]) " which is a global using GC'ed memory") % [s.name.s, u.name.s])
of routineKinds: of routineKinds:
# recursive call *always* produces only a warning so the full error # recursive call *always* produces only a warning so the full error
# message is printed: # message is printed:
listGcUnsafety(u, true, cycleCheck, c) listGcUnsafety(u, true, cycleCheck, conf)
message(c, s.info, msgKind, message(conf, s.info, msgKind,
"'$#' is not GC-safe as it calls '$#'" % "'$#' is not GC-safe as it calls '$#'" %
[s.name.s, u.name.s]) [s.name.s, u.name.s])
of skParam, skForVar: of skParam, skForVar:
message(c, s.info, msgKind, message(conf, s.info, msgKind,
"'$#' is not GC-safe as it performs an indirect call via '$#'" % "'$#' is not GC-safe as it performs an indirect call via '$#'" %
[s.name.s, u.name.s]) [s.name.s, u.name.s])
else: else:
message(c, u.info, msgKind, message(conf, u.info, msgKind,
"'$#' is not GC-safe as it performs an indirect call here" % s.name.s) "'$#' is not GC-safe as it performs an indirect call here" % s.name.s)
proc listGcUnsafety(s: PSym; onlyWarning: bool; c: PContext) = proc listGcUnsafety(s: PSym; onlyWarning: bool; conf: ConfigRef) =
var cycleCheck = initIntSet() var cycleCheck = initIntSet()
listGcUnsafety(s, onlyWarning, cycleCheck, c) listGcUnsafety(s, onlyWarning, cycleCheck, conf)
proc useVar(a: PEffects, n: PNode) = proc useVar(a: PEffects, n: PNode) =
let s = n.sym let s = n.sym
@ -257,9 +257,9 @@ proc useVar(a: PEffects, n: PNode) =
a.init.add s.id a.init.add s.id
elif s.id notin a.init: elif s.id notin a.init:
if {tfNeedsInit, tfNotNil} * s.typ.flags != {}: if {tfNeedsInit, tfNotNil} * s.typ.flags != {}:
message(a.c, n.info, warnProveInit, s.name.s) message(a.config, n.info, warnProveInit, s.name.s)
else: else:
message(a.c, n.info, warnUninit, s.name.s) message(a.config, n.info, warnUninit, s.name.s)
# prevent superfluous warnings about the same variable: # prevent superfluous warnings about the same variable:
a.init.add s.id a.init.add s.id
if {sfGlobal, sfThread} * s.flags != {} and s.kind in {skVar, skLet} and if {sfGlobal, sfThread} * s.flags != {} and s.kind in {skVar, skLet} and
@ -983,7 +983,7 @@ proc trackProc*(c: PContext; s: PSym, body: PNode) =
s.kind in {skProc, skFunc, skConverter, skMethod}: s.kind in {skProc, skFunc, skConverter, skMethod}:
var res = s.ast.sons[resultPos].sym # get result symbol var res = s.ast.sons[resultPos].sym # get result symbol
if res.id notin t.init: if res.id notin t.init:
message(c, body.info, warnProveInit, "result") message(g.config, body.info, warnProveInit, "result")
let p = s.ast.sons[pragmasPos] let p = s.ast.sons[pragmasPos]
let raisesSpec = effectSpec(p, wRaises) let raisesSpec = effectSpec(p, wRaises)
if not isNil(raisesSpec): if not isNil(raisesSpec):
@ -1002,13 +1002,13 @@ proc trackProc*(c: PContext; s: PSym, body: PNode) =
if sfThread in s.flags and t.gcUnsafe: if sfThread in s.flags and t.gcUnsafe:
if optThreads in g.config.globalOptions and optThreadAnalysis in g.config.globalOptions: if optThreads in g.config.globalOptions and optThreadAnalysis in g.config.globalOptions:
#localError(s.info, "'$1' is not GC-safe" % s.name.s) #localError(s.info, "'$1' is not GC-safe" % s.name.s)
listGcUnsafety(s, onlyWarning=false, c) listGcUnsafety(s, onlyWarning=false, g.config)
else: else:
listGcUnsafety(s, onlyWarning=true, c) listGcUnsafety(s, onlyWarning=true, g.config)
#localError(s.info, warnGcUnsafe2, s.name.s) #localError(s.info, warnGcUnsafe2, s.name.s)
if sfNoSideEffect in s.flags and t.hasSideEffect: if sfNoSideEffect in s.flags and t.hasSideEffect:
when false: when false:
listGcUnsafety(s, onlyWarning=false, c) listGcUnsafety(s, onlyWarning=false, g.config)
else: else:
localError(g.config, s.info, "'$1' can have side effects" % s.name.s) localError(g.config, s.info, "'$1' can have side effects" % s.name.s)
if not t.gcUnsafe: if not t.gcUnsafe:
@ -1019,7 +1019,7 @@ proc trackProc*(c: PContext; s: PSym, body: PNode) =
s.typ.lockLevel = t.maxLockLevel s.typ.lockLevel = t.maxLockLevel
elif t.maxLockLevel > s.typ.lockLevel: elif t.maxLockLevel > s.typ.lockLevel:
#localError(s.info, #localError(s.info,
message(c, s.info, warnLockLevel, message(g.config, s.info, warnLockLevel,
"declared lock level is $1, but real lock level is $2" % "declared lock level is $1, but real lock level is $2" %
[$s.typ.lockLevel, $t.maxLockLevel]) [$s.typ.lockLevel, $t.maxLockLevel])
when defined(useDfa): when defined(useDfa):

View file

@ -337,9 +337,9 @@ proc checkNilable(c: PContext; v: PSym) =
if {sfGlobal, sfImportc} * v.flags == {sfGlobal} and if {sfGlobal, sfImportc} * v.flags == {sfGlobal} and
{tfNotNil, tfNeedsInit} * v.typ.flags != {}: {tfNotNil, tfNeedsInit} * v.typ.flags != {}:
if v.astdef.isNil: if v.astdef.isNil:
message(c, v.info, warnProveInit, v.name.s) message(c.config, v.info, warnProveInit, v.name.s)
elif tfNotNil in v.typ.flags and not v.astdef.typ.isNil and tfNotNil notin v.astdef.typ.flags: elif tfNotNil in v.typ.flags and not v.astdef.typ.isNil and tfNotNil notin v.astdef.typ.flags:
message(c, v.info, warnProveInit, v.name.s) message(c.config, v.info, warnProveInit, v.name.s)
#include liftdestructors #include liftdestructors
@ -511,7 +511,7 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
addToVarSection(c, result, n, b) addToVarSection(c, result, n, b)
elif tup.kind == tyTuple and def.kind in {nkPar, nkTupleConstr} and elif tup.kind == tyTuple and def.kind in {nkPar, nkTupleConstr} and
a.kind == nkIdentDefs and a.len > 3: a.kind == nkIdentDefs and a.len > 3:
message(c, a.info, warnEachIdentIsTuple) message(c.config, a.info, warnEachIdentIsTuple)
for j in 0 .. length-3: for j in 0 .. length-3:
if a[j].kind == nkDotExpr: if a[j].kind == nkDotExpr:
@ -533,7 +533,7 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
if shadowed != nil: if shadowed != nil:
shadowed.flags.incl(sfShadowed) shadowed.flags.incl(sfShadowed)
if shadowed.kind == skResult and sfGenSym notin v.flags: if shadowed.kind == skResult and sfGenSym notin v.flags:
message(c, a.info, warnResultShadowed) message(c.config, a.info, warnResultShadowed)
if a.kind != nkVarTuple: if a.kind != nkVarTuple:
if def.kind != nkEmpty: if def.kind != nkEmpty:
if sfThread in v.flags: localError(c.config, def.info, errThreadvarCannotInit) if sfThread in v.flags: localError(c.config, def.info, errThreadvarCannotInit)
@ -576,7 +576,7 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
addSon(x, result[i]) addSon(x, result[i])
vm.setupCompileTimeVar(c.module, c.graph, x) vm.setupCompileTimeVar(c.module, c.graph, x)
if v.flags * {sfGlobal, sfThread} == {sfGlobal}: if v.flags * {sfGlobal, sfThread} == {sfGlobal}:
message(c, v.info, hintGlobalVar) message(c.config, v.info, hintGlobalVar)
proc semConst(c: PContext, n: PNode): PNode = proc semConst(c: PContext, n: PNode): PNode =
result = copyNode(n) result = copyNode(n)
@ -1714,7 +1714,7 @@ proc semMethodPrototype(c: PContext; s: PSym; n: PNode) =
if x.kind == tyObject and t.len-1 == n.sons[genericParamsPos].len: if x.kind == tyObject and t.len-1 == n.sons[genericParamsPos].len:
foundObj = true foundObj = true
x.methods.add((col,s)) x.methods.add((col,s))
message(c, n.info, warnDeprecated, "generic methods are deprecated") message(c.config, n.info, warnDeprecated, "generic methods are deprecated")
#if not foundObj: #if not foundObj:
# message(c.config, n.info, warnDeprecated, "generic method not attachable to object type is deprecated") # message(c.config, n.info, warnDeprecated, "generic method not attachable to object type is deprecated")
else: else:

View file

@ -853,9 +853,9 @@ proc semAnyRef(c: PContext; n: PNode; kind: TTypeKind; prev: PType): PType =
let region = semTypeNode(c, ni, nil) let region = semTypeNode(c, ni, nil)
if region.skipTypes({tyGenericInst, tyAlias, tySink}).kind notin { if region.skipTypes({tyGenericInst, tyAlias, tySink}).kind notin {
tyError, tyObject}: tyError, tyObject}:
message c, n[i].info, errGenerated, "region needs to be an object type" message c.config, n[i].info, errGenerated, "region needs to be an object type"
else: else:
message(c, n.info, warnDeprecated, "region for pointer types is deprecated") message(c.config, n.info, warnDeprecated, "region for pointer types is deprecated")
addSonSkipIntLit(result, region) addSonSkipIntLit(result, region)
addSonSkipIntLit(result, t) addSonSkipIntLit(result, t)
if tfPartial in result.flags: if tfPartial in result.flags:
@ -1215,7 +1215,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
"`void` or no return type declaration at all has the same " & "`void` or no return type declaration at all has the same " &
"meaning as the current meaning of `typed` as return type " & "meaning as the current meaning of `typed` as return type " &
"declaration." "declaration."
message(c, info, warnDeprecated, msg) message(c.config, info, warnDeprecated, msg)
r = nil r = nil
if r != nil: if r != nil:

View file

@ -1,17 +0,0 @@
discard """
nimout: '''
compile start
Hint: warn_module [Processing]
Hint: hashes [Processing]
warn_module.nim(4, 6) Hint: 'test' is declared but not used [XDeclaredButNotUsed]
compile end
'''
"""
static:
echo "compile start"
import warn_module
static:
echo "compile end"

View file

@ -1,7 +0,0 @@
{.warning[UnusedImport]: off.}
import hashes
proc test(a: float): float =
a