diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index db627144db29..8595efb0a4dd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -239,7 +239,7 @@ without control flow statements. This was done successfully in src/dmd/escape.d, it wasn't easy, but it was well worth it. -17. Try to eliminate reliance on `global.errors`, use `dmd.errorsink: ErrorSink` instead. +17. Try to eliminate reliance on `global.diag.errors`, use `dmd.errorsink: ErrorSink` instead. 18. For aggregates that expose public access to fields, think hard about why this is necessary and if it can be done better. Merely replacing them with read/write properties diff --git a/compiler/src/dmd/astbase.d b/compiler/src/dmd/astbase.d index bdc489871c36..bb001bed4065 100644 --- a/compiler/src/dmd/astbase.d +++ b/compiler/src/dmd/astbase.d @@ -2502,7 +2502,7 @@ struct ASTBase extern (D) this() { super(Loc.initial, STMT.Error); - assert(global.gaggedErrors || global.errors); + assert(global.diag.gaggedErrors || global.diag.errors); } override void accept(Visitor v) @@ -6350,7 +6350,7 @@ struct ASTBase if (errorexp is null) errorexp = new ErrorExp(); - if (global.errors == 0 && global.gaggedErrors == 0) + if (global.diag.errors == 0 && global.diag.gaggedErrors == 0) { /* Unfortunately, errors can still leak out of gagged errors, * and we need to set the error count to prevent bogus code diff --git a/compiler/src/dmd/blockexit.d b/compiler/src/dmd/blockexit.d index dc3e379e8d4b..25ba5e30583c 100644 --- a/compiler/src/dmd/blockexit.d +++ b/compiler/src/dmd/blockexit.d @@ -108,7 +108,7 @@ int blockExit(Statement s, FuncDeclaration func, ErrorSink eSink) void visitMixin(MixinStatement s) { - assert(global.errors); + assert(global.diag.errors); result = BE.fallthru; } @@ -177,7 +177,7 @@ int blockExit(Statement s, FuncDeclaration func, ErrorSink eSink) void visitWhile(WhileStatement s) { - assert(global.errors); + assert(global.diag.errors); result = BE.fallthru; } @@ -249,7 +249,7 @@ int blockExit(Statement s, FuncDeclaration func, ErrorSink eSink) void visitForeachRange(ForeachRangeStatement s) { - assert(global.errors); + assert(global.diag.errors); result = BE.fallthru; } diff --git a/compiler/src/dmd/canthrow.d b/compiler/src/dmd/canthrow.d index 5738ae37afc8..f7f74f2637d2 100644 --- a/compiler/src/dmd/canthrow.d +++ b/compiler/src/dmd/canthrow.d @@ -106,7 +106,7 @@ CT canThrow(Expression e, FuncDeclaration func, ErrorSink eSink) if (ce.inDebugStatement) return; - if (global.errors && !ce.e1.type) + if (global.diag.errors && !ce.e1.type) return; // error recovery if (ce.f && ce.arguments.length > 0) diff --git a/compiler/src/dmd/clone.d b/compiler/src/dmd/clone.d index bbfb1ee9f87d..dd7ccb3b8d45 100644 --- a/compiler/src/dmd/clone.d +++ b/compiler/src/dmd/clone.d @@ -110,7 +110,7 @@ FuncDeclaration hasIdentityOpAssign(AggregateDeclaration ad, Scope* sc) scope er = new NullExp(ad.loc, ad.type); // dummy rvalue scope el = new IdentifierExp(ad.loc, Id.p); // dummy lvalue el.type = ad.type; - const errors = global.startGagging(); // Do not report errors, even if the template opAssign fbody makes it. + const errors = global.diag.startGagging(); // Do not report errors, even if the template opAssign fbody makes it. sc = sc.push(); sc.tinst = null; sc.minst = null; @@ -125,7 +125,7 @@ FuncDeclaration hasIdentityOpAssign(AggregateDeclaration ad, Scope* sc) } sc = sc.pop(); - global.endGagging(errors); + global.diag.endGagging(errors); if (!f) return null; if (f.errors) @@ -385,7 +385,7 @@ FuncDeclaration buildOpAssign(StructDeclaration sd, Scope* sc) sd.members.push(fop); fop.addMember(sc, sd); sd.hasIdentityAssign = true; // temporary mark identity assignable - const errors = global.startGagging(); // Do not report errors, even if the template opAssign fbody makes it. + const errors = global.diag.startGagging(); // Do not report errors, even if the template opAssign fbody makes it. Scope* sc2 = sc.push(); sc2.stc = 0; sc2.linkage = LINK.d; @@ -395,7 +395,7 @@ FuncDeclaration buildOpAssign(StructDeclaration sd, Scope* sc) //semantic3(fop, sc2); // isn't run here for lazy forward reference resolution. sc2.pop(); - if (global.endGagging(errors)) // if errors happened + if (global.diag.endGagging(errors)) // if errors happened { // Disable generated opAssign, because some members forbid identity assignment. fop.storage_class |= STC.disable; @@ -494,7 +494,7 @@ private FuncDeclaration hasIdentityOpEquals(AggregateDeclaration ad, Scope* sc) bool hasIt(Type tthis) { - const errors = global.startGagging(); // Do not report errors, even if the template opAssign fbody makes it + const errors = global.diag.startGagging(); // Do not report errors, even if the template opAssign fbody makes it sc = sc.push(); sc.tinst = null; sc.minst = null; @@ -511,7 +511,7 @@ private FuncDeclaration hasIdentityOpEquals(AggregateDeclaration ad, Scope* sc) f = rfc(el); sc = sc.pop(); - global.endGagging(errors); + global.diag.endGagging(errors); return f !is null; } @@ -614,14 +614,14 @@ FuncDeclaration buildXopEquals(StructDeclaration sd, Scope* sc) Expression e2 = new IdentifierExp(loc, Id.p); Expression e = new EqualExp(EXP.equal, loc, e1, e2); fop.fbody = new ReturnStatement(loc, e); - const errors = global.startGagging(); // Do not report errors + const errors = global.diag.startGagging(); // Do not report errors Scope* sc2 = sc.push(); sc2.stc = 0; sc2.linkage = LINK.d; fop.dsymbolSemantic(sc2); fop.semantic2(sc2); sc2.pop(); - if (global.endGagging(errors)) // if errors happened + if (global.diag.endGagging(errors)) // if errors happened fop = sd.xerreq; return fop; } @@ -738,14 +738,14 @@ FuncDeclaration buildXopCmp(StructDeclaration sd, Scope* sc) Expression e2 = new IdentifierExp(loc, Id.p); Expression e = new CallExp(loc, new DotIdExp(loc, e1, Id.cmp), e2); fop.fbody = new ReturnStatement(loc, e); - const errors = global.startGagging(); // Do not report errors + const errors = global.diag.startGagging(); // Do not report errors Scope* sc2 = sc.push(); sc2.stc = 0; sc2.linkage = LINK.d; fop.dsymbolSemantic(sc2); fop.semantic2(sc2); sc2.pop(); - if (global.endGagging(errors)) // if errors happened + if (global.diag.endGagging(errors)) // if errors happened fop = sd.xerrcmp; return fop; } @@ -1617,7 +1617,7 @@ private Statement generateCopyCtorBody(StructDeclaration sd) */ bool needCopyCtor(StructDeclaration sd, out bool hasCpCtor) { - if (global.errors) + if (global.diag.errors) return false; auto ctor = sd.search(sd.loc, Id.ctor); @@ -1731,7 +1731,7 @@ bool buildCopyCtor(StructDeclaration sd, Scope* sc) ccd.fbody = copyCtorBody; sd.members.push(ccd); ccd.addMember(sc, sd); - const errors = global.startGagging(); + const errors = global.diag.startGagging(); Scope* sc2 = sc.push(); sc2.stc = 0; sc2.linkage = LINK.d; @@ -1740,7 +1740,7 @@ bool buildCopyCtor(StructDeclaration sd, Scope* sc) ccd.semantic3(sc2); //printf("ccd semantic: %s\n", ccd.type.toChars()); sc2.pop(); - if (global.endGagging(errors) || sd.isUnionDeclaration()) + if (global.diag.endGagging(errors) || sd.isUnionDeclaration()) { ccd.storage_class |= STC.disable; ccd.fbody = null; diff --git a/compiler/src/dmd/cond.d b/compiler/src/dmd/cond.d index cffc412367d2..13b2c519c79b 100644 --- a/compiler/src/dmd/cond.d +++ b/compiler/src/dmd/cond.d @@ -382,9 +382,9 @@ extern (C++) final class StaticForeach : RootObject // Run 'typeof' gagged to avoid duplicate errors and if it fails just create // an empty foreach to expose them. - const olderrors = global.startGagging(); + const olderrors = global.diag.startGagging(); ety = ety.typeSemantic(aloc, sc); - if (global.endGagging(olderrors)) + if (global.diag.endGagging(olderrors)) s2.push(createForeach(aloc, pparams[1], null)); else { @@ -924,7 +924,7 @@ extern (C++) final class StaticIfCondition : Condition int errorReturn() { - if (!global.gag) + if (!global.diag.gag) inc = Include.no; // so we don't see the error message again return 0; } diff --git a/compiler/src/dmd/constfold.d b/compiler/src/dmd/constfold.d index 1578ef770a09..2fd56a33b2fd 100644 --- a/compiler/src/dmd/constfold.d +++ b/compiler/src/dmd/constfold.d @@ -654,7 +654,7 @@ UnionExp Equal(EXP op, const ref Loc loc, Type type, Expression e1, Expression e StringExp es2 = e2.isStringExp(); if (es1.sz != es2.sz) { - assert(global.errors); + assert(global.diag.errors); cantExp(ue); return ue; } @@ -1477,7 +1477,7 @@ UnionExp Cat(const ref Loc loc, Type type, Expression e1, Expression e2) /* Can happen with: * auto s = "foo"d ~ "bar"c; */ - assert(global.errors); + assert(global.diag.errors); cantExp(ue); assert(ue.exp().type); return ue; diff --git a/compiler/src/dmd/dcast.d b/compiler/src/dmd/dcast.d index 34b120b34125..595d6429eaef 100644 --- a/compiler/src/dmd/dcast.d +++ b/compiler/src/dmd/dcast.d @@ -2068,9 +2068,9 @@ Expression castTo(Expression e, Scope* sc, Type t, Type att = null) * cast(to)e1.aliasthis */ auto exp = resolveAliasThis(sc, e); - const errors = global.startGagging(); + const errors = global.diag.startGagging(); exp = castTo(exp, sc, t, att); - return global.endGagging(errors) ? null : exp; + return global.diag.endGagging(errors) ? null : exp; } bool hasAliasThis; diff --git a/compiler/src/dmd/declaration.d b/compiler/src/dmd/declaration.d index 995995400a55..521bc20a6002 100644 --- a/compiler/src/dmd/declaration.d +++ b/compiler/src/dmd/declaration.d @@ -619,7 +619,7 @@ extern (C++) final class AliasDeclaration : Declaration Dsymbol err() { // Avoid breaking "recursive alias" state during errors gagged - if (global.gag) + if (global.diag.gag) return this; aliassym = new AliasDeclaration(loc, ident, Type.terror); type = Type.terror; @@ -632,15 +632,15 @@ extern (C++) final class AliasDeclaration : Declaration if (inuse == 1 && type && _scope) { inuse = 2; - const olderrors = global.errors; + const olderrors = global.diag.errors; Dsymbol s = type.toDsymbol(_scope); //printf("[%s] type = %s, s = %p, this = %p\n", loc.toChars(), type.toChars(), s, this); - if (global.errors != olderrors) + if (global.diag.errors != olderrors) return err(); if (s) { s = s.toAlias(); - if (global.errors != olderrors) + if (global.diag.errors != olderrors) return err(); aliassym = s; inuse = 0; @@ -650,7 +650,7 @@ extern (C++) final class AliasDeclaration : Declaration Type t = type.typeSemantic(loc, _scope); if (t.ty == Terror) return err(); - if (global.errors != olderrors) + if (global.diag.errors != olderrors) return err(); //printf("t = %s\n", t.toChars()); inuse = 0; @@ -1099,12 +1099,12 @@ extern (C++) class VarDeclaration : Declaration assert(type && _init); // Ungag errors when not speculative - const oldgag = global.gag; - if (global.gag) + const oldgag = global.diag.gag; + if (global.diag.gag) { Dsymbol sym = isMember(); if (sym && !sym.isSpeculative()) - global.gag = 0; + global.diag.gag = 0; } if (_scope) @@ -1118,7 +1118,7 @@ extern (C++) class VarDeclaration : Declaration } Expression e = _init.initializerToExpression(needFullType ? type : null); - global.gag = oldgag; + global.diag.gag = oldgag; return e; } diff --git a/compiler/src/dmd/dinterpret.d b/compiler/src/dmd/dinterpret.d index 4e04a272141a..e5ad8bf690da 100644 --- a/compiler/src/dmd/dinterpret.d +++ b/compiler/src/dmd/dinterpret.d @@ -2121,7 +2121,7 @@ public: v.inuse++; e = interpret(e, istate); v.inuse--; - if (CTFEExp.isCantExp(e) && !global.gag && !ctfeGlobals.stackTraceCallsToSuppress) + if (CTFEExp.isCantExp(e) && !global.diag.gag && !ctfeGlobals.stackTraceCallsToSuppress) errorSupplemental(loc, "while evaluating %s.init", v.toChars()); if (exceptionOrCantInterpret(e)) return e; @@ -4992,7 +4992,7 @@ public: result = paintTypeOntoLiteral(pue, e.type, result); result.loc = e.loc; } - else if (CTFEExp.isCantExp(result) && !global.gag) + else if (CTFEExp.isCantExp(result) && !global.diag.gag) showCtfeBackTrace(e, fd); // Print a stack trace. } diff --git a/compiler/src/dmd/dmodule.d b/compiler/src/dmd/dmodule.d index 60dd0b3ce63c..25ba4cc89671 100644 --- a/compiler/src/dmd/dmodule.d +++ b/compiler/src/dmd/dmodule.d @@ -655,7 +655,7 @@ extern (C++) final class Module : Package cast(int)name.length, name.ptr, cast(int)pkgfile.length, pkgfile.ptr); } } - if (!global.gag) + if (!global.diag.gag) { /* Print path */ @@ -929,7 +929,7 @@ extern (C++) final class Module : Package error(md ? md.loc : loc, "%s `%s` from file %s conflicts with package name %s", kind, toPrettyChars, srcname, pkg.toChars()); } else - assert(global.errors); + assert(global.diag.errors); } else { @@ -1085,7 +1085,7 @@ extern (C++) final class Module : Package //printf("[%d] %s semantic2a\n", i, s.toPrettyChars()); s.semantic2(null); - if (global.errors) + if (global.diag.errors) break; } a.setDim(0); @@ -1102,7 +1102,7 @@ extern (C++) final class Module : Package //printf("[%d] %s semantic3a\n", i, s.toPrettyChars()); s.semantic3(null); - if (global.errors) + if (global.diag.errors) break; } a.setDim(0); @@ -1260,14 +1260,14 @@ extern (C++) final class Module : Package auto imp = new Import(Loc.initial, pkgids[], modid, null, true); // Module.load will call fatal() if there's no module available. // Gag the error here, pushing the error handling to the caller. - const errors = global.startGagging(); + const errors = global.diag.startGagging(); imp.load(null); if (imp.mod) { imp.mod.importAll(null); imp.mod.dsymbolSemantic(null); } - global.endGagging(errors); + global.diag.endGagging(errors); mod = imp.mod; return mod; } diff --git a/compiler/src/dmd/dscope.d b/compiler/src/dmd/dscope.d index 05cc8f156e11..cf26a9bac5fa 100644 --- a/compiler/src/dmd/dscope.d +++ b/compiler/src/dmd/dscope.d @@ -562,7 +562,7 @@ extern (C++) struct Scope extern (D) Dsymbol search_correct(Identifier ident) { - if (global.gag) + if (global.diag.gag) return null; // don't do it for speculative compiles; too time consuming /************************************************ diff --git a/compiler/src/dmd/dsymbol.d b/compiler/src/dmd/dsymbol.d index af32f7afa1e8..97483adca397 100644 --- a/compiler/src/dmd/dsymbol.d +++ b/compiler/src/dmd/dsymbol.d @@ -118,7 +118,7 @@ struct Ungag extern (C++) ~this() nothrow { - global.gag = oldgag; + global.diag.gag = oldgag; } } @@ -605,9 +605,9 @@ extern (C++) class Dsymbol : ASTNode final Ungag ungagSpeculative() const { - const oldgag = global.gag; - if (global.gag && !isSpeculative() && !toParent2().isFuncDeclaration()) - global.gag = 0; + const oldgag = global.diag.gag; + if (global.diag.gag && !isSpeculative() && !toParent2().isFuncDeclaration()) + global.diag.gag = 0; return Ungag(oldgag); } diff --git a/compiler/src/dmd/dsymbol.h b/compiler/src/dmd/dsymbol.h index e3bf30179c8c..374f0707473b 100644 --- a/compiler/src/dmd/dsymbol.h +++ b/compiler/src/dmd/dsymbol.h @@ -86,7 +86,7 @@ struct Ungag unsigned oldgag; Ungag(unsigned old) : oldgag(old) {} - ~Ungag() { global.gag = oldgag; } + ~Ungag() { global.diag.gag = oldgag; } }; enum class ThreeState : uint8_t diff --git a/compiler/src/dmd/dsymbolsem.d b/compiler/src/dmd/dsymbolsem.d index ec73e08858e2..568e07cd04ef 100644 --- a/compiler/src/dmd/dsymbolsem.d +++ b/compiler/src/dmd/dsymbolsem.d @@ -174,7 +174,7 @@ const(char)* getMessage(DeprecatedDeclaration dd) bool checkDeprecated(Dsymbol d, const ref Loc loc, Scope* sc) { - if (global.params.useDeprecated == DiagnosticReporting.off) + if (global.diag.useDeprecated == DiagnosticReporting.off) return false; if (!d.isDeprecated()) return false; @@ -314,10 +314,10 @@ Expression resolveAliasThis(Scope* sc, Expression e, bool gag = false, bool find Loc loc = e.loc; Type tthis = (e.op == EXP.type ? e.type : null); const flags = cast(DotExpFlag) (DotExpFlag.noAliasThis | (gag * DotExpFlag.gag)); - const olderrors = gag ? global.startGagging() : 0; + const olderrors = gag ? global.diag.startGagging() : 0; e = dotExp(ad.type, sc, e, ad.aliasthis.ident, flags); if (!e || findOnly) - return gag && global.endGagging(olderrors) ? null : e; + return gag && global.diag.endGagging(olderrors) ? null : e; if (tthis && ad.aliasthis.sym.needThis()) { @@ -355,7 +355,7 @@ Expression resolveAliasThis(Scope* sc, Expression e, bool gag = false, bool find e = resolveProperties(sc, e); if (!gag) ad.aliasthis.checkDeprecatedAliasThis(loc, sc); - else if (global.endGagging(olderrors)) + else if (global.diag.endGagging(olderrors)) e = null; } @@ -390,7 +390,7 @@ Expression resolveAliasThis(Scope* sc, Expression e, bool gag = false, bool find */ private bool checkDeprecatedAliasThis(AliasThis at, const ref Loc loc, Scope* sc) { - if (global.params.useDeprecated != DiagnosticReporting.off + if (global.diag.useDeprecated != DiagnosticReporting.off && at.isDeprecated() && !sc.isDeprecated()) { const(char)* message = null; @@ -1435,7 +1435,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor */ if (!inferred) { - const errors = global.errors; + const errors = global.diag.errors; dsym.inuse++; // Bug 20549. Don't try this on modules or packages, syntaxCopy // could crash (inf. recursion) on a mod/pkg referencing itself @@ -1498,7 +1498,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor dsym._init = dsym._init.initializerSemantic(sc, dsym.type, INITinterpret); dsym.inuse--; - if (global.errors > errors) + if (global.diag.errors > errors) { dsym._init = new ErrorInitializer(); dsym.type = Type.terror; @@ -1835,7 +1835,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor if (expressionsToString(buf, sc, cd.exps, cd.loc, null, true)) return null; - const errors = global.errors; + const errors = global.diag.errors; const len = buf.length; buf.writeByte(0); const str = buf.extractSlice()[0 .. len]; @@ -1845,7 +1845,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor p.nextToken(); auto d = p.parseDeclDefs(0); - if (global.errors != errors) + if (global.diag.errors != errors) return null; if (p.token.value != TOK.endOfFile) @@ -2214,7 +2214,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor tm.argsym.parent = scy.parent; Scope* argscope = scy.push(tm.argsym); - const errorsave = global.errors; + const errorsave = global.diag.errors; // Declare each template parameter as an alias for the argument type tm.declareParameters(argscope); @@ -2234,7 +2234,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor //printf("%d\n", nest); if (++nest > global.recursionLimit) { - global.gag = 0; // ensure error message gets printed + global.diag.gag = 0; // ensure error message gets printed .error(tm.loc, "%s `%s` recursive expansion", tm.kind, tm.toPrettyChars); fatal(); } @@ -2261,7 +2261,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor } // Give additional context info if error occurred during instantiation - if (global.errors != errorsave) + if (global.diag.errors != errorsave) { .error(tm.loc, "%s `%s` error instantiating", tm.kind, tm.toPrettyChars); tm.errors = true; @@ -2842,7 +2842,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor if (sd.semanticRun >= PASS.semanticdone) return; - const errors = global.errors; + const errors = global.diag.errors; //printf("+StructDeclaration::semantic(this=%p, '%s', sizeok = %d)\n", sd, sd.toPrettyChars(), sd.sizeok); Scope* scx = null; @@ -3004,13 +3004,13 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor Dsymbol scall = sd.search(Loc.initial, Id.call); if (scall) { - const xerrors = global.startGagging(); + const xerrors = global.diag.startGagging(); sc = sc.push(); sc.tinst = null; sc.minst = null; auto fcall = resolveFuncCall(sd.loc, sc, scall, null, null, ArgumentList(), FuncResolveFlag.quiet); sc = sc.pop(); - global.endGagging(xerrors); + global.diag.endGagging(xerrors); if (fcall && fcall.isStatic()) { @@ -3042,7 +3042,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor } } - if (global.errors != errors) + if (global.diag.errors != errors) { // The type is no good. sd.type = Type.terror; @@ -3051,7 +3051,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor sd.deferred.errors = true; } - if (sd.deferred && !global.gag) + if (sd.deferred && !global.diag.gag) { sd.deferred.semantic2(sc); sd.deferred.semantic3(sc); @@ -3089,7 +3089,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor if (cldec.semanticRun >= PASS.semanticdone) return; - const errors = global.errors; + const errors = global.diag.errors; //printf("+ClassDeclaration.dsymbolSemantic(%s), type = %p, sizeok = %d, this = %p\n", toChars(), type, sizeok, this); @@ -3697,7 +3697,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor .error(cldec.loc, "%s `%s` already exists at %s. Perhaps in another function with the same name?", cldec.kind, cldec.toPrettyChars, cd.loc.toChars()); } - if (global.errors != errors || (cldec.baseClass && cldec.baseClass.errors)) + if (global.diag.errors != errors || (cldec.baseClass && cldec.baseClass.errors)) { // The type is no good, but we should keep the // the type so that we have more accurate error messages @@ -3721,7 +3721,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor } } - if (cldec.deferred && !global.gag) + if (cldec.deferred && !global.diag.gag) { cldec.deferred.semantic2(sc); cldec.deferred.semantic3(sc); @@ -3752,7 +3752,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor //printf("InterfaceDeclaration.dsymbolSemantic(%s), type = %p\n", toChars(), type); if (idec.semanticRun >= PASS.semanticdone) return; - const errors = global.errors; + const errors = global.diag.errors; //printf("+InterfaceDeclaration.dsymbolSemantic(%s), type = %p\n", toChars(), type); @@ -4021,7 +4021,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor sc2.pop(); - if (global.errors != errors) + if (global.diag.errors != errors) { // The type is no good. idec.type = Type.terror; @@ -4488,7 +4488,7 @@ private bool isDRuntimeHook(Identifier id) void templateInstanceSemantic(TemplateInstance tempinst, Scope* sc, ArgumentList argumentList) { - //printf("[%s] TemplateInstance.dsymbolSemantic('%s', this=%p, gag = %d, sc = %p)\n", tempinst.loc.toChars(), tempinst.toChars(), tempinst, global.gag, sc); + //printf("[%s] TemplateInstance.dsymbolSemantic('%s', this=%p, gag = %d, sc = %p)\n", tempinst.loc.toChars(), tempinst.toChars(), tempinst, global.diag.gag, sc); version (none) { for (Dsymbol s = tempinst; s; s = s.parent) @@ -4521,9 +4521,9 @@ void templateInstanceSemantic(TemplateInstance tempinst, Scope* sc, ArgumentList { printf("Recursive template expansion\n"); } - auto ungag = Ungag(global.gag); + auto ungag = Ungag(global.diag.gag); if (!tempinst.gagged) - global.gag = 0; + global.diag.gag = 0; .error(tempinst.loc, "%s `%s` recursive template expansion", tempinst.kind, tempinst.toPrettyChars); if (tempinst.gagged) tempinst.semanticRun = PASS.initial; @@ -4546,7 +4546,7 @@ void templateInstanceSemantic(TemplateInstance tempinst, Scope* sc, ArgumentList tempinst.minst = null; } - tempinst.gagged = (global.gag > 0); + tempinst.gagged = (global.diag.gag > 0); tempinst.semanticRun = PASS.semantic; @@ -4636,8 +4636,8 @@ void templateInstanceSemantic(TemplateInstance tempinst, Scope* sc, ArgumentList // If both this and the previous instantiation were gagged, // use the number of errors that happened last time. - global.errors += tempinst.errors; - global.gaggedErrors += tempinst.errors; + global.diag.errors += tempinst.errors; + global.diag.gaggedErrors += tempinst.errors; // If the first instantiation was gagged, but this is not: if (tempinst.inst.gagged) @@ -4762,7 +4762,7 @@ void templateInstanceSemantic(TemplateInstance tempinst, Scope* sc, ArgumentList printf("\timplement template instance %s '%s'\n", tempdecl.parent.toChars(), tempinst.toChars()); printf("\ttempdecl %s\n", tempdecl.toChars()); } - const errorsave = global.errors; + const errorsave = global.diag.errors; tempinst.inst = tempinst; tempinst.parent = tempinst.enclosing ? tempinst.enclosing : tempdecl.parent; @@ -4910,7 +4910,7 @@ void templateInstanceSemantic(TemplateInstance tempinst, Scope* sc, ArgumentList } } - if (global.errors != errorsave) + if (global.diag.errors != errorsave) goto Laftersemantic; /* If any of the instantiation members didn't get semantic() run @@ -4952,7 +4952,7 @@ void templateInstanceSemantic(TemplateInstance tempinst, Scope* sc, ArgumentList */ tempinst.semantic2(sc2); } - if (global.errors != errorsave) + if (global.diag.errors != errorsave) goto Laftersemantic; if ((sc.func || sc.fullinst) && !tempinst.tinst) @@ -4973,13 +4973,13 @@ void templateInstanceSemantic(TemplateInstance tempinst, Scope* sc, ArgumentList * types. Deprecations are disabled while analysing hooks to avoid * spurious error messages. */ - auto saveUseDeprecated = global.params.useDeprecated; + auto saveUseDeprecated = global.diag.useDeprecated; if (sc.isDeprecated() && isDRuntimeHook(tempinst.name)) - global.params.useDeprecated = DiagnosticReporting.off; + global.diag.useDeprecated = DiagnosticReporting.off; tempinst.trySemantic3(sc2); - global.params.useDeprecated = saveUseDeprecated; + global.diag.useDeprecated = saveUseDeprecated; for (size_t i = 0; i < deferred.length; i++) { @@ -5048,7 +5048,7 @@ void templateInstanceSemantic(TemplateInstance tempinst, Scope* sc, ArgumentList ti = ti.tinst; if (++nest > global.recursionLimit) { - global.gag = 0; // ensure error message gets printed + global.diag.gag = 0; // ensure error message gets printed .error(tempinst.loc, "%s `%s` recursive expansion", tempinst.kind, tempinst.toPrettyChars); fatal(); } @@ -5092,7 +5092,7 @@ Laftersemantic: _scope.pop(); // Give additional context info if error occurred during instantiation - if (global.errors != errorsave) + if (global.diag.errors != errorsave) { if (!tempinst.errors) { @@ -5270,16 +5270,16 @@ void aliasSemantic(AliasDeclaration ds, Scope* sc) // type. If it is a symbol, then `.aliassym` is set and type is `null` - // toAlias() will return `.aliassym` - const errors = global.errors; + const errors = global.diag.errors; Type oldtype = ds.type; // Ungag errors when not instantiated DeclDefs scope alias - auto ungag = Ungag(global.gag); - //printf("%s parent = %s, gag = %d, instantiated = %d\n", ds.toChars(), ds.parent.toChars(), global.gag, ds.isInstantiated() !is null); - if (ds.parent && global.gag && !ds.isInstantiated() && !ds.toParent2().isFuncDeclaration() && (sc.minst || sc.tinst)) + auto ungag = Ungag(global.diag.gag); + //printf("%s parent = %s, gag = %d, instantiated = %d\n", ds.toChars(), ds.parent.toChars(), global.diag.gag, ds.isInstantiated() !is null); + if (ds.parent && global.diag.gag && !ds.isInstantiated() && !ds.toParent2().isFuncDeclaration() && (sc.minst || sc.tinst)) { //printf("%s type = %s\n", ds.toPrettyChars(), ds.type.toChars()); - global.gag = 0; + global.diag.gag = 0; } // https://issues.dlang.org/show_bug.cgi?id=18480 @@ -5323,7 +5323,7 @@ void aliasSemantic(AliasDeclaration ds, Scope* sc) * try to convert identifier x to 3. */ auto s = ds.type.toDsymbol(sc); - if (errors != global.errors) + if (errors != global.diag.errors) return errorRet(); if (s == ds) { @@ -5367,7 +5367,7 @@ void aliasSemantic(AliasDeclaration ds, Scope* sc) } if (s == ds) { - assert(global.errors); + assert(global.diag.errors); return errorRet(); } if (s) // it's a symbolic alias @@ -5383,7 +5383,7 @@ void aliasSemantic(AliasDeclaration ds, Scope* sc) ds.aliassym = null; } - if (global.gag && errors != global.errors) + if (global.diag.gag && errors != global.diag.errors) return errorRet(); normalRet(); @@ -5498,7 +5498,7 @@ private void aliasAssignSemantic(AliasAssign ds, Scope* sc) * It appears here as `ds.type`. Do semantic analysis on `def` to disambiguate. */ - const errors = global.errors; + const errors = global.diag.errors; Dsymbol s; // Try AliasSeq optimization @@ -5521,7 +5521,7 @@ private void aliasAssignSemantic(AliasAssign ds, Scope* sc) * try to convert identifier x to 3. */ s = ds.type.toDsymbol(sc); - if (errors != global.errors) + if (errors != global.diag.errors) return errorRet(); if (s == aliassym) { @@ -5566,7 +5566,7 @@ private void aliasAssignSemantic(AliasAssign ds, Scope* sc) } if (s == aliassym) { - assert(global.errors); + assert(global.diag.errors); return errorRet(); } @@ -5591,7 +5591,7 @@ private void aliasAssignSemantic(AliasAssign ds, Scope* sc) aliassym.adFlags &= ~Declaration.ignoreRead; if (aliassym.type && aliassym.type.ty == Terror || - global.gag && errors != global.errors) + global.diag.gag && errors != global.diag.errors) { aliassym.type = Type.terror; aliassym.aliassym = null; @@ -5965,7 +5965,7 @@ Dsymbol search_correct(Dsymbol d, Identifier ident) return s.search(Loc.initial, id, SearchOpt.ignoreErrors); } - if (global.gag) + if (global.diag.gag) return null; // don't do it for speculative compiles; too time consuming // search for exact name first if (auto s = d.search(Loc.initial, ident, SearchOpt.ignoreErrors)) @@ -6461,14 +6461,14 @@ private extern(C++) class SearchVisitor : Visitor return setResult(m.searchCacheSymbol); } - const errors = global.errors; + const errors = global.diag.errors; m.insearch = true; visit(cast(ScopeDsymbol)m); Dsymbol s = result; m.insearch = false; - if (errors == global.errors) + if (errors == global.diag.errors) { // https://issues.dlang.org/show_bug.cgi?id=10752 // Can cache the result only when it does not cause @@ -6873,7 +6873,7 @@ extern(C++) class ImportAllVisitor : Visitor extern (D) bool load(Import imp, Scope* sc) { // See if existing module - const errors = global.errors; + const errors = global.diag.errors; DsymbolTable dst = Package.resolve(imp.packages, null, &imp.pkg); version (none) { @@ -6899,7 +6899,7 @@ extern (D) bool load(Import imp, Scope* sc) { if (p.isPkgMod == PKG.unknown) { - const preverrors = global.errors; + const preverrors = global.diag.errors; imp.mod = Module.load(imp.loc, imp.packages, imp.id); if (!imp.mod) p.isPkgMod = PKG.package_; @@ -6911,7 +6911,7 @@ extern (D) bool load(Import imp, Scope* sc) else { // show error if Module.load does not - if (preverrors == global.errors) + if (preverrors == global.diag.errors) .error(imp.loc, "%s `%s` from file %s conflicts with %s `%s`", imp.mod.kind(), imp.mod.toPrettyChars(), imp.mod.srcfile.toChars, p.kind(), p.toPrettyChars()); return true; } @@ -6959,7 +6959,7 @@ extern (D) bool load(Import imp, Scope* sc) else imp.pkg = imp.mod; } - return global.errors != errors; + return global.diag.errors != errors; } void setFieldOffset(Dsymbol d, AggregateDeclaration ad, FieldState* fieldState, bool isunion) @@ -7697,7 +7697,7 @@ Lfail: error(loc, "%s `%s` no size because of forward reference", ad.kind, ad.toPrettyChars); // Don't cache errors from speculative semantic, might be resolvable later. // https://issues.dlang.org/show_bug.cgi?id=16574 - if (!global.gag) + if (!global.diag.gag) { ad.type = Type.terror; ad.errors = true; diff --git a/compiler/src/dmd/dtemplate.d b/compiler/src/dmd/dtemplate.d index 08f8d06f68b8..177fb18f0916 100644 --- a/compiler/src/dmd/dtemplate.d +++ b/compiler/src/dmd/dtemplate.d @@ -3858,9 +3858,9 @@ extern (C++) class TemplateInstance : ScopeDsymbol * max_shown = maximum number of trace elements printed (controlled with -v/-verror-limit) */ extern(D) final void printInstantiationTrace(Classification cl = Classification.error, - const(uint) max_shown = global.params.v.errorSupplementCount()) + const(uint) max_shown = global.diag.errorSupplementCount()) { - if (global.gag) + if (global.diag.gag) return; // Print full trace for verbose mode, otherwise only short traces @@ -3888,8 +3888,8 @@ extern (C++) class TemplateInstance : ScopeDsymbol // Set error here as we don't want it to depend on the number of // entries that are being printed. if (cl == Classification.error || - (cl == Classification.warning && global.params.useWarnings == DiagnosticReporting.error) || - (cl == Classification.deprecation && global.params.useDeprecated == DiagnosticReporting.error)) + (cl == Classification.warning && global.diag.useWarnings == DiagnosticReporting.error) || + (cl == Classification.deprecation && global.diag.useDeprecated == DiagnosticReporting.error)) cur.errors = true; // If two instantiations use the same declaration, they are recursive. @@ -4431,7 +4431,7 @@ extern (C++) class TemplateInstance : ScopeDsymbol return true; // Error already issued, just return `false` - if (!s.parent && global.errors) + if (!s.parent && global.diag.errors) return false; if (!s.parent && s.getType()) @@ -4534,7 +4534,7 @@ extern (C++) class TemplateInstance : ScopeDsymbol goto Ldsym; if (ta is null) { - assert(global.errors); + assert(global.diag.errors); ta = Type.terror; } @@ -4607,9 +4607,9 @@ extern (C++) class TemplateInstance : ScopeDsymbol { if (ea.checkValue()) // check void expression ea = ErrorExp.get(); - const olderrs = global.errors; + const olderrs = global.diag.errors; ea = ea.ctfeInterpret(); - if (global.errors != olderrs) + if (global.diag.errors != olderrs) ea = ErrorExp.get(); } } @@ -4819,7 +4819,7 @@ extern (C++) class TemplateInstance : ScopeDsymbol printf("TemplateInstance.findBestMatch()\n"); } - const errs = global.errors; + const errs = global.diag.errors; TemplateDeclaration td_last = null; Objects dedtypes; @@ -4949,14 +4949,14 @@ extern (C++) class TemplateInstance : ScopeDsymbol else if (errors && inst) { // instantiation was failed with error reporting - assert(global.errors); + assert(global.diag.errors); return false; } else { auto tdecl = tempdecl.isTemplateDeclaration(); - if (errs != global.errors) + if (errs != global.diag.errors) errorSupplemental(loc, "while looking for match for `%s`", toChars()); else if (tdecl && !tdecl.overnext) { @@ -5031,7 +5031,7 @@ extern (C++) class TemplateInstance : ScopeDsymbol { printf("\tIt's a match with template declaration '%s'\n", tempdecl.toChars()); } - return (errs == global.errors); + return (errs == global.diag.errors); } /***************************************** @@ -5328,7 +5328,7 @@ extern (C++) class TemplateInstance : ScopeDsymbol //printf("%d\n", nest); if (++nest > global.recursionLimit) { - global.gag = 0; // ensure error message gets printed + global.diag.gag = 0; // ensure error message gets printed .error(loc, "%s `%s` recursive expansion exceeded allowed nesting limit", kind, toPrettyChars); fatal(); } @@ -5345,7 +5345,7 @@ extern (C++) class TemplateInstance : ScopeDsymbol //printf("%d\n", nest); if (++nest > global.recursionLimit) { - global.gag = 0; // ensure error message gets printed + global.diag.gag = 0; // ensure error message gets printed .error(loc, "%s `%s` recursive expansion exceeded allowed nesting limit", kind, toPrettyChars); fatal(); } @@ -5856,10 +5856,10 @@ MATCH matchArg(TemplateParameter tp, Scope* sc, RootObject oarg, size_t i, Templ /* If a function is really property-like, and then * it's CTFEable, ei will be a literal expression. */ - const olderrors = global.startGagging(); + const olderrors = global.diag.startGagging(); ei = resolveProperties(sc, ei); ei = ei.ctfeInterpret(); - if (global.endGagging(olderrors) || ei.op == EXP.error) + if (global.diag.endGagging(olderrors) || ei.op == EXP.error) return matchArgNoMatch(); /* https://issues.dlang.org/show_bug.cgi?id=14520 diff --git a/compiler/src/dmd/dtoh.d b/compiler/src/dmd/dtoh.d index 296e13c63d51..b80a0ceaeb41 100644 --- a/compiler/src/dmd/dtoh.d +++ b/compiler/src/dmd/dtoh.d @@ -512,7 +512,7 @@ public: } } - if (global.params.useWarnings != DiagnosticReporting.off || canFix) + if (global.diag.useWarnings != DiagnosticReporting.off || canFix) { // Warn about identifiers that are keywords in C++. if (auto kc = keywordClass(ident)) diff --git a/compiler/src/dmd/enumsem.d b/compiler/src/dmd/enumsem.d index 99211e498548..7fd5fd1ecccf 100644 --- a/compiler/src/dmd/enumsem.d +++ b/compiler/src/dmd/enumsem.d @@ -589,10 +589,10 @@ void enumMemberSemantic(Scope* sc, EnumMember em) if (!em.ed.isAnonymous()) em.ed.memtype = t; } - const errors = global.startGagging(); + const errors = global.diag.startGagging(); Expression e = new IntegerExp(em.loc, 0, t); e = e.ctfeInterpret(); - if (global.endGagging(errors)) + if (global.diag.endGagging(errors)) { error(em.loc, "cannot generate 0 value of type `%s` for `%s`", t.toChars(), em.toChars()); @@ -630,7 +630,7 @@ void enumMemberSemantic(Scope* sc, EnumMember em) if (emprev.errors) return errorReturn(); - auto errors = global.startGagging(); + auto errors = global.diag.startGagging(); Expression eprev = emprev.value; assert(eprev); // .toHeadMutable() due to https://issues.dlang.org/show_bug.cgi?id=18645 @@ -650,7 +650,7 @@ void enumMemberSemantic(Scope* sc, EnumMember em) Expression e = new EqualExp(EXP.equal, em.loc, eprev, emax); e = e.expressionSemantic(sc); e = e.ctfeInterpret(); - if (global.endGagging(errors)) + if (global.diag.endGagging(errors)) { // display an introductory error before showing what actually failed error(em.loc, "cannot check `%s` value for overflow", em.toPrettyChars()); @@ -672,13 +672,13 @@ void enumMemberSemantic(Scope* sc, EnumMember em) emprev.ed.toChars(), emprev.toChars(), mt.toChars()); return errorReturn(); } - errors = global.startGagging(); + errors = global.diag.startGagging(); // Now set e to (eprev + 1) e = new AddExp(em.loc, eprev, IntegerExp.literal!1); e = e.expressionSemantic(sc); e = e.castTo(sc, eprev.type); e = e.ctfeInterpret(); - if (global.endGagging(errors)) + if (global.diag.endGagging(errors)) { error(em.loc, "cannot generate value for `%s`", em.toPrettyChars()); // rerun to show errors diff --git a/compiler/src/dmd/errors.d b/compiler/src/dmd/errors.d index a0a5137a3beb..74d11d367e6e 100644 --- a/compiler/src/dmd/errors.d +++ b/compiler/src/dmd/errors.d @@ -101,6 +101,93 @@ class ErrorSinkCompiler : ErrorSink } } +extern (C++) struct Diagnostics +{ + uint errors; /// number of errors reported so far + uint deprecations; /// number of deprecations reported so far + uint warnings; /// number of warnings reported so far + uint gag; /// !=0 means gag reporting of errors & warnings + uint gaggedErrors; /// number of errors reported while gagged + uint gaggedWarnings; /// number of warnings reported while gagged + + uint errorLimit = 20; + uint errorSupplementLimit = 6; // Limit the number of supplemental messages for each error (0 means unlimited) + + uint errorSupplementCount() + { + if (global.params.v.verbose) + return uint.max; + if (errorSupplementLimit == 0) + return uint.max; + return errorSupplementLimit; + } + MessageStyle messageStyle = MessageStyle.digitalmars; // style of file/line annotations on messages + bool showGaggedErrors; // print gagged errors anyway + bool printErrorContext; // print errors with the error context (the error line in the source file) + + DiagnosticReporting useDeprecated = DiagnosticReporting.inform; // how use of deprecated features are handled + DiagnosticReporting useWarnings = DiagnosticReporting.off; // how compiler warnings are handled +nothrow: + /** + * Start ignoring compile errors instead of reporting them. + * + * Used for speculative compilation like `__traits(compiles, XXX)`, but also internally + * to e.g. try out an `alias this` rewrite without comitting to it. + * + * Works like a stack, so N calls to `startGagging` should be paired with N + * calls to `endGagging`. + * + * Returns: the current number of gagged errors, which should later be passed to `endGagging` + */ + extern (C++) uint startGagging() @safe + { + ++gag; + gaggedWarnings = 0; + return gaggedErrors; + } + + /** + * Stop gagging, restoring the old gagged state before the most recent call to `startGagging`. + * + * Params: + * oldGagged = the previous number of errors, as returned by `startGagging` + * Returns: true if errors occurred while gagged. + */ + extern (C++) bool endGagging(uint oldGagged) @safe + { + bool anyErrs = (gaggedErrors != oldGagged); + --gag; + // Restore the original state of gagged errors; set total errors + // to be original errors + new ungagged errors. + errors -= (gaggedErrors - oldGagged); + gaggedErrors = oldGagged; + return anyErrs; + } + + /** + * Increment the error count to record that an error has occurred in the current context. + * + * An error message may or may not have been printed. + */ + extern (C++) void increaseErrorCount() @safe + { + if (gag) + ++gaggedErrors; + ++errors; + } + + /// Returns: `true` if errors have been diagnosed + extern(D) bool hasErrors() + { + return errors > 0; + } + + /// Returns: `true` if warnings have been diagnosed + extern(D) bool hasWarnings() + { + return warnings > 0; + } +} /** * Color highlighting to classify messages @@ -468,37 +555,37 @@ private extern(C++) void verrorReport(const SourceLoc loc, const(char)* format, final switch (info.kind) { case ErrorKind.error: - global.errors++; - if (!global.gag) + global.diag.errors++; + if (!global.diag.gag) { info.headerColor = Classification.error; verrorPrint(format, ap, info); - if (global.params.v.errorLimit && global.errors >= global.params.v.errorLimit) + if (global.diag.errorLimit && global.diag.errors >= global.diag.errorLimit) { - fprintf(stderr, "error limit (%d) reached, use `-verrors=0` to show all\n", global.params.v.errorLimit); + fprintf(stderr, "error limit (%d) reached, use `-verrors=0` to show all\n", global.diag.errorLimit); fatal(); // moderate blizzard of cascading messages } } else { - if (global.params.v.showGaggedErrors) + if (global.diag.showGaggedErrors) { info.headerColor = Classification.gagged; verrorPrint(format, ap, info); } - global.gaggedErrors++; + global.diag.gaggedErrors++; } return; case ErrorKind.deprecation: - if (global.params.useDeprecated == DiagnosticReporting.error) + if (global.diag.useDeprecated == DiagnosticReporting.error) goto case ErrorKind.error; - else if (global.params.useDeprecated == DiagnosticReporting.inform) + else if (global.diag.useDeprecated == DiagnosticReporting.inform) { - if (!global.gag) + if (!global.diag.gag) { - global.deprecations++; - if (global.params.v.errorLimit == 0 || global.deprecations <= global.params.v.errorLimit) + global.diag.deprecations++; + if (global.diag.errorLimit == 0 || global.diag.deprecations <= global.diag.errorLimit) { info.headerColor = Classification.deprecation; verrorPrint(format, ap, info); @@ -506,30 +593,30 @@ private extern(C++) void verrorReport(const SourceLoc loc, const(char)* format, } else { - global.gaggedWarnings++; + global.diag.gaggedWarnings++; } } return; case ErrorKind.warning: - if (global.params.useWarnings != DiagnosticReporting.off) + if (global.diag.useWarnings != DiagnosticReporting.off) { - if (!global.gag) + if (!global.diag.gag) { info.headerColor = Classification.warning; verrorPrint(format, ap, info); - if (global.params.useWarnings == DiagnosticReporting.error) - global.warnings++; + if (global.diag.useWarnings == DiagnosticReporting.error) + global.diag.warnings++; } else { - global.gaggedWarnings++; + global.diag.gaggedWarnings++; } } return; case ErrorKind.tip: - if (!global.gag) + if (!global.diag.gag) { info.headerColor = Classification.tip; verrorPrint(format, ap, info); @@ -575,9 +662,9 @@ private extern(C++) void verrorReportSupplemental(const SourceLoc loc, const(cha switch (info.kind) { case ErrorKind.error: - if (global.gag) + if (global.diag.gag) { - if (!global.params.v.showGaggedErrors) + if (!global.diag.showGaggedErrors) return; info.headerColor = Classification.gagged; } @@ -587,11 +674,11 @@ private extern(C++) void verrorReportSupplemental(const SourceLoc loc, const(cha return; case ErrorKind.deprecation: - if (global.params.useDeprecated == DiagnosticReporting.error) + if (global.diag.useDeprecated == DiagnosticReporting.error) goto case ErrorKind.error; - else if (global.params.useDeprecated == DiagnosticReporting.inform && !global.gag) + else if (global.diag.useDeprecated == DiagnosticReporting.inform && !global.diag.gag) { - if (global.params.v.errorLimit == 0 || global.deprecations <= global.params.v.errorLimit) + if (global.diag.errorLimit == 0 || global.diag.deprecations <= global.diag.errorLimit) { info.headerColor = Classification.deprecation; verrorPrint(format, ap, info); @@ -600,7 +687,7 @@ private extern(C++) void verrorReportSupplemental(const SourceLoc loc, const(cha return; case ErrorKind.warning: - if (global.params.useWarnings != DiagnosticReporting.off && !global.gag) + if (global.diag.useWarnings != DiagnosticReporting.off && !global.diag.gag) { info.headerColor = Classification.warning; verrorPrint(format, ap, info); @@ -647,8 +734,8 @@ private void verrorPrint(const(char)* format, va_list ap, ref ErrorInfo info) return; } - if (global.params.v.showGaggedErrors && global.gag) - fprintf(stderr, "(spec:%d) ", global.gag); + if (global.diag.showGaggedErrors && global.diag.gag) + fprintf(stderr, "(spec:%d) ", global.diag.gag); auto con = cast(Console) global.console; OutBuffer tmp; @@ -690,7 +777,7 @@ private void verrorPrint(const(char)* format, va_list ap, ref ErrorInfo info) __gshared SourceLoc old_loc; auto loc = info.loc; - if (global.params.v.printErrorContext && + if (global.diag.printErrorContext && // ignore supplemental messages with same loc (loc != old_loc || !info.supplemental) && // ignore invalid files diff --git a/compiler/src/dmd/expression.d b/compiler/src/dmd/expression.d index 3c79b02caa02..de98165d2741 100644 --- a/compiler/src/dmd/expression.d +++ b/compiler/src/dmd/expression.d @@ -522,7 +522,7 @@ extern (C++) abstract class Expression : ASTNode { error(loc, "expression `%s` is `void` and has no value", toChars()); //print(); assert(0); - if (!global.gag) + if (!global.diag.gag) type = Type.terror; return true; } @@ -1062,7 +1062,7 @@ extern (C++) final class ErrorExp : Expression if (errorexp is null) errorexp = new ErrorExp(); - if (global.errors == 0 && global.gaggedErrors == 0) + if (global.diag.errors == 0 && global.diag.gaggedErrors == 0) { /* Unfortunately, errors can still leak out of gagged errors, * and we need to set the error count to prevent bogus code diff --git a/compiler/src/dmd/expressionsem.d b/compiler/src/dmd/expressionsem.d index 36cca4a0fc71..98febd9c60b8 100644 --- a/compiler/src/dmd/expressionsem.d +++ b/compiler/src/dmd/expressionsem.d @@ -514,7 +514,7 @@ private Expression checkOpAssignTypes(BinExp binExp, Scope* sc) } if (type.isReal() || type.isImaginary()) { - assert(global.errors || t2.isFloating()); + assert(global.diag.errors || t2.isFloating()); e2 = e2.castTo(sc, t1); } } @@ -714,11 +714,11 @@ Expression resolveOpDollar(Scope* sc, ArrayExp ae, Expression* pe0) (*fargs)[0] = ie.lwr; (*fargs)[1] = ie.upr; - const xerrors = global.startGagging(); + const xerrors = global.diag.startGagging(); sc = sc.push(); FuncDeclaration fslice = resolveFuncCall(ae.loc, sc, slice, tiargs, ae.e1.type, ArgumentList(fargs), FuncResolveFlag.quiet); sc = sc.pop(); - global.endGagging(xerrors); + global.diag.endGagging(xerrors); if (!fslice) return fallback(); @@ -1214,9 +1214,9 @@ private Expression resolveUFCS(Scope* sc, CallExp ce) // check them for issues. Expressions* originalArguments = Expression.arraySyntaxCopy(ce.arguments); - const errors = global.startGagging(); + const errors = global.diag.startGagging(); e = ce.expressionSemantic(sc); - if (!global.endGagging(errors)) + if (!global.diag.endGagging(errors)) return e; if (arrayExpressionSemantic(originalArguments.peekSlice(), sc)) @@ -1248,10 +1248,10 @@ private Expression resolveUFCS(Scope* sc, CallExp ce) * s.remove("foo"); * } */ - const errors = global.startGagging(); + const errors = global.diag.startGagging(); e = searchUFCS(sc, die, ident); // if there were any errors and the identifier was remove - if (global.endGagging(errors)) + if (global.diag.endGagging(errors)) { if (ident == Id.remove) { @@ -2954,7 +2954,7 @@ private bool functionParameters(const ref Loc loc, Scope* sc, assert(arguments); assert(fd || tf.next); const size_t nparams = tf.parameterList.length; - const olderrors = global.errors; + const olderrors = global.diag.errors; bool err = false; Expression eprefix = null; *peprefix = null; @@ -3715,7 +3715,7 @@ private bool functionParameters(const ref Loc loc, Scope* sc, // wildmatch, tf.isWild(), fd.isReturnIsolated()); if (!tthis) { - assert(sc.intypeof || global.errors); + assert(sc.intypeof || global.diag.errors); tthis = fd.isThis().type.addMod(fd.type.mod); } if (tf.isWild() && !fd.isReturnIsolated()) @@ -3743,7 +3743,7 @@ private bool functionParameters(const ref Loc loc, Scope* sc, *prettype = tret; *peprefix = eprefix; - return (err || olderrors != global.errors); + return (err || olderrors != global.diag.errors); } /** @@ -4620,7 +4620,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor * in the enclosing function or template, since the initializer * will be part of the stuct declaration. */ - global.increaseErrorCount(); + global.diag.increaseErrorCount(); return setError(); } @@ -5757,15 +5757,15 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor return done(); } - const olderrors = global.errors; + const olderrors = global.diag.errors; exp.fd.dsymbolSemantic(sc); - if (olderrors == global.errors) + if (olderrors == global.diag.errors) { exp.fd.semantic2(sc); - if (olderrors == global.errors) + if (olderrors == global.diag.errors) exp.fd.semantic3(sc); } - if (olderrors != global.errors) + if (olderrors != global.diag.errors) { if (exp.fd.type && exp.fd.type.ty == Tfunction && !exp.fd.type.nextOf()) (cast(TypeFunction)exp.fd.type).next = Type.terror; @@ -6969,7 +6969,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor printf("DeclarationExp::semantic() %s\n", e.toChars()); } - const olderrors = global.errors; + const olderrors = global.diag.errors; /* This is here to support extern(linkage) declaration, * where the extern(linkage) winds up being an AttribDeclaration @@ -7115,10 +7115,10 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor sc2.pop(); s.parent = sc.parent; } - if (global.errors == olderrors) + if (global.diag.errors == olderrors) { e.declaration.semantic2(sc); - if (global.errors == olderrors) + if (global.diag.errors == olderrors) { e.declaration.semantic3(sc); } @@ -7283,9 +7283,9 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor if (e.tok2 == TOK.package_ || e.tok2 == TOK.module_) // These is() expressions are special because they can work on modules, not just types. { - const oldErrors = global.startGagging(); + const oldErrors = global.diag.startGagging(); Dsymbol sym = e.targ.toDsymbol(sc); - global.endGagging(oldErrors); + global.diag.endGagging(oldErrors); if (sym is null) return no(); @@ -7494,7 +7494,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor // current scope is itself deprecated, or deprecations are not errors const bool deprecationAllowed = sc.isDeprecated - || global.params.useDeprecated != DiagnosticReporting.error; + || global.diag.useDeprecated != DiagnosticReporting.error; const bool preventAliasThis = e.targ.hasDeprecatedAliasThis && !deprecationAllowed; if (preventAliasThis && e.targ.ty == Tstruct) @@ -7701,7 +7701,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor if (expressionsToString(buf, sc, exp.exps, exp.loc, null, true)) return null; - const errors = global.errors; + const errors = global.diag.errors; const len = buf.length; const str = buf.extractChars()[0 .. len]; const bool doUnittests = global.params.parsingUnittestsRequired(); @@ -7711,7 +7711,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor //printf("p.loc.linnum = %d\n", p.loc.linnum); Expression e = p.parseExpression(); - if (global.errors != errors) + if (global.diag.errors != errors) return null; if (p.token.value != TOK.endOfFile) @@ -8233,10 +8233,10 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor if (e && isDotOpDispatch(e)) { auto ode = e; - const errors = global.startGagging(); + const errors = global.diag.startGagging(); e = resolvePropertiesX(sc, e); // Any error or if 'e' is not resolved, go to UFCS - if (global.endGagging(errors) || e is ode) + if (global.diag.endGagging(errors) || e is ode) e = null; /* fall down to UFCS */ else { @@ -8386,7 +8386,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor else { exp.type = exp.var.type; - if (!exp.type && global.errors) // var is goofed up, just return error. + if (!exp.type && global.diag.errors) // var is goofed up, just return error. return setError(); assert(exp.type); @@ -10596,10 +10596,10 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor */ auto ode = e; exp.e2 = exp.e2.expressionSemantic(sc); - const errors = global.startGagging(); + const errors = global.diag.startGagging(); e = resolvePropertiesX(sc, e, exp.e2); // Any error or if 'e' is not resolved, go to UFCS - if (global.endGagging(errors) || e is ode) + if (global.diag.endGagging(errors) || e is ode) e = null; /* fall down to UFCS */ else return setResult(e); @@ -14278,9 +14278,9 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor Expression trySemantic(Expression exp, Scope* sc) { //printf("+trySemantic(%s)\n", exp.toChars()); - const errors = global.startGagging(); + const errors = global.diag.startGagging(); Expression e = expressionSemantic(exp, sc); - if (global.endGagging(errors)) + if (global.diag.endGagging(errors)) { e = null; } @@ -16859,7 +16859,7 @@ bool evalStaticCondition(Scope* sc, Expression original, Expression e, out bool } Expression before = e; - const uint nerrors = global.errors; + const uint nerrors = global.diag.errors; sc = sc.startCTFE(); sc.condition = true; @@ -16871,7 +16871,7 @@ bool evalStaticCondition(Scope* sc, Expression original, Expression e, out bool sc = sc.endCTFE(); e = e.optimize(WANTvalue); - if (nerrors != global.errors || + if (nerrors != global.diag.errors || e.isErrorExp() || e.type.toBasetype() == Type.terror) { @@ -17382,7 +17382,7 @@ private bool needsTypeInference(TemplateInstance ti, Scope* sc, int flag = 0) if (ti.semanticRun != PASS.initial) return false; - const olderrs = global.errors; + const olderrs = global.diag.errors; Objects dedtypes; size_t count = 0; @@ -17484,9 +17484,9 @@ private bool needsTypeInference(TemplateInstance ti, Scope* sc, int flag = 0) return true; } - if (olderrs != global.errors) + if (olderrs != global.diag.errors) { - if (!global.gag) + if (!global.diag.gag) { errorSupplemental(ti.loc, "while looking for match for `%s`", ti.toChars()); ti.semanticRun = PASS.semanticdone; diff --git a/compiler/src/dmd/frontend.d b/compiler/src/dmd/frontend.d index a181a6628916..9a58d1ea676a 100644 --- a/compiler/src/dmd/frontend.d +++ b/compiler/src/dmd/frontend.d @@ -25,28 +25,6 @@ import core.stdc.stdarg; version (Windows) private enum sep = ";", exe = ".exe"; version (Posix) private enum sep = ":", exe = ""; -/// Contains aggregated diagnostics information. -immutable struct Diagnostics -{ - /// Number of errors diagnosed - uint errors; - - /// Number of warnings diagnosed - uint warnings; - - /// Returns: `true` if errors have been diagnosed - bool hasErrors() - { - return errors > 0; - } - - /// Returns: `true` if warnings have been diagnosed - bool hasWarnings() - { - return warnings > 0; - } -} - /// Indicates the checking state of various contracts. enum ContractChecking : CHECKENABLE { @@ -410,12 +388,7 @@ Tuple!(Module, "module_", Diagnostics, "diagnostics") parseModule(AST = ASTCodeg m.importedFrom = m; m = m.parseModule!AST(); - Diagnostics diagnostics = { - errors: global.errors, - warnings: global.warnings - }; - - return typeof(return)(m, diagnostics); + return typeof(return)(m, global.diag); } /** diff --git a/compiler/src/dmd/frontend.h b/compiler/src/dmd/frontend.h index d947d4530aec..2d4533aba263 100644 --- a/compiler/src/dmd/frontend.h +++ b/compiler/src/dmd/frontend.h @@ -8051,6 +8051,58 @@ extern bool c_isxdigit(const int32_t c); extern bool c_isalnum(const int32_t c); +struct Diagnostics final +{ + uint32_t errors; + uint32_t deprecations; + uint32_t warnings; + uint32_t gag; + uint32_t gaggedErrors; + uint32_t gaggedWarnings; + uint32_t errorLimit; + uint32_t errorSupplementLimit; + uint32_t errorSupplementCount(); + MessageStyle messageStyle; + bool showGaggedErrors; + bool printErrorContext; + DiagnosticReporting useDeprecated; + DiagnosticReporting useWarnings; + uint32_t startGagging(); + bool endGagging(uint32_t oldGagged); + void increaseErrorCount(); + Diagnostics() : + errors(), + deprecations(), + warnings(), + gag(), + gaggedErrors(), + gaggedWarnings(), + errorLimit(20u), + errorSupplementLimit(6u), + messageStyle((MessageStyle)0u), + showGaggedErrors(), + printErrorContext(), + useDeprecated((DiagnosticReporting)1u), + useWarnings((DiagnosticReporting)2u) + { + } + Diagnostics(uint32_t errors, uint32_t deprecations = 0u, uint32_t warnings = 0u, uint32_t gag = 0u, uint32_t gaggedErrors = 0u, uint32_t gaggedWarnings = 0u, uint32_t errorLimit = 20u, uint32_t errorSupplementLimit = 6u, MessageStyle messageStyle = (MessageStyle)0u, bool showGaggedErrors = false, bool printErrorContext = false, DiagnosticReporting useDeprecated = (DiagnosticReporting)1u, DiagnosticReporting useWarnings = (DiagnosticReporting)2u) : + errors(errors), + deprecations(deprecations), + warnings(warnings), + gag(gag), + gaggedErrors(gaggedErrors), + gaggedWarnings(gaggedWarnings), + errorLimit(errorLimit), + errorSupplementLimit(errorSupplementLimit), + messageStyle(messageStyle), + showGaggedErrors(showGaggedErrors), + printErrorContext(printErrorContext), + useDeprecated(useDeprecated), + useWarnings(useWarnings) + {} +}; + extern void error(const Loc& loc, const char* format, ...); extern void error(const char* filename, uint32_t linnum, uint32_t charnum, const char* format, ...); @@ -8157,15 +8209,9 @@ struct Verbose final bool field; bool complex; bool vin; - bool showGaggedErrors; - bool printErrorContext; bool logo; bool color; bool cov; - MessageStyle messageStyle; - uint32_t errorLimit; - uint32_t errorSupplementLimit; - uint32_t errorSupplementCount(); Verbose() : verbose(), showColumns(), @@ -8176,17 +8222,12 @@ struct Verbose final field(), complex(true), vin(), - showGaggedErrors(), - printErrorContext(), logo(), color(), - cov(), - messageStyle((MessageStyle)0u), - errorLimit(20u), - errorSupplementLimit(6u) + cov() { } - Verbose(bool verbose, bool showColumns = false, bool tls = false, bool templates = false, bool templatesListInstances = false, bool gc = false, bool field = false, bool complex = true, bool vin = false, bool showGaggedErrors = false, bool printErrorContext = false, bool logo = false, bool color = false, bool cov = false, MessageStyle messageStyle = (MessageStyle)0u, uint32_t errorLimit = 20u, uint32_t errorSupplementLimit = 6u) : + Verbose(bool verbose, bool showColumns = false, bool tls = false, bool templates = false, bool templatesListInstances = false, bool gc = false, bool field = false, bool complex = true, bool vin = false, bool logo = false, bool color = false, bool cov = false) : verbose(verbose), showColumns(showColumns), tls(tls), @@ -8196,14 +8237,9 @@ struct Verbose final field(field), complex(complex), vin(vin), - showGaggedErrors(showGaggedErrors), - printErrorContext(printErrorContext), logo(logo), color(color), - cov(cov), - messageStyle(messageStyle), - errorLimit(errorLimit), - errorSupplementLimit(errorSupplementLimit) + cov(cov) {} }; @@ -8214,12 +8250,10 @@ struct Param final bool trace; bool tracegc; bool vcg_ast; - DiagnosticReporting useDeprecated; bool useUnitTests; bool useInline; bool release; bool preservePaths; - DiagnosticReporting useWarnings; bool cov; uint8_t covPercent; bool ctfe_cov; @@ -8301,12 +8335,10 @@ struct Param final trace(), tracegc(), vcg_ast(), - useDeprecated((DiagnosticReporting)1u), useUnitTests(), useInline(false), release(), preservePaths(), - useWarnings((DiagnosticReporting)2u), cov(), covPercent(), ctfe_cov(false), @@ -8376,18 +8408,16 @@ struct Param final timeTraceFile() { } - Param(bool obj, bool multiobj = false, bool trace = false, bool tracegc = false, bool vcg_ast = false, DiagnosticReporting useDeprecated = (DiagnosticReporting)1u, bool useUnitTests = false, bool useInline = false, bool release = false, bool preservePaths = false, DiagnosticReporting useWarnings = (DiagnosticReporting)2u, bool cov = false, uint8_t covPercent = 0u, bool ctfe_cov = false, bool ignoreUnsupportedPragmas = true, bool useModuleInfo = true, bool useTypeInfo = true, bool useExceptions = true, bool useGC = true, bool betterC = false, bool addMain = false, bool allInst = false, bool bitfields = false, CppStdRevision cplusplus = (CppStdRevision)201103u, Help help = Help(), Verbose v = Verbose(), FeatureState useDIP25 = (FeatureState)2u, FeatureState useDIP1000 = (FeatureState)0u, bool ehnogc = false, bool useDIP1021 = false, FeatureState fieldwise = (FeatureState)0u, bool fixAliasThis = false, FeatureState rvalueRefParam = (FeatureState)0u, FeatureState noSharedAccess = (FeatureState)0u, bool previewIn = false, bool inclusiveInContracts = false, bool shortenedMethods = true, bool fixImmutableConv = false, bool fix16997 = true, FeatureState dtorFields = (FeatureState)0u, FeatureState systemVariables = (FeatureState)0u, CHECKENABLE useInvariants = (CHECKENABLE)0u, CHECKENABLE useIn = (CHECKENABLE)0u, CHECKENABLE useOut = (CHECKENABLE)0u, CHECKENABLE useArrayBounds = (CHECKENABLE)0u, CHECKENABLE useAssert = (CHECKENABLE)0u, CHECKENABLE useSwitchError = (CHECKENABLE)0u, CHECKENABLE boundscheck = (CHECKENABLE)0u, CHECKACTION checkAction = (CHECKACTION)0u, CLIIdentifierTable dIdentifierTable = (CLIIdentifierTable)0u, CLIIdentifierTable cIdentifierTable = (CLIIdentifierTable)0u, _d_dynamicArray< const char > argv0 = {}, Array modFileAliasStrings = Array(), Array imppath = Array(), Array fileImppath = Array(), _d_dynamicArray< const char > objdir = {}, _d_dynamicArray< const char > objname = {}, _d_dynamicArray< const char > libname = {}, Output ddoc = Output(), Output dihdr = Output(), Output cxxhdr = Output(), Output json = Output(), JsonFieldFlags jsonFieldFlags = (JsonFieldFlags)0u, Output makeDeps = Output(), Output mixinOut = Output(), Output moduleDeps = Output(), uint32_t debuglevel = 0u, uint32_t versionlevel = 0u, bool run = false, Array runargs = Array(), Array cppswitches = Array(), const char* cpp = nullptr, Array objfiles = Array(), Array linkswitches = Array(), Array linkswitchIsForCC = Array(), Array libfiles = Array(), Array dllfiles = Array(), _d_dynamicArray< const char > deffile = {}, _d_dynamicArray< const char > resfile = {}, _d_dynamicArray< const char > exefile = {}, _d_dynamicArray< const char > mapfile = {}, bool fullyQualifiedObjectFiles = false, bool timeTrace = false, uint32_t timeTraceGranularityUs = 500u, const char* timeTraceFile = nullptr) : + Param(bool obj, bool multiobj = false, bool trace = false, bool tracegc = false, bool vcg_ast = false, bool useUnitTests = false, bool useInline = false, bool release = false, bool preservePaths = false, bool cov = false, uint8_t covPercent = 0u, bool ctfe_cov = false, bool ignoreUnsupportedPragmas = true, bool useModuleInfo = true, bool useTypeInfo = true, bool useExceptions = true, bool useGC = true, bool betterC = false, bool addMain = false, bool allInst = false, bool bitfields = false, CppStdRevision cplusplus = (CppStdRevision)201103u, Help help = Help(), Verbose v = Verbose(), FeatureState useDIP25 = (FeatureState)2u, FeatureState useDIP1000 = (FeatureState)0u, bool ehnogc = false, bool useDIP1021 = false, FeatureState fieldwise = (FeatureState)0u, bool fixAliasThis = false, FeatureState rvalueRefParam = (FeatureState)0u, FeatureState noSharedAccess = (FeatureState)0u, bool previewIn = false, bool inclusiveInContracts = false, bool shortenedMethods = true, bool fixImmutableConv = false, bool fix16997 = true, FeatureState dtorFields = (FeatureState)0u, FeatureState systemVariables = (FeatureState)0u, CHECKENABLE useInvariants = (CHECKENABLE)0u, CHECKENABLE useIn = (CHECKENABLE)0u, CHECKENABLE useOut = (CHECKENABLE)0u, CHECKENABLE useArrayBounds = (CHECKENABLE)0u, CHECKENABLE useAssert = (CHECKENABLE)0u, CHECKENABLE useSwitchError = (CHECKENABLE)0u, CHECKENABLE boundscheck = (CHECKENABLE)0u, CHECKACTION checkAction = (CHECKACTION)0u, CLIIdentifierTable dIdentifierTable = (CLIIdentifierTable)0u, CLIIdentifierTable cIdentifierTable = (CLIIdentifierTable)0u, _d_dynamicArray< const char > argv0 = {}, Array modFileAliasStrings = Array(), Array imppath = Array(), Array fileImppath = Array(), _d_dynamicArray< const char > objdir = {}, _d_dynamicArray< const char > objname = {}, _d_dynamicArray< const char > libname = {}, Output ddoc = Output(), Output dihdr = Output(), Output cxxhdr = Output(), Output json = Output(), JsonFieldFlags jsonFieldFlags = (JsonFieldFlags)0u, Output makeDeps = Output(), Output mixinOut = Output(), Output moduleDeps = Output(), uint32_t debuglevel = 0u, uint32_t versionlevel = 0u, bool run = false, Array runargs = Array(), Array cppswitches = Array(), const char* cpp = nullptr, Array objfiles = Array(), Array linkswitches = Array(), Array linkswitchIsForCC = Array(), Array libfiles = Array(), Array dllfiles = Array(), _d_dynamicArray< const char > deffile = {}, _d_dynamicArray< const char > resfile = {}, _d_dynamicArray< const char > exefile = {}, _d_dynamicArray< const char > mapfile = {}, bool fullyQualifiedObjectFiles = false, bool timeTrace = false, uint32_t timeTraceGranularityUs = 500u, const char* timeTraceFile = nullptr) : obj(obj), multiobj(multiobj), trace(trace), tracegc(tracegc), vcg_ast(vcg_ast), - useDeprecated(useDeprecated), useUnitTests(useUnitTests), useInline(useInline), release(release), preservePaths(preservePaths), - useWarnings(useWarnings), cov(cov), covPercent(covPercent), ctfe_cov(ctfe_cov), @@ -8475,12 +8505,6 @@ struct Global final char datetime[26LLU]; CompileEnv compileEnv; Param params; - uint32_t errors; - uint32_t deprecations; - uint32_t warnings; - uint32_t gag; - uint32_t gaggedErrors; - uint32_t gaggedWarnings; void* console; Array versionids; Array debugids; @@ -8489,12 +8513,10 @@ struct Global final FileManager* fileManager; enum : int32_t { recursionLimit = 500 }; + Diagnostics diag; ErrorSink* errorSink; ErrorSink* errorSinkNull; DArray(*preprocess)(FileName , const Loc& , OutBuffer& ); - uint32_t startGagging(); - bool endGagging(uint32_t oldGagged); - void increaseErrorCount(); void _init(); uint32_t versionNumber(); const char* const versionChars(); @@ -8506,24 +8528,19 @@ struct Global final filePath(), compileEnv(), params(), - errors(), - deprecations(), - warnings(), - gag(), - gaggedErrors(), - gaggedWarnings(), console(), versionids(), debugids(), hasMainFunction(), varSequenceNumber(1u), fileManager(), + diag(), errorSink(), errorSinkNull(), preprocess() { } - Global(_d_dynamicArray< const char > inifilename, _d_dynamicArray< const char > copyright = { 73, "Copyright (C) 1999-2024 by The D Language Foundation, All Rights Reserved" }, _d_dynamicArray< const char > written = { 24, "written by Walter Bright" }, Array path = Array(), Array filePath = Array(), CompileEnv compileEnv = CompileEnv(), Param params = Param(), uint32_t errors = 0u, uint32_t deprecations = 0u, uint32_t warnings = 0u, uint32_t gag = 0u, uint32_t gaggedErrors = 0u, uint32_t gaggedWarnings = 0u, void* console = nullptr, Array versionids = Array(), Array debugids = Array(), bool hasMainFunction = false, uint32_t varSequenceNumber = 1u, FileManager* fileManager = nullptr, ErrorSink* errorSink = nullptr, ErrorSink* errorSinkNull = nullptr, DArray(*preprocess)(FileName , const Loc& , OutBuffer& ) = nullptr) : + Global(_d_dynamicArray< const char > inifilename, _d_dynamicArray< const char > copyright = { 73, "Copyright (C) 1999-2024 by The D Language Foundation, All Rights Reserved" }, _d_dynamicArray< const char > written = { 24, "written by Walter Bright" }, Array path = Array(), Array filePath = Array(), CompileEnv compileEnv = CompileEnv(), Param params = Param(), void* console = nullptr, Array versionids = Array(), Array debugids = Array(), bool hasMainFunction = false, uint32_t varSequenceNumber = 1u, FileManager* fileManager = nullptr, Diagnostics diag = Diagnostics(), ErrorSink* errorSink = nullptr, ErrorSink* errorSinkNull = nullptr, DArray(*preprocess)(FileName , const Loc& , OutBuffer& ) = nullptr) : inifilename(inifilename), copyright(copyright), written(written), @@ -8531,18 +8548,13 @@ struct Global final filePath(filePath), compileEnv(compileEnv), params(params), - errors(errors), - deprecations(deprecations), - warnings(warnings), - gag(gag), - gaggedErrors(gaggedErrors), - gaggedWarnings(gaggedWarnings), console(console), versionids(versionids), debugids(debugids), hasMainFunction(hasMainFunction), varSequenceNumber(varSequenceNumber), fileManager(fileManager), + diag(diag), errorSink(errorSink), errorSinkNull(errorSinkNull), preprocess(preprocess) diff --git a/compiler/src/dmd/funcsem.d b/compiler/src/dmd/funcsem.d index c142a16f065d..0c7e4842a729 100644 --- a/compiler/src/dmd/funcsem.d +++ b/compiler/src/dmd/funcsem.d @@ -1167,15 +1167,15 @@ bool functionSemantic(FuncDeclaration fd) if (!fd.originalType) // semantic not yet run { TemplateInstance spec = fd.isSpeculative(); - const olderrs = global.errors; - const oldgag = global.gag; - if (global.gag && !spec) - global.gag = 0; + const olderrs = global.diag.errors; + const oldgag = global.diag.gag; + if (global.diag.gag && !spec) + global.diag.gag = 0; dsymbolSemantic(fd, fd._scope); - global.gag = oldgag; - if (spec && global.errors != olderrs) - spec.errors = (global.errors - olderrs != 0); - if (olderrs != global.errors) // if errors compiling this function + global.diag.gag = oldgag; + if (spec && global.diag.errors != olderrs) + spec.errors = (global.diag.errors - olderrs != 0); + if (olderrs != global.diag.errors) // if errors compiling this function return false; } @@ -1223,18 +1223,18 @@ bool functionSemantic3(FuncDeclaration fd) * we need to temporarily ungag errors. */ TemplateInstance spec = fd.isSpeculative(); - const olderrs = global.errors; - const oldgag = global.gag; - if (global.gag && !spec) - global.gag = 0; + const olderrs = global.diag.errors; + const oldgag = global.diag.gag; + if (global.diag.gag && !spec) + global.diag.gag = 0; semantic3(fd, fd._scope); - global.gag = oldgag; + global.diag.gag = oldgag; // If it is a speculatively-instantiated template, and errors occur, // we need to mark the template as having errors. - if (spec && global.errors != olderrs) - spec.errors = (global.errors - olderrs != 0); - if (olderrs != global.errors) // if errors compiling this function + if (spec && global.diag.errors != olderrs) + spec.errors = (global.diag.errors - olderrs != 0); + if (olderrs != global.diag.errors) // if errors compiling this function return false; } @@ -1627,7 +1627,7 @@ FuncDeclaration resolveFuncCall(const ref Loc loc, Scope* sc, Dsymbol s, } - if (!global.gag || global.params.v.showGaggedErrors) + if (!global.diag.gag || global.diag.showGaggedErrors) printCandidates(loc, td, sc.isDeprecated()); return null; } @@ -1644,7 +1644,7 @@ FuncDeclaration resolveFuncCall(const ref Loc loc, Scope* sc, Dsymbol s, { .error(loc, "none of the overloads of `%s` are callable using argument types `!(%s)%s`", od.ident.toChars(), tiargsBuf.peekChars(), fargsBuf.peekChars()); - if (!global.gag || global.params.v.showGaggedErrors) + if (!global.diag.gag || global.diag.showGaggedErrors) printCandidates(loc, od, sc.isDeprecated()); return null; } @@ -1679,7 +1679,7 @@ FuncDeclaration resolveFuncCall(const ref Loc loc, Scope* sc, Dsymbol s, .error(loc, "none of the overloads of `%s` are callable using a %sobject with argument types `(%s)`", fd.toChars(), thisBuf.peekChars(), buf.peekChars()); - if (!global.gag || global.params.v.showGaggedErrors) + if (!global.diag.gag || global.diag.showGaggedErrors) printCandidates(loc, fd, sc.isDeprecated()); return null; } @@ -1717,7 +1717,7 @@ FuncDeclaration resolveFuncCall(const ref Loc loc, Scope* sc, Dsymbol s, { .error(loc, "none of the overloads of `%s` are callable using argument types `%s`", fd.toChars(), fargsBuf.peekChars()); - if (!global.gag || global.params.v.showGaggedErrors) + if (!global.diag.gag || global.diag.showGaggedErrors) printCandidates(loc, fd, sc.isDeprecated()); return null; } @@ -1726,7 +1726,7 @@ FuncDeclaration resolveFuncCall(const ref Loc loc, Scope* sc, Dsymbol s, fd.kind(), fd.toPrettyChars(), parametersTypeToChars(tf.parameterList), tf.modToChars(), fargsBuf.peekChars()); - if (global.gag && !global.params.v.showGaggedErrors) + if (global.diag.gag && !global.diag.showGaggedErrors) return null; // re-resolve to check for supplemental message @@ -1773,7 +1773,7 @@ FuncDeclaration resolveFuncCall(const ref Loc loc, Scope* sc, Dsymbol s, private void printCandidates(Decl)(const ref Loc loc, Decl declaration, bool showDeprecated) { // max num of overloads to print (-v or -verror-supplements overrides this). - const uint DisplayLimit = global.params.v.errorSupplementCount(); + const uint DisplayLimit = global.diag.errorSupplementCount(); const(char)* constraintsTip; int printed = 0; // number of candidates printed diff --git a/compiler/src/dmd/globals.d b/compiler/src/dmd/globals.d index ccb63e330e9e..6c8d198bd374 100644 --- a/compiler/src/dmd/globals.d +++ b/compiler/src/dmd/globals.d @@ -125,23 +125,9 @@ extern(C++) struct Verbose bool field; // identify non-mutable field variables bool complex = true; // identify complex/imaginary type usage bool vin; // identify 'in' parameters - bool showGaggedErrors; // print gagged errors anyway - bool printErrorContext; // print errors with the error context (the error line in the source file) bool logo; // print compiler logo bool color; // use ANSI colors in console output bool cov; // generate code coverage data - MessageStyle messageStyle = MessageStyle.digitalmars; // style of file/line annotations on messages - uint errorLimit = 20; - uint errorSupplementLimit = 6; // Limit the number of supplemental messages for each error (0 means unlimited) - - uint errorSupplementCount() @safe - { - if (verbose) - return uint.max; - if (errorSupplementLimit == 0) - return uint.max; - return errorSupplementLimit; - } } /// Put command line switches in here @@ -152,12 +138,10 @@ extern (C++) struct Param bool trace; // insert profiling hooks bool tracegc; // instrument calls to 'new' bool vcg_ast; // write-out codegen-ast - DiagnosticReporting useDeprecated = DiagnosticReporting.inform; // how use of deprecated features are handled bool useUnitTests; // generate unittest code bool useInline = false; // inline expand functions bool release; // build release version bool preservePaths; // true means don't strip path from source file - DiagnosticReporting useWarnings = DiagnosticReporting.off; // how compiler warnings are handled bool cov; // generate code coverage data ubyte covPercent; // 0..100 code coverage percentage required bool ctfe_cov = false; // generate coverage data for ctfe @@ -290,12 +274,6 @@ extern (C++) struct Global CompileEnv compileEnv; Param params; /// command line parameters - uint errors; /// number of errors reported so far - uint deprecations; /// number of deprecations reported so far - uint warnings; /// number of warnings reported so far - uint gag; /// !=0 means gag reporting of errors & warnings - uint gaggedErrors; /// number of errors reported while gagged - uint gaggedWarnings; /// number of warnings reported while gagged void* console; /// opaque pointer to console for controlling text attributes @@ -310,6 +288,7 @@ extern (C++) struct Global enum recursionLimit = 500; /// number of recursive template expansions before abort + Diagnostics diag; ErrorSink errorSink; /// where the error messages go ErrorSink errorSinkNull; /// where the error messages are ignored @@ -317,54 +296,6 @@ extern (C++) struct Global nothrow: - /** - * Start ignoring compile errors instead of reporting them. - * - * Used for speculative compilation like `__traits(compiles, XXX)`, but also internally - * to e.g. try out an `alias this` rewrite without comitting to it. - * - * Works like a stack, so N calls to `startGagging` should be paired with N - * calls to `endGagging`. - * - * Returns: the current number of gagged errors, which should later be passed to `endGagging` - */ - extern (C++) uint startGagging() @safe - { - ++gag; - gaggedWarnings = 0; - return gaggedErrors; - } - - /** - * Stop gagging, restoring the old gagged state before the most recent call to `startGagging`. - * - * Params: - * oldGagged = the previous number of errors, as returned by `startGagging` - * Returns: true if errors occurred while gagged. - */ - extern (C++) bool endGagging(uint oldGagged) @safe - { - bool anyErrs = (gaggedErrors != oldGagged); - --gag; - // Restore the original state of gagged errors; set total errors - // to be original errors + new ungagged errors. - errors -= (gaggedErrors - oldGagged); - gaggedErrors = oldGagged; - return anyErrs; - } - - /** - * Increment the error count to record that an error has occurred in the current context. - * - * An error message may or may not have been printed. - */ - extern (C++) void increaseErrorCount() @safe - { - if (gag) - ++gaggedErrors; - ++errors; - } - extern (C++) void _init() { errorSink = new ErrorSinkCompiler; diff --git a/compiler/src/dmd/globals.h b/compiler/src/dmd/globals.h index 8a87bd6432a9..3a2c007a6ac2 100644 --- a/compiler/src/dmd/globals.h +++ b/compiler/src/dmd/globals.h @@ -24,12 +24,11 @@ class ErrorSink; class FileManager; struct Loc; -typedef unsigned char Diagnostic; -enum +enum class DiagnosticReporting : unsigned char { - DIAGNOSTICerror, // generate an error - DIAGNOSTICinform, // generate a warning - DIAGNOSTICoff // disable diagnostic + error, // generate an error + inform, // generate a warning + off // disable diagnostic }; enum class MessageStyle : unsigned char @@ -136,15 +135,45 @@ struct Verbose d_bool field; // identify non-mutable field variables d_bool complex = true; // identify complex/imaginary type usage d_bool vin; // identify 'in' parameters - d_bool showGaggedErrors; // print gagged errors anyway - d_bool printErrorContext; // print errors with the error context (the error line in the source file) d_bool logo; // print compiler logo d_bool color; // use ANSI colors in console output d_bool cov; // generate code coverage data - MessageStyle messageStyle; // style of file/line annotations on messages - unsigned errorLimit; - unsigned errorSupplementLimit; // Limit the number of supplemental messages for each error (0 means unlimited) +}; + +struct Diagnostics +{ + unsigned errors; + unsigned deprecations; + unsigned warnings; + unsigned gag; + unsigned gaggedErrors; + unsigned gaggedWarnings; + unsigned errorSupplementCount(); + unsigned errorLimit; + unsigned errorSupplementLimit; + + MessageStyle messageStyle = MessageStyle::digitalmars; // style of file/line annotations on messages + d_bool showGaggedErrors; // print gagged errors anyway + d_bool printErrorContext; // print errors with the error context (the error line in the source file) + + DiagnosticReporting useDeprecated; + DiagnosticReporting useWarnings; + + /* Start gagging. Return the current number of gagged errors + */ + unsigned startGagging(); + + /* End gagging, restoring the old gagged state. + * Return true if errors occurred while gagged. + */ + bool endGagging(unsigned oldGagged); + + /* Increment the error count to record that an error + * has occurred in the current context. An error message + * may or may not have been printed. + */ + void increaseErrorCount(); }; // Put command line switches in here @@ -155,12 +184,10 @@ struct Param d_bool trace; // insert profiling hooks d_bool tracegc; // instrument calls to 'new' d_bool vcg_ast; // write-out codegen-ast - Diagnostic useDeprecated; d_bool useUnitTests; // generate unittest code d_bool useInline; // inline expand functions d_bool release; // build release version d_bool preservePaths; // true means don't strip path from source file - Diagnostic useWarnings; d_bool cov; // generate code coverage data unsigned char covPercent; // 0..100 code coverage percentage required d_bool ctfe_cov; // generate coverage data for ctfe @@ -311,12 +338,6 @@ struct Global CompileEnv compileEnv; Param params; - unsigned errors; // number of errors reported so far - unsigned deprecations; // number of deprecations reported so far - unsigned warnings; // number of warnings reported so far - unsigned gag; // !=0 means gag reporting of errors & warnings - unsigned gaggedErrors; // number of errors reported while gagged - unsigned gaggedWarnings; // number of warnings reported while gagged void* console; // opaque pointer to console for controlling text attributes @@ -327,26 +348,12 @@ struct Global unsigned varSequenceNumber; FileManager* fileManager; + Diagnostics diag; ErrorSink* errorSink; // where the error messages go ErrorSink* errorSinkNull; // where the error messages disappear DArray (*preprocess)(FileName, const Loc&, OutBuffer&); - /* Start gagging. Return the current number of gagged errors - */ - unsigned startGagging(); - - /* End gagging, restoring the old gagged state. - * Return true if errors occurred while gagged. - */ - bool endGagging(unsigned oldGagged); - - /* Increment the error count to record that an error - * has occurred in the current context. An error message - * may or may not have been printed. - */ - void increaseErrorCount(); - void _init(); /** diff --git a/compiler/src/dmd/glue.d b/compiler/src/dmd/glue.d index 83dcce418a36..f0f7c9806b0f 100644 --- a/compiler/src/dmd/glue.d +++ b/compiler/src/dmd/glue.d @@ -336,7 +336,7 @@ void generateCodeAndWrite(Module[] modules, const(char)*[] libmodules, eSink.message(Loc.initial, "code %s", m.toChars()); genObjFile(m, false); } - if (!global.errors && firstm) + if (!global.diag.errors && firstm) { obj_end(objbuf, library, firstm.objfile.toString()); } @@ -354,11 +354,11 @@ void generateCodeAndWrite(Module[] modules, const(char)*[] libmodules, genObjFile(m, multiobj); obj_end(objbuf, library, m.objfile.toString()); obj_write_deferred(objbuf, library, glue.obj_symbols_towrite); - if (global.errors && !writeLibrary) + if (global.diag.errors && !writeLibrary) m.deleteObjFile(); } } - if (writeLibrary && !global.errors) + if (writeLibrary && !global.diag.errors) { if (verbose) eSink.message(Loc.initial, "library %.*s", library.filename.fTuple.expand); @@ -443,7 +443,7 @@ void FuncDeclaration_toObjFile(FuncDeclaration fd, bool multiobj) if (fd.hasSemantic3Errors) return; - if (global.errors) + if (global.diag.errors) return; if (!fd.fbody) @@ -880,7 +880,7 @@ void FuncDeclaration_toObjFile(FuncDeclaration fd, bool multiobj) Statement_toIR(sbody, irs); - if (global.errors) + if (global.diag.errors) { // Restore symbol table cstate.CSpsymtab = symtabsave; @@ -958,7 +958,7 @@ void FuncDeclaration_toObjFile(FuncDeclaration fd, bool multiobj) glue.stests.push(s); } - if (global.errors) + if (global.diag.errors) { // Restore symbol table cstate.CSpsymtab = symtabsave; diff --git a/compiler/src/dmd/iasmdmd.d b/compiler/src/dmd/iasmdmd.d index 30fe573ded1b..d11f6e87ee93 100644 --- a/compiler/src/dmd/iasmdmd.d +++ b/compiler/src/dmd/iasmdmd.d @@ -95,7 +95,7 @@ public Statement inlineAsmSemantic(InlineAsmStatement s, Scope *sc) asmstate.ucItype = 0; asmstate.bReturnax = false; asmstate.lbracketNestCount = 0; - asmstate.startErrors = global.errors; + asmstate.startErrors = global.diag.errors; asmstate.statement = s; asmstate.sc = sc; @@ -320,7 +320,7 @@ struct ASM_STATE ucItype_t ucItype; /// Instruction type Loc loc; bool bInit; - uint startErrors; // global.errors at start of iasm + uint startErrors; // global.diag.errors at start of iasm LabelDsymbol psDollar; Dsymbol psLocalsize; bool bReturnax; @@ -329,7 +329,7 @@ struct ASM_STATE Token* tok; TOK tokValue; int lbracketNestCount; - bool errors() { return global.errors > startErrors; } + bool errors() { return global.diag.errors > startErrors; } } __gshared ASM_STATE asmstate; diff --git a/compiler/src/dmd/iasmgcc.d b/compiler/src/dmd/iasmgcc.d index 1410e0a22991..e662f2f64587 100644 --- a/compiler/src/dmd/iasmgcc.d +++ b/compiler/src/dmd/iasmgcc.d @@ -58,9 +58,9 @@ public Statement gccAsmSemantic(GccAsmStatement s, Scope *sc) p.scanloc = s.loc; // Parse the gcc asm statement. - const errors = global.errors; + const errors = global.diag.errors; s = p.parseGccAsm(s); - if (errors != global.errors) + if (errors != global.diag.errors) return null; s.stc = sc.stc; @@ -410,8 +410,8 @@ unittest if (!global.errorSink) global.errorSink = new ErrorSinkCompiler; - const errors = global.startGagging(); - scope(exit) global.endGagging(errors); + const errors = global.diag.startGagging(); + scope(exit) global.diag.endGagging(errors); // If this check fails, then Type._init() was called before reaching here, // and the entire chunk of code that follows can be removed. @@ -430,13 +430,13 @@ unittest // Imitates asmSemantic if version = IN_GCC. static int semanticAsm(Token* tokens) { - const errors = global.errors; + const errors = global.diag.errors; scope gas = new GccAsmStatement(Loc.initial, tokens); const bool doUnittests = false; scope p = new Parser!ASTCodegen(null, ";", false, global.errorSink, &global.compileEnv, doUnittests); p.token = *tokens; p.parseGccAsm(gas); - return global.errors - errors; + return global.diag.errors - errors; } // Imitates parseStatement for asm statements. diff --git a/compiler/src/dmd/initsem.d b/compiler/src/dmd/initsem.d index 505a3e13636f..7eed8edf36e5 100644 --- a/compiler/src/dmd/initsem.d +++ b/compiler/src/dmd/initsem.d @@ -350,7 +350,7 @@ Initializer initializerSemantic(Initializer init, Scope* sc, ref Type tx, NeedIn sc = sc.endCTFE(); if (i.exp.op == EXP.error) return err(); - const olderrors = global.errors; + const olderrors = global.diag.errors; /* ImportC: convert arrays to pointers, functions to pointers to functions */ @@ -372,7 +372,7 @@ Initializer initializerSemantic(Initializer init, Scope* sc, ref Type tx, NeedIn { i.exp = i.exp.implicitCastTo(sc, t); } - if (!global.gag && olderrors != global.errors) + if (!global.diag.gag && olderrors != global.diag.errors) { return i; } @@ -401,7 +401,7 @@ Initializer initializerSemantic(Initializer init, Scope* sc, ref Type tx, NeedIn i.exp = i.exp.optimize(WANTvalue); } - if (!global.gag && olderrors != global.errors) + if (!global.diag.gag && olderrors != global.diag.errors) { return i; // Failed, suppress duplicate error messages } @@ -582,9 +582,9 @@ Initializer initializerSemantic(Initializer init, Scope* sc, ref Type tx, NeedIn } } Type et = i.exp.type; - const errors = global.startGagging(); + const errors = global.diag.startGagging(); i.exp = i.exp.implicitCastTo(sc, t); - if (global.endGagging(errors)) + if (global.diag.endGagging(errors)) error(currExp.loc, "cannot implicitly convert expression `%s` of type `%s` to `%s`", currExp.toChars(), et.toChars(), t.toChars()); } } diff --git a/compiler/src/dmd/inline.d b/compiler/src/dmd/inline.d index ab175d79cf74..eea53d7338ed 100644 --- a/compiler/src/dmd/inline.d +++ b/compiler/src/dmd/inline.d @@ -1738,7 +1738,7 @@ private bool canInline(FuncDeclaration fd, bool hasthis, bool hdrscan, bool stat if (!functionSemantic3(fd)) return false; Module.runDeferredSemantic3(); - if (global.errors) + if (global.diag.errors) return false; assert(fd.semanticRun >= PASS.semantic3done); } @@ -1923,7 +1923,7 @@ private bool canInline(FuncDeclaration fd, bool hasthis, bool hdrscan, bool stat return true; Lno: - if (fd.inlining == PINLINE.always && global.params.useWarnings == DiagnosticReporting.inform) + if (fd.inlining == PINLINE.always && global.diag.useWarnings == DiagnosticReporting.inform) warning(fd.loc, "cannot inline function `%s`", fd.toPrettyChars()); if (!hdrscan) // Don't modify inlineStatus for header content scan diff --git a/compiler/src/dmd/main.d b/compiler/src/dmd/main.d index 5f6e75627a98..6d4ffcb18b8d 100644 --- a/compiler/src/dmd/main.d +++ b/compiler/src/dmd/main.d @@ -241,7 +241,7 @@ private int tryMain(size_t argc, const(char)** argv, ref Param params) static int printHelpUsage(string help) { printf("%.*s", cast(int)help.length, &help[0]); - return global.errors ? EXIT_FAILURE : EXIT_SUCCESS; + return global.diag.errors ? EXIT_FAILURE : EXIT_SUCCESS; } /* @@ -256,10 +256,10 @@ private int tryMain(size_t argc, const(char)** argv, ref Param params) // In case deprecation messages were omitted, inform the user about it static void mentionOmittedDeprecations() { - if (global.params.v.errorLimit != 0 && - global.deprecations > global.params.v.errorLimit) + if (global.diag.errorLimit != 0 && + global.diag.deprecations > global.diag.errorLimit) { - const omitted = global.deprecations - global.params.v.errorLimit; + const omitted = global.diag.deprecations - global.diag.errorLimit; message(Loc.initial, "%d deprecation warning%s omitted, use `-verrors=0` to show all", omitted, omitted == 1 ? "".ptr : "s".ptr); } @@ -329,9 +329,9 @@ private int tryMain(size_t argc, const(char)** argv, ref Param params) global.console = cast(void*) createConsole(core.stdc.stdio.stderr); target.setCPU(); - Loc.set(params.v.showColumns, params.v.messageStyle); + Loc.set(params.v.showColumns, global.diag.messageStyle); - if (global.errors) + if (global.diag.errors) { fatal(); } @@ -514,7 +514,7 @@ private int tryMain(size_t argc, const(char)** argv, ref Param params) error(Loc.initial, "conflicting Ddoc and obj generation options"); fatal(); } - if (global.errors) + if (global.diag.errors) fatal(); if (params.dihdr.doOutput) @@ -538,7 +538,7 @@ private int tryMain(size_t argc, const(char)** argv, ref Param params) fatal(); } } - if (global.errors) + if (global.diag.errors) removeHdrFilesAndFail(params, modules); { @@ -552,7 +552,7 @@ private int tryMain(size_t argc, const(char)** argv, ref Param params) message("importall %s", m.toChars()); m.importAll(null); } - if (global.errors) + if (global.diag.errors) removeHdrFilesAndFail(params, modules); backend_init(params, driverParams, target); @@ -564,7 +564,7 @@ private int tryMain(size_t argc, const(char)** argv, ref Param params) message("semantic %s", m.toChars()); m.dsymbolSemantic(null); } - //if (global.errors) + //if (global.diag.errors) // fatal(); Module.runDeferredSemantic(); if (Module.deferred.length) @@ -585,7 +585,7 @@ private int tryMain(size_t argc, const(char)** argv, ref Param params) m.semantic2(null); } Module.runDeferredSemantic2(); - if (global.errors) + if (global.diag.errors) removeHdrFilesAndFail(params, modules); // Do pass 3 semantic analysis @@ -610,7 +610,7 @@ private int tryMain(size_t argc, const(char)** argv, ref Param params) } } Module.runDeferredSemantic3(); - if (global.errors) + if (global.diag.errors) removeHdrFilesAndFail(params, modules); // Scan for functions to inline @@ -624,14 +624,14 @@ private int tryMain(size_t argc, const(char)** argv, ref Param params) } } - if (global.warnings) + if (global.diag.warnings) errorOnWarning(); - if (global.params.useDeprecated == DiagnosticReporting.inform) + if (global.diag.useDeprecated == DiagnosticReporting.inform) mentionOmittedDeprecations(); // Do not attempt to generate output files if errors or warnings occurred - if (global.errors || global.warnings) + if (global.diag.errors || global.diag.warnings) removeHdrFilesAndFail(params, modules); // inlineScan incrementally run semantic3 of each expanded functions. @@ -662,7 +662,7 @@ private int tryMain(size_t argc, const(char)** argv, ref Param params) if (generateJson(modules, global.errorSink)) fatal(); } - if (!global.errors && params.ddoc.doOutput) + if (!global.diag.errors && params.ddoc.doOutput) { foreach (m; modules) { @@ -694,7 +694,7 @@ private int tryMain(size_t argc, const(char)** argv, ref Param params) if (global.params.cxxhdr.doOutput) genCppHdrFiles(modules); - if (global.errors) + if (global.diag.errors) fatal(); if (driverParams.lib && params.objfiles.length == 0) @@ -721,7 +721,7 @@ private int tryMain(size_t argc, const(char)** argv, ref Param params) backend_term(); - if (global.errors) + if (global.diag.errors) fatal(); int status = EXIT_SUCCESS; if (!params.objfiles.length) @@ -810,10 +810,10 @@ private int tryMain(size_t argc, const(char)** argv, ref Param params) printf("%.*s", cast(int) data.length, data.ptr); } - if (global.warnings) + if (global.diag.warnings) errorOnWarning(); - if (global.errors || global.warnings) + if (global.diag.errors || global.diag.warnings) removeHdrFilesAndFail(params, modules); return status; diff --git a/compiler/src/dmd/mangle/package.d b/compiler/src/dmd/mangle/package.d index d184fe9f42c2..5c124c133f4f 100644 --- a/compiler/src/dmd/mangle/package.d +++ b/compiler/src/dmd/mangle/package.d @@ -830,9 +830,9 @@ public: continue; } // Now that we know it is not an alias, we MUST obtain a value - const olderr = global.errors; + const olderr = global.diag.errors; ea = ea.ctfeInterpret(); - if (ea.op == EXP.error || olderr != global.errors) + if (ea.op == EXP.error || olderr != global.diag.errors) continue; /* Use type mangling that matches what it would be for a function parameter diff --git a/compiler/src/dmd/mars.d b/compiler/src/dmd/mars.d index a3c95d63fafc..b07cf2aacf7d 100644 --- a/compiler/src/dmd/mars.d +++ b/compiler/src/dmd/mars.d @@ -646,11 +646,11 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, ref Param } } else if (arg == "-de") // https://dlang.org/dmd.html#switch-de - params.useDeprecated = DiagnosticReporting.error; + global.diag.useDeprecated = DiagnosticReporting.error; else if (arg == "-d") // https://dlang.org/dmd.html#switch-d - params.useDeprecated = DiagnosticReporting.off; + global.diag.useDeprecated = DiagnosticReporting.off; else if (arg == "-dw") // https://dlang.org/dmd.html#switch-dw - params.useDeprecated = DiagnosticReporting.inform; + global.diag.useDeprecated = DiagnosticReporting.inform; else if (arg == "-c") // https://dlang.org/dmd.html#switch-c driverParams.link = false; else if (startsWith(p + 1, "checkaction")) // https://dlang.org/dmd.html#switch-checkaction @@ -1002,13 +1002,13 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, ref Param } if (startsWith(p + 9, "spec")) { - params.v.showGaggedErrors = true; + global.diag.showGaggedErrors = true; } else if (startsWith(p + 9, "context")) { - params.v.printErrorContext = true; + global.diag.printErrorContext = true; } - else if (!params.v.errorLimit.parseDigits(p.toDString()[9 .. $])) + else if (!global.diag.errorLimit.parseDigits(p.toDString()[9 .. $])) { errorInvalidSwitch(p, "Only number, `spec`, or `context` are allowed for `-verrors`"); return true; @@ -1016,7 +1016,7 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, ref Param } else if (startsWith(p + 1, "verror-supplements")) { - if (!params.v.errorSupplementLimit.parseDigits(p.toDString()[20 .. $])) + if (!global.diag.errorSupplementLimit.parseDigits(p.toDString()[20 .. $])) { errorInvalidSwitch(p, "Only a number is allowed for `-verror-supplements`"); return true; @@ -1029,10 +1029,10 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, ref Param switch (style) { case "digitalmars": - params.v.messageStyle = MessageStyle.digitalmars; + global.diag.messageStyle = MessageStyle.digitalmars; break; case "gnu": - params.v.messageStyle = MessageStyle.gnu; + global.diag.messageStyle = MessageStyle.gnu; break; default: error("unknown error style '%.*s', must be 'digitalmars' or 'gnu'", cast(int) style.length, style.ptr); @@ -1242,9 +1242,9 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, ref Param } } else if (arg == "-w") // https://dlang.org/dmd.html#switch-w - params.useWarnings = DiagnosticReporting.error; + global.diag.useWarnings = DiagnosticReporting.error; else if (arg == "-wi") // https://dlang.org/dmd.html#switch-wi - params.useWarnings = DiagnosticReporting.inform; + global.diag.useWarnings = DiagnosticReporting.inform; else if (arg == "-wo") // https://dlang.org/dmd.html#switch-wo { // Obsolete features has been obsoleted until a DIP for "editions" diff --git a/compiler/src/dmd/mtype.d b/compiler/src/dmd/mtype.d index be70b02dec90..d66c888f8421 100644 --- a/compiler/src/dmd/mtype.d +++ b/compiler/src/dmd/mtype.d @@ -2604,7 +2604,7 @@ extern (C++) final class TypeFunction : TypeNext extern(D) static const(char)* getMatchError(A...)(const(char)* format, A args) { - if (global.gag && !global.params.v.showGaggedErrors) + if (global.diag.gag && !global.diag.showGaggedErrors) return null; OutBuffer buf; buf.printf(format, args); diff --git a/compiler/src/dmd/pragmasem.d b/compiler/src/dmd/pragmasem.d index 405b7654ffa6..87415b19e085 100644 --- a/compiler/src/dmd/pragmasem.d +++ b/compiler/src/dmd/pragmasem.d @@ -335,7 +335,7 @@ void pragmaDeclSemantic(PragmaDeclaration pd, Scope* sc) buf.writestring(pd.ident.toString()); if (pd.args) { - const errors_save = global.startGagging(); + const errors_save = global.diag.startGagging(); for (size_t i = 0; i < pd.args.length; i++) { Expression e = (*pd.args)[i]; @@ -352,7 +352,7 @@ void pragmaDeclSemantic(PragmaDeclaration pd, Scope* sc) } if (pd.args.length) buf.writeByte(')'); - global.endGagging(errors_save); + global.diag.endGagging(errors_save); } message("pragma %s", buf.peekChars()); return declarations(); diff --git a/compiler/src/dmd/safe.d b/compiler/src/dmd/safe.d index 24d874585516..cf3c7cd76bcf 100644 --- a/compiler/src/dmd/safe.d +++ b/compiler/src/dmd/safe.d @@ -433,7 +433,7 @@ bool setUnsafe(Scope* sc, { if (sc.func.isSafeBypassingInference()) { - // Message wil be gagged, but still call error() to update global.errors and for + // Message wil be gagged, but still call error() to update global.diag.errors and for // -verrors=spec .error(loc, fmt, arg0 ? arg0.toChars() : "", arg1 ? arg1.toChars() : "", arg2 ? arg2.toChars() : ""); return true; diff --git a/compiler/src/dmd/semantic2.d b/compiler/src/dmd/semantic2.d index 31fc418dbcc3..1acc3918036c 100644 --- a/compiler/src/dmd/semantic2.d +++ b/compiler/src/dmd/semantic2.d @@ -146,9 +146,9 @@ private extern(C++) final class Semantic2Visitor : Visitor sc.tinst = tempinst; sc.minst = tempinst.minst; - const needGagging = (tempinst.gagged && !global.gag); - const olderrors = global.errors; - const oldGaggedErrors = needGagging ? global.startGagging() : -1; + const needGagging = (tempinst.gagged && !global.diag.gag); + const olderrors = global.diag.errors; + const oldGaggedErrors = needGagging ? global.diag.startGagging() : -1; for (size_t i = 0; i < tempinst.members.length; i++) { @@ -158,11 +158,11 @@ private extern(C++) final class Semantic2Visitor : Visitor printf("\tmember '%s', kind = '%s'\n", s.toChars(), s.kind()); } s.semantic2(sc); - if (tempinst.gagged && global.errors != olderrors) + if (tempinst.gagged && global.diag.errors != olderrors) break; } - if (global.errors != olderrors) + if (global.diag.errors != olderrors) { if (!tempinst.errors) { @@ -174,7 +174,7 @@ private extern(C++) final class Semantic2Visitor : Visitor tempinst.errors = true; } if (needGagging) - global.endGagging(oldGaggedErrors); + global.diag.endGagging(oldGaggedErrors); sc = sc.pop(); sc.pop(); @@ -730,7 +730,7 @@ private void doGNUABITagSemantic(ref Expression e, ref Expression* lastTag) auto sle = e.isStructLiteralExp(); if (sle is null) { - assert(global.errors); + assert(global.diag.errors); return; } // The definition of `gnuAttributes` only have 1 member, `string[] tags` @@ -884,7 +884,7 @@ void staticAssertFail(StaticAssert sa, Scope* sc) if (e.op == EXP.error) { errorSupplemental(sa.loc, "while evaluating `static assert` argument `%s`", (*sa.msgs)[i].toChars()); - if (!global.gag) + if (!global.diag.gag) fatal(); return; } @@ -906,6 +906,6 @@ void staticAssertFail(StaticAssert sa, Scope* sc) error(sa.loc, "static assert: `%s` is false", sa.exp.toChars()); if (sc.tinst) sc.tinst.printInstantiationTrace(); - if (!global.gag) + if (!global.diag.gag) fatal(); } diff --git a/compiler/src/dmd/semantic3.d b/compiler/src/dmd/semantic3.d index a90cf4424010..cb64aecfbb3c 100644 --- a/compiler/src/dmd/semantic3.d +++ b/compiler/src/dmd/semantic3.d @@ -119,9 +119,9 @@ private extern(C++) final class Semantic3Visitor : Visitor sc.tinst = tempinst; sc.minst = tempinst.minst; - bool needGagging = tempinst.gagged && !global.gag; - const olderrors = global.errors; - const oldGaggedErrors = needGagging ? global.startGagging() : -1; + bool needGagging = tempinst.gagged && !global.diag.gag; + const olderrors = global.diag.errors; + const oldGaggedErrors = needGagging ? global.diag.startGagging() : -1; /* If this is a gagged instantiation, gag errors. * Future optimisation: If the results are actually needed, errors * would already be gagged, so we don't really need to run semantic @@ -132,11 +132,11 @@ private extern(C++) final class Semantic3Visitor : Visitor { Dsymbol s = (*tempinst.members)[i]; s.semantic3(sc); - if (tempinst.gagged && global.errors != olderrors) + if (tempinst.gagged && global.diag.errors != olderrors) break; } - if (global.errors != olderrors) + if (global.diag.errors != olderrors) { if (!tempinst.errors) { @@ -148,7 +148,7 @@ private extern(C++) final class Semantic3Visitor : Visitor tempinst.errors = true; } if (needGagging) - global.endGagging(oldGaggedErrors); + global.diag.endGagging(oldGaggedErrors); sc = sc.pop(); sc.pop(); @@ -169,7 +169,7 @@ private extern(C++) final class Semantic3Visitor : Visitor sc = sc.push(tmix.argsym); sc = sc.push(tmix); - const olderrors = global.errors; + const olderrors = global.diag.errors; for (size_t i = 0; i < tmix.members.length; i++) { @@ -177,7 +177,7 @@ private extern(C++) final class Semantic3Visitor : Visitor s.semantic3(sc); } - if (global.errors != olderrors) + if (global.diag.errors != olderrors) errorSupplemental(tmix.loc, "parent scope from here: `mixin %s`", tmix.toChars()); sc = sc.pop(); @@ -242,7 +242,7 @@ private extern(C++) final class Semantic3Visitor : Visitor if (!funcdecl.parent) { - if (global.errors) + if (global.diag.errors) return; //printf("FuncDeclaration::semantic3(%s '%s', sc = %p)\n", kind(), toChars(), sc); assert(0); @@ -278,11 +278,11 @@ private extern(C++) final class Semantic3Visitor : Visitor * For generated opAssign function, any errors * from its body need to be gagged. */ - const oldErrors = global.startGagging(); + const oldErrors = global.diag.startGagging(); ++funcdecl.inuse; funcdecl.semantic3(sc); --funcdecl.inuse; - if (global.endGagging(oldErrors)) // if errors happened + if (global.diag.endGagging(oldErrors)) // if errors happened { // Disable generated opAssign, because some members forbid identity assignment. funcdecl.storage_class |= STC.disable; @@ -311,7 +311,7 @@ private extern(C++) final class Semantic3Visitor : Visitor return; } - const oldErrors = global.errors; + const oldErrors = global.diag.errors; auto fds = FuncDeclSem3(funcdecl,sc); fds.checkInContractOverrides(); @@ -1404,7 +1404,7 @@ private extern(C++) final class Semantic3Visitor : Visitor * Otherwise, error gagging should be temporarily ungagged by functionSemantic3. */ funcdecl.semanticRun = PASS.semantic3done; - if ((global.errors != oldErrors) || (funcdecl.fbody && funcdecl.fbody.isErrorStatement())) + if ((global.diag.errors != oldErrors) || (funcdecl.fbody && funcdecl.fbody.isErrorStatement())) funcdecl.hasSemantic3Errors = true; else funcdecl.hasSemantic3Errors = false; @@ -1569,7 +1569,7 @@ private extern(C++) final class Semantic3Visitor : Visitor // Instantiate RTInfo!S to provide a pointer bitmap for the GC // Don't do it in -betterC or on unused deprecated / error types if (!ad.getRTInfo && global.params.useTypeInfo && Type.rtinfo && - (!ad.isDeprecated() || global.params.useDeprecated != DiagnosticReporting.error) && + (!ad.isDeprecated() || global.diag.useDeprecated != DiagnosticReporting.error) && (ad.type && ad.type.ty != Terror)) { // Evaluate: RTinfo!type @@ -1638,9 +1638,9 @@ void semanticTypeInfoMembers(StructDeclaration sd) sd.xeq._scope && sd.xeq.semanticRun < PASS.semantic3done) { - const errors = global.startGagging(); + const errors = global.diag.startGagging(); sd.xeq.semantic3(sd.xeq._scope); - if (global.endGagging(errors)) + if (global.diag.endGagging(errors)) sd.xeq = sd.xerreq; } @@ -1648,9 +1648,9 @@ void semanticTypeInfoMembers(StructDeclaration sd) sd.xcmp._scope && sd.xcmp.semanticRun < PASS.semantic3done) { - const errors = global.startGagging(); + const errors = global.diag.startGagging(); sd.xcmp.semantic3(sd.xcmp._scope); - if (global.endGagging(errors)) + if (global.diag.endGagging(errors)) sd.xcmp = sd.xerrcmp; } @@ -1701,13 +1701,13 @@ extern (D) bool checkClosure(FuncDeclaration fd) if (fd.setGC(fd.loc, "%s `%s` is `@nogc` yet allocates closure for `%s()` with the GC", fd)) { .error(fd.loc, "%s `%s` is `@nogc` yet allocates closure for `%s()` with the GC", fd.kind, fd.toPrettyChars(), fd.toChars()); - if (global.gag) // need not report supplemental errors + if (global.diag.gag) // need not report supplemental errors return true; } else if (!global.params.useGC) { .error(fd.loc, "%s `%s` is `-betterC` yet allocates closure for `%s()` with the GC", fd.kind, fd.toPrettyChars(), fd.toChars()); - if (global.gag) // need not report supplemental errors + if (global.diag.gag) // need not report supplemental errors return true; } else diff --git a/compiler/src/dmd/statement.d b/compiler/src/dmd/statement.d index 5c759b088f5d..a7b01fd8eee6 100644 --- a/compiler/src/dmd/statement.d +++ b/compiler/src/dmd/statement.d @@ -331,7 +331,7 @@ extern (C++) final class ErrorStatement : Statement super(Loc.initial, STMT.Error); import dmd.globals; - assert(global.gaggedErrors || global.errors); + assert(global.diag.gaggedErrors || global.diag.errors); } override ErrorStatement syntaxCopy() diff --git a/compiler/src/dmd/statementsem.d b/compiler/src/dmd/statementsem.d index 597124f7a5eb..3b54063026c9 100644 --- a/compiler/src/dmd/statementsem.d +++ b/compiler/src/dmd/statementsem.d @@ -661,9 +661,9 @@ Statement statementSemanticVisit(Statement s, Scope* sc) // @@@DEPRECATED_2.112@@@ // remove gagging and deprecation() to turn deprecation into an error when // deprecation cycle is over - const olderrors = global.startGagging(); + const olderrors = global.diag.startGagging(); discardValue(fs.increment); - if (global.endGagging(olderrors)) + if (global.diag.endGagging(olderrors)) deprecation(fs.increment.loc, "`%s` has no effect", fs.increment.toChars()); if (checkNonAssignmentArrayOp(fs.increment)) fs.increment = ErrorExp.get(); @@ -1927,7 +1927,7 @@ Statement statementSemanticVisit(Statement s, Scope* sc) if (ed && ss.cases.length < ed.members.length) { int missingMembers = 0; - const maxShown = global.params.v.errorSupplementCount(); + const maxShown = global.diag.errorSupplementCount(); Lmembers: foreach (es; *ed.members) { @@ -2569,14 +2569,14 @@ Statement statementSemanticVisit(Statement s, Scope* sc) rs.exp = checkNoreturnVarAccess(rs.exp); // @@@DEPRECATED_2.111@@@ - const olderrors = global.startGagging(); + const olderrors = global.diag.startGagging(); // uncomment to turn deprecation into an error when // deprecation cycle is over if (discardValue(rs.exp)) { //errors = true; } - if (global.endGagging(olderrors)) + if (global.diag.endGagging(olderrors)) deprecation(rs.exp.loc, "`%s` has no effect", rs.exp.toChars()); /* Replace: @@ -4806,7 +4806,7 @@ private Statements* flatten(Statement statement, Scope* sc) if (expressionsToString(buf, sc, cs.exps, cs.loc, null, true)) return errorStatements(); - const errors = global.errors; + const errors = global.diag.errors; const len = buf.length; buf.writeByte(0); const str = buf.extractSlice()[0 .. len]; @@ -4819,7 +4819,7 @@ private Statements* flatten(Statement statement, Scope* sc) while (p.token.value != TOK.endOfFile) { Statement s = p.parseStatement(ParseStatementFlags.curlyScope); - if (!s || global.errors != errors) + if (!s || global.diag.errors != errors) return errorStatements(); a.push(s); } diff --git a/compiler/src/dmd/templateparamsem.d b/compiler/src/dmd/templateparamsem.d index f2dc50ebb702..bbf821739609 100644 --- a/compiler/src/dmd/templateparamsem.d +++ b/compiler/src/dmd/templateparamsem.d @@ -173,10 +173,10 @@ RootObject aliasParameterSemantic(Loc loc, Scope* sc, RootObject o, TemplatePara else if (TypeInstance ti = ta.isTypeInstance()) { Type t; - const errors = global.errors; + const errors = global.diag.errors; ta.resolve(loc, sc, ea, t, s); // if we had an error evaluating the symbol, suppress further errors - if (!t && errors != global.errors) + if (!t && errors != global.diag.errors) return Type.terror; // We might have something that looks like a type // but is actually an expression or a dsymbol diff --git a/compiler/src/dmd/templatesem.d b/compiler/src/dmd/templatesem.d index bd3674a8cc82..7f799aa167e4 100644 --- a/compiler/src/dmd/templatesem.d +++ b/compiler/src/dmd/templatesem.d @@ -353,9 +353,9 @@ MATCH matchWithInstance(Scope* sc, TemplateDeclaration td, TemplateInstance ti, // Resolve parameter types and 'auto ref's. tf.inferenceArguments = argumentList; - const olderrors = global.startGagging(); + const olderrors = global.diag.startGagging(); fd.type = tf.typeSemantic(td.loc, paramscope); - global.endGagging(olderrors); + global.diag.endGagging(olderrors); if (fd.type.ty != Tfunction) return nomatch(); fd.originalType = fd.type; // for mangling @@ -1421,7 +1421,7 @@ extern (D) MATCHpair deduceFunctionTemplateMatch(TemplateDeclaration td, Templat Dsymbol s; Scope *sco; - const errors = global.startGagging(); + const errors = global.diag.startGagging(); /* ref: https://issues.dlang.org/show_bug.cgi?id=11118 * The parameter isn't part of the template * ones, let's try to find it in the @@ -1434,7 +1434,7 @@ extern (D) MATCHpair deduceFunctionTemplateMatch(TemplateDeclaration td, Templat sco = paramscope; taa.index.resolve(instLoc, sco, e, t, s); } - global.endGagging(errors); + global.diag.endGagging(errors); if (!e) return nomatch(); diff --git a/compiler/src/dmd/toctype.d b/compiler/src/dmd/toctype.d index 38b69bc66220..fb2c2877a443 100644 --- a/compiler/src/dmd/toctype.d +++ b/compiler/src/dmd/toctype.d @@ -162,7 +162,7 @@ type* Type_toCtype(Type t) /* Add in fields of the struct * (after setting ctype to avoid infinite recursion) */ - if (driverParams.symdebug && !global.errors) + if (driverParams.symdebug && !global.diag.errors) { foreach (v; sym.fields) { diff --git a/compiler/src/dmd/traits.d b/compiler/src/dmd/traits.d index 7b32209fd2ef..868da940f8c2 100644 --- a/compiler/src/dmd/traits.d +++ b/compiler/src/dmd/traits.d @@ -1038,10 +1038,10 @@ Expression semanticTraits(TraitsExp e, Scope* sc) e.ident == Id.getVirtualMethods || e.ident == Id.getOverloads) { - const errors = global.errors; + const errors = global.diag.errors; Expression eorig = ex; ex = ex.expressionSemantic(scx); - if (errors < global.errors) + if (errors < global.diag.errors) error(e.loc, "`%s` cannot be resolved", eorig.toChars()); if (e.ident == Id.getVirtualFunctions) @@ -1746,7 +1746,7 @@ Expression semanticTraits(TraitsExp e, Scope* sc) foreach (o; *e.args) { - const errors = global.startGagging(); + const errors = global.diag.startGagging(); Scope* sc2 = sc.push(); sc2.tinst = null; sc2.minst = null; // this is why code for these are not emitted to object file @@ -1793,7 +1793,7 @@ Expression semanticTraits(TraitsExp e, Scope* sc) // https://issues.dlang.org/show_bug.cgi?id=15428 sc2.detach(); - if (global.endGagging(errors) || err) + if (global.diag.endGagging(errors) || err) { return False(); } diff --git a/compiler/src/dmd/typesem.d b/compiler/src/dmd/typesem.d index eebbf45573dc..d5a500466575 100644 --- a/compiler/src/dmd/typesem.d +++ b/compiler/src/dmd/typesem.d @@ -230,7 +230,7 @@ private void resolveHelper(TypeQualified mt, const ref Loc loc, Scope* sc, Dsymb } Type t = s.getType(); // type symbol, type alias, or type tuple? - const errorsave = global.errors; + const errorsave = global.diag.errors; SearchOptFlags flags = t is null ? SearchOpt.localsOnly : SearchOpt.ignorePrivateImports; Dsymbol sm = s.searchX(loc, sc, id, flags); @@ -251,7 +251,7 @@ private void resolveHelper(TypeQualified mt, const ref Loc loc, Scope* sc, Dsymb //sm = null; } } - if (global.errors != errorsave) + if (global.diag.errors != errorsave) { pt = Type.terror; return; @@ -1130,7 +1130,7 @@ private extern(D) MATCH argumentMatchParameter (TypeFunction tf, Parameter p, // arguments get specially formatted private const(char)* getParamError(TypeFunction tf, Expression arg, Parameter par) { - if (global.gag && !global.params.v.showGaggedErrors) + if (global.diag.gag && !global.diag.showGaggedErrors) return null; // show qualification when toChars() is the same but types are different // https://issues.dlang.org/show_bug.cgi?id=19948 @@ -1659,9 +1659,9 @@ Type typeSemantic(Type type, const ref Loc loc, Scope* sc) Type visitVector(TypeVector mtype) { - const errors = global.errors; + const errors = global.diag.errors; mtype.basetype = mtype.basetype.typeSemantic(loc, sc); - if (errors != global.errors) + if (errors != global.diag.errors) return error(); mtype.basetype = mtype.basetype.toBasetype().mutableOf(); if (mtype.basetype.ty != Tsarray) @@ -1734,10 +1734,10 @@ Type typeSemantic(Type type, const ref Loc loc, Scope* sc) Type tbn = tn.toBasetype(); if (mtype.dim) { - auto errors = global.errors; + auto errors = global.diag.errors; mtype.dim = semanticLength(sc, tbn, mtype.dim); mtype.dim = mtype.dim.implicitCastTo(sc, Type.tsize_t); - if (errors != global.errors) + if (errors != global.diag.errors) return error(); mtype.dim = mtype.dim.optimize(WANTvalue); @@ -1745,9 +1745,9 @@ Type typeSemantic(Type type, const ref Loc loc, Scope* sc) if (mtype.dim.op == EXP.error) return error(); - errors = global.errors; + errors = global.diag.errors; dinteger_t d1 = mtype.dim.toInteger(); - if (errors != global.errors) + if (errors != global.diag.errors) return error(); mtype.dim = mtype.dim.implicitCastTo(sc, Type.tsize_t); @@ -1755,9 +1755,9 @@ Type typeSemantic(Type type, const ref Loc loc, Scope* sc) if (mtype.dim.op == EXP.error) return error(); - errors = global.errors; + errors = global.diag.errors; dinteger_t d2 = mtype.dim.toInteger(); - if (errors != global.errors) + if (errors != global.diag.errors) return error(); if (mtype.dim.op == EXP.error) @@ -1957,9 +1957,9 @@ Type typeSemantic(Type type, const ref Loc loc, Scope* sc) if (sd.xeq && sd.xeq.isGenerated() && sd.xeq._scope && sd.xeq.semanticRun < PASS.semantic3done) { - uint errors = global.startGagging(); + uint errors = global.diag.startGagging(); sd.xeq.semantic3(sd.xeq._scope); - if (global.endGagging(errors)) + if (global.diag.endGagging(errors)) sd.xeq = sd.xerreq; } @@ -2741,10 +2741,10 @@ Type typeSemantic(Type type, const ref Loc loc, Scope* sc) //printf("TypeInstance::semantic(%p, %s)\n", this, toChars()); { - const errors = global.errors; + const errors = global.diag.errors; mtype.resolve(loc, sc, e, t, s); // if we had an error evaluating the symbol, suppress further errors - if (!t && errors != global.errors) + if (!t && errors != global.diag.errors) return error(); } @@ -2789,7 +2789,7 @@ Type typeSemantic(Type type, const ref Loc loc, Scope* sc) if (!t) { - if (!global.errors) + if (!global.diag.errors) .error(mtype.loc, "`%s` does not give a valid type", mtype.toChars); return error(); } @@ -3159,14 +3159,14 @@ Type typeSemantic(Type type, const ref Loc loc, Scope* sc) Type trySemantic(Type type, const ref Loc loc, Scope* sc) { - //printf("+trySemantic(%s) %d\n", toChars(), global.errors); + //printf("+trySemantic(%s) %d\n", toChars(), global.diag.errors); // Needed to display any deprecations that were gagged auto tcopy = type.syntaxCopy(); - const errors = global.startGagging(); + const errors = global.diag.startGagging(); Type t = typeSemantic(type, loc, sc); - if (global.endGagging(errors) || t.ty == Terror) // if any errors happened + if (global.diag.endGagging(errors) || t.ty == Terror) // if any errors happened { t = null; } @@ -3175,10 +3175,10 @@ Type trySemantic(Type type, const ref Loc loc, Scope* sc) // If `typeSemantic` succeeded, there may have been deprecations that // were gagged due the `startGagging` above. Run again to display // those deprecations. https://issues.dlang.org/show_bug.cgi?id=19107 - if (global.gaggedWarnings > 0) + if (global.diag.gaggedWarnings > 0) typeSemantic(tcopy, loc, sc); } - //printf("-trySemantic(%s) %d\n", toChars(), global.errors); + //printf("-trySemantic(%s) %d\n", toChars(), global.diag.errors); return t; } @@ -4019,7 +4019,7 @@ void resolve(Type mt, const ref Loc loc, Scope* sc, out Expression pe, out Type //printf("TypeInstance::resolve(sc = %p, tempinst = '%s')\n", sc, mt.tempinst.toChars()); mt.tempinst.dsymbolSemantic(sc); - if (!global.gag && mt.tempinst.errors) + if (!global.diag.gag && mt.tempinst.errors) return returnError(); mt.resolveHelper(loc, sc, mt.tempinst, null, pe, pt, ps, intypeid); @@ -4073,7 +4073,7 @@ void resolve(Type mt, const ref Loc loc, Scope* sc, out Expression pe, out Type if (exp2.op == EXP.error) { - if (!global.gag) + if (!global.diag.gag) mt.exp = exp2; goto Lerr; } @@ -4377,7 +4377,7 @@ void resolve(Type mt, const ref Loc loc, Scope* sc, out Expression pe, out Type } else { - assert(global.errors); + assert(global.diag.errors); mt.obj = Type.terror; return returnError(); } @@ -4925,9 +4925,9 @@ Expression dotExp(Type mt, Scope* sc, Expression e, Identifier ident, DotExpFlag * e.g. * template opDispatch(name) if (isValid!name) { ... } */ - const errors = gagError ? global.startGagging() : 0; + const errors = gagError ? global.diag.startGagging() : 0; e = dti.dotTemplateSemanticProp(sc, DotExpFlag.none); - if (gagError && global.endGagging(errors)) + if (gagError && global.diag.endGagging(errors)) e = null; return returnExp(e); } @@ -4943,11 +4943,11 @@ Expression dotExp(Type mt, Scope* sc, Expression e, Identifier ident, DotExpFlag */ auto die = new DotIdExp(e.loc, alias_e, ident); - const errors = gagError ? 0 : global.startGagging(); + const errors = gagError ? 0 : global.diag.startGagging(); auto exp = die.dotIdSemanticProp(sc, gagError); if (!gagError) { - global.endGagging(errors); + global.diag.endGagging(errors); if (exp && exp.op == EXP.error) exp = null; } @@ -7856,7 +7856,7 @@ RootObject compileTypeMixin(TypeMixin tm, ref const Loc loc, Scope* sc) if (expressionsToString(buf, sc, tm.exps, tm.loc, null, true)) return null; - const errors = global.errors; + const errors = global.diag.errors; const len = buf.length; buf.writeByte(0); const str = buf.extractSlice()[0 .. len]; @@ -7867,9 +7867,9 @@ RootObject compileTypeMixin(TypeMixin tm, ref const Loc loc, Scope* sc) //printf("p.loc.linnum = %d\n", p.loc.linnum); auto o = p.parseTypeOrAssignExp(TOK.endOfFile); - if (errors != global.errors) + if (errors != global.diag.errors) { - assert(global.errors != errors); // should have caught all these cases + assert(global.diag.errors != errors); // should have caught all these cases return null; } if (p.token.value != TOK.endOfFile) diff --git a/compiler/src/dmd/typinf.d b/compiler/src/dmd/typinf.d index 98d4287b8db5..aacfd730f5d2 100644 --- a/compiler/src/dmd/typinf.d +++ b/compiler/src/dmd/typinf.d @@ -46,7 +46,7 @@ bool genTypeInfo(Expression e, const ref Loc loc, Type torig, Scope* sc) { if (!global.params.useTypeInfo) { - global.gag = 0; + global.diag.gag = 0; if (e) .error(loc, "expression `%s` uses the GC and cannot be used with switch `-betterC`", e.toChars()); else diff --git a/compiler/src/tests/cxxfrontend.cc b/compiler/src/tests/cxxfrontend.cc index 5355aa93f9af..f5a711596652 100644 --- a/compiler/src/tests/cxxfrontend.cc +++ b/compiler/src/tests/cxxfrontend.cc @@ -276,7 +276,7 @@ void test_semantic() Module *m = Module::create("object.d", Identifier::idPool("object"), 0, 0); - unsigned errors = global.startGagging(); + unsigned errors = global.diag.startGagging(); m->src = src; m->parse(); @@ -297,7 +297,7 @@ void test_semantic() ClassDeclaration *cd = ad->isClassDeclaration(); assert(cd && cd->hasMonitor()); - assert(!global.endGagging(errors)); + assert(!global.diag.endGagging(errors)); } /**********************************/ @@ -314,7 +314,7 @@ void test_skip_importall() Module *m = Module::create("rootobject.d", Identifier::idPool("rootobject"), 0, 0); - unsigned errors = global.startGagging(); + unsigned errors = global.diag.startGagging(); m->src = src; m->parse(); @@ -323,7 +323,7 @@ void test_skip_importall() dmd::semantic2(m, NULL); dmd::semantic3(m, NULL); - assert(!global.endGagging(errors)); + assert(!global.diag.endGagging(errors)); } /**********************************/ @@ -500,7 +500,7 @@ void test_cppmangle() Module *m = Module::create("cppa.d", Identifier::idPool("cppa"), 0, 0); - unsigned errors = global.startGagging(); + unsigned errors = global.diag.startGagging(); FuncDeclaration *fd; const char *mangle; @@ -530,15 +530,15 @@ void test_cppmangle() mangle = dmd::cppThunkMangleItanium(fd, b->offset); assert(strcmp(mangle, "_ZThn8_N7Derived7MethodDEv") == 0); - assert(!global.endGagging(errors)); + assert(!global.diag.endGagging(errors)); } void test_module() { - unsigned errors = global.startGagging(); + unsigned errors = global.diag.startGagging(); Module *mod = Module::load(Loc(), NULL, Identifier::idPool("doesnotexist.d")); assert(mod == NULL); - assert(global.endGagging(errors)); + assert(global.diag.endGagging(errors)); } void test_optional() @@ -1624,7 +1624,7 @@ class MiniGlueVisitor : public Visitor dmd::functionSemantic3(d); Module::runDeferredSemantic3(); } - if (global.errors) + if (global.diag.errors) return; visitDeclaration(d); if (!d->fbody) diff --git a/compiler/test/dub_package/retrieve_scope.d b/compiler/test/dub_package/retrieve_scope.d index 05dd643e06be..f6e45f1b83eb 100755 --- a/compiler/test/dub_package/retrieve_scope.d +++ b/compiler/test/dub_package/retrieve_scope.d @@ -74,7 +74,7 @@ int main() va_list args, const(char)* prefix1, const(char)* prefix2) => true; - global.gag = 1; + global.diag.gag = 1; initDMD(diagnosticHandler); Module m = parseModule("testfiles/correct.d").module_; diff --git a/compiler/test/fail_compilation/fail134.d b/compiler/test/fail_compilation/fail134.d index d8ae89cdf8ed..f73026fe1453 100644 --- a/compiler/test/fail_compilation/fail134.d +++ b/compiler/test/fail_compilation/fail134.d @@ -8,7 +8,7 @@ fail_compilation/fail134.d(15): Error: template instance `fail134.bar!(f)` error */ // https://issues.dlang.org/show_bug.cgi?id=651 -// Assertion failure: 'global.errors' on line 2622 in file 'template.c' +// Assertion failure: 'global.diag.errors' on line 2622 in file 'template.c' void f() {} template foo(T) {} template bar(T...) { alias foo!(T) buz; } diff --git a/compiler/test/fail_compilation/ice15172.d b/compiler/test/fail_compilation/ice15172.d index aa070f6db1b2..726110259592 100644 --- a/compiler/test/fail_compilation/ice15172.d +++ b/compiler/test/fail_compilation/ice15172.d @@ -28,6 +28,6 @@ void onThreadError() // 7. ctfeInterpret // Finally, FuncDeclaration::interpret may encounter a function which is semantic3Errors == true. So // 7a. functionSemantic3() should return false if semantic3Errors is true. - // 7b. the function body errors may not happen during ctfeInterpret call and global.errors could be unincremented. + // 7b. the function body errors may not happen during ctfeInterpret call and global.diag.errors could be unincremented. __gshared auto ThreadError = new ThreadError(null); } diff --git a/compiler/test/unit/compilable/searching.d b/compiler/test/unit/compilable/searching.d index 5add95dfc8fd..f4cf1a4c808a 100644 --- a/compiler/test/unit/compilable/searching.d +++ b/compiler/test/unit/compilable/searching.d @@ -173,11 +173,11 @@ Dsymbol findSymbol(Dsymbol sym, string name, bool allowMissing = false) { assert(sym, "Missing symbol while searching for: " ~ name); - const oldErrors = global.errors; + const oldErrors = global.diag.errors; Identifier id = Identifier.idPool(name); Dsymbol found = sym.search(Loc.initial, id, SearchOpt.ignoreErrors); - assert(global.errors == oldErrors, "Searching " ~ name ~ " caused errors!"); + assert(global.diag.errors == oldErrors, "Searching " ~ name ~ " caused errors!"); assert(allowMissing || found, name ~ " not found!"); return found; } diff --git a/compiler/test/unit/frontend.d b/compiler/test/unit/frontend.d index c970e5aa8f30..2cf6c0f6b69b 100644 --- a/compiler/test/unit/frontend.d +++ b/compiler/test/unit/frontend.d @@ -205,7 +205,7 @@ unittest t.module_.fullSemantic(); - assert(global.errors == 0); + assert(global.diag.errors == 0); } @("initDMD - version identifiers") @@ -233,7 +233,7 @@ unittest t.module_.fullSemantic(); - assert(global.errors == 0); + assert(global.diag.errors == 0); } @("initDMD - custom diagnostic handling") @@ -296,7 +296,7 @@ unittest t.module_.fullSemantic(); - assert(global.errors == 0); + assert(global.diag.errors == 0); } @("initDMD - floating-point") @@ -319,7 +319,7 @@ unittest t.module_.fullSemantic(); - assert(global.errors == 0); + assert(global.diag.errors == 0); } @("inline assembly") @@ -348,7 +348,7 @@ unittest t.module_.fullSemantic(); - assert(global.errors == 0); + assert(global.diag.errors == 0); } // Issue https://issues.dlang.org/show_bug.cgi?id=22906 @@ -387,7 +387,7 @@ unittest t.module_.fullSemantic(); - assert(global.errors == 1); + assert(global.diag.errors == 1); assert(endsWith(diagnosticMessages[0], "is a Ddoc file, cannot import it")); } diff --git a/compiler/test/unit/parser/diagnostic_reporter.d b/compiler/test/unit/parser/diagnostic_reporter.d index 719811fa315f..a844760c43e2 100644 --- a/compiler/test/unit/parser/diagnostic_reporter.d +++ b/compiler/test/unit/parser/diagnostic_reporter.d @@ -86,7 +86,7 @@ unittest } } - global.params.useWarnings = DiagnosticReporting.inform; + global.diag.useWarnings = DiagnosticReporting.inform; scope reporter = new WarningCountingDiagnosticReporter; parseModule("test.d", q{ diff --git a/compiler/test/unit/semantic/control_flow.d b/compiler/test/unit/semantic/control_flow.d index 0e4b0918044f..c48a28ad157a 100644 --- a/compiler/test/unit/semantic/control_flow.d +++ b/compiler/test/unit/semantic/control_flow.d @@ -898,7 +898,7 @@ void testBlockExit(FuncDeclaration fd, Statement stmt, const BE expected) const actual = blockExit(stmt, fd, null); assert(actual == expected, beToString(actual) ~ " != " ~ beToString(expected)); - assert(!global.errors, "`blockExit` raised an error!"); + assert(!global.diag.errors, "`blockExit` raised an error!"); } //======================================================================================== diff --git a/compiler/test/unit/semantic/covariance.d b/compiler/test/unit/semantic/covariance.d index dc2123146d9f..57404f1f0e0e 100644 --- a/compiler/test/unit/semantic/covariance.d +++ b/compiler/test/unit/semantic/covariance.d @@ -859,7 +859,7 @@ void testCovariant(Type base, Type target, in Result expected, const size_t line StorageClass actualStc; const actual = base.covariant(target, &actualStc); - enforce(!global.errors, line, "`covariant` raised an error!"); + enforce(!global.diag.errors, line, "`covariant` raised an error!"); enforce(actual == expected.result, line, cast(string) ( "Unexpected result!\n\n" ~