From 4c73139316fc7853b58f298a978ccd95aac6abe8 Mon Sep 17 00:00:00 2001 From: Andrii Riabushenko Date: Thu, 25 Jul 2019 23:18:20 +0100 Subject: [PATCH] revert changes --- compiler/msgs.nim | 26 ++++++++++---------------- compiler/pragmas.nim | 8 ++------ compiler/sem.nim | 4 ++-- compiler/semcall.nim | 2 +- compiler/semdata.nim | 3 --- compiler/semexprs.nim | 4 ++-- compiler/semmagic.nim | 4 ++-- compiler/sempass2.nim | 30 +++++++++++++++--------------- compiler/semstmts.nim | 12 ++++++------ compiler/semtypes.nim | 6 +++--- tests/pragmas/twarning_off.nim | 17 ----------------- tests/pragmas/warn_module.nim | 7 ------- 12 files changed, 43 insertions(+), 80 deletions(-) delete mode 100644 tests/pragmas/twarning_off.nim delete mode 100644 tests/pragmas/warn_module.nim diff --git a/compiler/msgs.nim b/compiler/msgs.nim index 667ea5791f..1264133a9d 100644 --- a/compiler/msgs.nim +++ b/compiler/msgs.nim @@ -480,8 +480,7 @@ proc formatMsg*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string): s title & getMessageStr(msg, arg) -proc liMessage(conf: ConfigRef; notes: TNoteKinds, options: TOptions, - info: TLineInfo, msg: TMsgKind, arg: string, +proc liMessage(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string, eh: TErrorHandling) = var title: string @@ -501,16 +500,15 @@ proc liMessage(conf: ConfigRef; notes: TNoteKinds, options: TOptions, conf.m.lastError = info of warnMin..warnMax: 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) title = WarningTitle color = WarningColor kind = WarningsToStr[ord(msg) - ord(warnMin)] inc(conf.warnCounter) - of hintMin..hintMax: sev = Severity.Hint - ignoreMsg = optHints notin options or msg notin notes + ignoreMsg = optHints notin conf.options or msg notin conf.notes title = HintTitle color = HintColor 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' # was executed. 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 = "") = - liMessage(conf, conf.notes, conf.options, info, msg, arg, doRaise) + liMessage(conf, info, msg, arg, doRaise) 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 = "") = - liMessage(conf, conf.notes, conf.options, info, msg, arg, doNothing) + liMessage(conf, info, msg, arg, doNothing) 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]) = localError(conf, info, format % params) proc message*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") = - liMessage(conf, conf.notes, conf.options, 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) + liMessage(conf, info, msg, arg, doNothing) proc internalError*(conf: ConfigRef; info: TLineInfo, errMsg: string) = if conf.cmd == cmdIdeTools and conf.structuredErrorHook.isNil: return 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) = if conf.cmd == cmdIdeTools and conf.structuredErrorHook.isNil: return diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 93ac290273..9e3976e733 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -321,12 +321,8 @@ proc processNote(c: PContext, n: PNode) = let x = c.semConstBoolExpr(c, n[1]) n.sons[1] = x - if x.kind == nkIntLit and x.intVal != 0: - incl(c.config.notes, nk) - incl(c.optionStack[^1].notes, nk) - else: - excl(c.config.notes, nk) - excl(c.optionStack[^1].notes, nk) + if x.kind == nkIntLit and x.intVal != 0: incl(c.config.notes, nk) + else: excl(c.config.notes, nk) else: invalidPragma(c, n) diff --git a/compiler/sem.nim b/compiler/sem.nim index 2bc83309a8..e331705535 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -467,7 +467,7 @@ proc semMacroExpr(c: PContext, n, nOrig: PNode, sym: PSym, if efNoSemCheck notin flags: result = semAfterMacroCall(c, n, result, sym, flags) 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) popInfoContext(c.config) @@ -620,7 +620,7 @@ proc myProcess(context: PPassContext, n: PNode): PNode = proc reportUnusedModules(c: PContext) = 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 = var c = PContext(context) diff --git a/compiler/semcall.nim b/compiler/semcall.nim index b61f2d1b1c..aa263fdee3 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -526,7 +526,7 @@ proc semOverloadedCall(c: PContext, n, nOrig: PNode, # this may be triggered, when the explain pragma is used if errors.len > 0: let (_, candidates) = presentFailedCandidates(c, n, errors) - message(c, n.info, hintUserRaw, + message(c.config, n.info, hintUserRaw, "Non-matching candidates for " & renderTree(n) & "\n" & candidates) result = semResolvedCall(c, r, n, flags) diff --git a/compiler/semdata.nim b/compiler/semdata.nim index 45f3e454ab..76eb468edc 100644 --- a/compiler/semdata.nim +++ b/compiler/semdata.nim @@ -171,9 +171,6 @@ proc popOwner*(c: PContext) = proc lastOptionEntry*(c: PContext): POptionEntry = 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 put*(p: PProcCon; key, val: PSym) = diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 316b4ab781..733df2c404 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -289,7 +289,7 @@ proc semConv(c: PContext, n: PNode): PNode = elif op.kind in {nkPar, nkTupleConstr} and targetType.kind == tyTuple: op = fitNode(c, targetType, op, result.info) of convNotNeedeed: - message(c, n.info, hintConvFromXtoItselfNotNeeded, result.typ.typeToString) + message(c.config, n.info, hintConvFromXtoItselfNotNeeded, result.typ.typeToString) of convNotLegal: result = fitNode(c, result.typ, result.sons[1], result.info) if result == nil: @@ -2588,7 +2588,7 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode = result.kind = nkCall result = semExpr(c, result, flags) 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) of nkTypeOfExpr, nkTupleTy, nkTupleClassTy, nkRefTy..nkEnumTy, nkStaticTy: if c.matchedConcept != nil and n.len == 1: diff --git a/compiler/semmagic.nim b/compiler/semmagic.nim index c5507aa412..6956e9eca1 100644 --- a/compiler/semmagic.nim +++ b/compiler/semmagic.nim @@ -305,7 +305,7 @@ proc semOf(c: PContext, n: PNode): PNode = # | returns: `maxint` iff `a` and `b` are not compatible at all if diff <= 0: # optimize to true: - message(c, n.info, hintConditionAlwaysTrue, renderTree(n)) + message(c.config, n.info, hintConditionAlwaysTrue, renderTree(n)) result = newIntNode(nkIntLit, 1) result.info = n.info result.typ = getSysType(c.graph, n.info, tyBool) @@ -314,7 +314,7 @@ proc semOf(c: PContext, n: PNode): PNode = if commonSuperclass(a, b) == nil: localError(c.config, n.info, "'$1' cannot be of this subtype" % typeToString(a)) else: - message(c, n.info, hintConditionAlwaysFalse, renderTree(n)) + message(c.config, n.info, hintConditionAlwaysFalse, renderTree(n)) result = newIntNode(nkIntLit, 0) result.info = n.info result.typ = getSysType(c.graph, n.info, tyBool) diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim index ba21a4fb82..8252a78574 100644 --- a/compiler/sempass2.nim +++ b/compiler/sempass2.nim @@ -221,33 +221,33 @@ else: if not a.inEnforcedNoSideEffects: a.hasSideEffect = true 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 if u != nil and not cycleCheck.containsOrIncl(u.id): let msgKind = if onlyWarning: warnGcUnsafe2 else: errGenerated case u.kind of skLet, skVar: - message(c, s.info, msgKind, + message(conf, s.info, msgKind, ("'$#' is not GC-safe as it accesses '$#'" & " which is a global using GC'ed memory") % [s.name.s, u.name.s]) of routineKinds: # recursive call *always* produces only a warning so the full error # message is printed: - listGcUnsafety(u, true, cycleCheck, c) - message(c, s.info, msgKind, + listGcUnsafety(u, true, cycleCheck, conf) + message(conf, s.info, msgKind, "'$#' is not GC-safe as it calls '$#'" % [s.name.s, u.name.s]) of skParam, skForVar: - message(c, s.info, msgKind, + message(conf, s.info, msgKind, "'$#' is not GC-safe as it performs an indirect call via '$#'" % [s.name.s, u.name.s]) 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) -proc listGcUnsafety(s: PSym; onlyWarning: bool; c: PContext) = +proc listGcUnsafety(s: PSym; onlyWarning: bool; conf: ConfigRef) = var cycleCheck = initIntSet() - listGcUnsafety(s, onlyWarning, cycleCheck, c) + listGcUnsafety(s, onlyWarning, cycleCheck, conf) proc useVar(a: PEffects, n: PNode) = let s = n.sym @@ -257,9 +257,9 @@ proc useVar(a: PEffects, n: PNode) = a.init.add s.id elif s.id notin a.init: 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: - 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: a.init.add s.id 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}: var res = s.ast.sons[resultPos].sym # get result symbol 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 raisesSpec = effectSpec(p, wRaises) 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 optThreads in g.config.globalOptions and optThreadAnalysis in g.config.globalOptions: #localError(s.info, "'$1' is not GC-safe" % s.name.s) - listGcUnsafety(s, onlyWarning=false, c) + listGcUnsafety(s, onlyWarning=false, g.config) else: - listGcUnsafety(s, onlyWarning=true, c) + listGcUnsafety(s, onlyWarning=true, g.config) #localError(s.info, warnGcUnsafe2, s.name.s) if sfNoSideEffect in s.flags and t.hasSideEffect: when false: - listGcUnsafety(s, onlyWarning=false, c) + listGcUnsafety(s, onlyWarning=false, g.config) else: localError(g.config, s.info, "'$1' can have side effects" % s.name.s) if not t.gcUnsafe: @@ -1019,7 +1019,7 @@ proc trackProc*(c: PContext; s: PSym, body: PNode) = s.typ.lockLevel = t.maxLockLevel elif t.maxLockLevel > s.typ.lockLevel: #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" % [$s.typ.lockLevel, $t.maxLockLevel]) when defined(useDfa): diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 8488e16cff..402816078e 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -337,9 +337,9 @@ proc checkNilable(c: PContext; v: PSym) = if {sfGlobal, sfImportc} * v.flags == {sfGlobal} and {tfNotNil, tfNeedsInit} * v.typ.flags != {}: 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: - message(c, v.info, warnProveInit, v.name.s) + message(c.config, v.info, warnProveInit, v.name.s) #include liftdestructors @@ -511,7 +511,7 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode = addToVarSection(c, result, n, b) elif tup.kind == tyTuple and def.kind in {nkPar, nkTupleConstr} and a.kind == nkIdentDefs and a.len > 3: - message(c, a.info, warnEachIdentIsTuple) + message(c.config, a.info, warnEachIdentIsTuple) for j in 0 .. length-3: if a[j].kind == nkDotExpr: @@ -533,7 +533,7 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode = if shadowed != nil: shadowed.flags.incl(sfShadowed) 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 def.kind != nkEmpty: 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]) vm.setupCompileTimeVar(c.module, c.graph, x) if v.flags * {sfGlobal, sfThread} == {sfGlobal}: - message(c, v.info, hintGlobalVar) + message(c.config, v.info, hintGlobalVar) proc semConst(c: PContext, n: PNode): PNode = 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: foundObj = true 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: # message(c.config, n.info, warnDeprecated, "generic method not attachable to object type is deprecated") else: diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 3840bdd4d6..e7fbc83ecd 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -853,9 +853,9 @@ proc semAnyRef(c: PContext; n: PNode; kind: TTypeKind; prev: PType): PType = let region = semTypeNode(c, ni, nil) if region.skipTypes({tyGenericInst, tyAlias, tySink}).kind notin { 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: - 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, t) 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 " & "meaning as the current meaning of `typed` as return type " & "declaration." - message(c, info, warnDeprecated, msg) + message(c.config, info, warnDeprecated, msg) r = nil if r != nil: diff --git a/tests/pragmas/twarning_off.nim b/tests/pragmas/twarning_off.nim deleted file mode 100644 index 1b86c62995..0000000000 --- a/tests/pragmas/twarning_off.nim +++ /dev/null @@ -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" diff --git a/tests/pragmas/warn_module.nim b/tests/pragmas/warn_module.nim deleted file mode 100644 index 0d1e5f4192..0000000000 --- a/tests/pragmas/warn_module.nim +++ /dev/null @@ -1,7 +0,0 @@ - -{.warning[UnusedImport]: off.} - -import hashes - -proc test(a: float): float = - a