Skip to content

Commit

Permalink
Limit the number of deprecation messages by default (#16403)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorpel authored Apr 22, 2024
1 parent c09adbb commit 499a851
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 6 deletions.
26 changes: 26 additions & 0 deletions changelog/dmd.deprecation-limit.dd
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Deprecation warnings are now also limited by `-verrors`

By default, the compiler stops after 20 error messages, unless a different amount is specified by passing e.g. `-verrors=50` or `-verrors=0` for no limit.
This error limit now also applies to deprecation messages, so the command line isn't flooded with hundreds of them when compiling a big project that hasn't fixed all deprecations yet.

---
deprecated void f()
{
}

void main()
{
f();
f();
f();
f();
}
---

$(CONSOLE
> dmd -verrors=3 app.d
app.d(7): Deprecation: function `deprecationlimit.x` is deprecated
app.d(8): Deprecation: function `deprecationlimit.x` is deprecated
app.d(9): Deprecation: function `deprecationlimit.x` is deprecated
1 deprecation warning omitted, use `-verrors=0` to show all
)
2 changes: 1 addition & 1 deletion compiler/src/dmd/cli.d
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ dmd -cov -unittest myprog.d
"limit the number of supplemental messages for each error (0 means unlimited)"
),
Option("verrors=<num>",
"limit the number of error messages (0 means unlimited)"
"limit the number of error/deprecation messages (0 means unlimited)"
),
Option("verrors=context",
"show error messages with the context of the erroring source line"
Expand Down
8 changes: 6 additions & 2 deletions compiler/src/dmd/errors.d
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,12 @@ extern (C++) void verrorReport(const ref Loc loc, const(char)* format, va_list a
{
if (!global.gag)
{
info.headerColor = Classification.deprecation;
verrorPrint(format, ap, info);
global.deprecations++;
if (global.params.v.errorLimit == 0 || global.deprecations <= global.params.v.errorLimit)
{
info.headerColor = Classification.deprecation;
verrorPrint(format, ap, info);
}
}
else
{
Expand Down
5 changes: 4 additions & 1 deletion compiler/src/dmd/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -8294,6 +8294,7 @@ struct Global final
CompileEnv compileEnv;
Param params;
uint32_t errors;
uint32_t deprecations;
uint32_t warnings;
uint32_t gag;
uint32_t gaggedErrors;
Expand Down Expand Up @@ -8324,6 +8325,7 @@ struct Global final
compileEnv(),
params(),
errors(),
deprecations(),
warnings(),
gag(),
gaggedErrors(),
Expand All @@ -8339,7 +8341,7 @@ struct Global final
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<const char* > path = Array<const char* >(), Array<const char* > filePath = Array<const char* >(), CompileEnv compileEnv = CompileEnv(), Param params = Param(), uint32_t errors = 0u, uint32_t warnings = 0u, uint32_t gag = 0u, uint32_t gaggedErrors = 0u, uint32_t gaggedWarnings = 0u, void* console = nullptr, Array<Identifier* > versionids = Array<Identifier* >(), Array<Identifier* > debugids = Array<Identifier* >(), bool hasMainFunction = false, uint32_t varSequenceNumber = 1u, FileManager* fileManager = nullptr, ErrorSink* errorSink = nullptr, ErrorSink* errorSinkNull = nullptr, DArray<uint8_t >(*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<const char* > path = Array<const char* >(), Array<const char* > filePath = Array<const char* >(), 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<Identifier* > versionids = Array<Identifier* >(), Array<Identifier* > debugids = Array<Identifier* >(), bool hasMainFunction = false, uint32_t varSequenceNumber = 1u, FileManager* fileManager = nullptr, ErrorSink* errorSink = nullptr, ErrorSink* errorSinkNull = nullptr, DArray<uint8_t >(*preprocess)(FileName , const Loc& , OutBuffer& ) = nullptr) :
inifilename(inifilename),
copyright(copyright),
written(written),
Expand All @@ -8348,6 +8350,7 @@ struct Global final
compileEnv(compileEnv),
params(params),
errors(errors),
deprecations(deprecations),
warnings(warnings),
gag(gag),
gaggedErrors(gaggedErrors),
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dmd/globals.d
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ extern (C++) struct Global

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
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dmd/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ struct Global

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
Expand Down
15 changes: 15 additions & 0 deletions compiler/src/dmd/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,18 @@ private int tryMain(size_t argc, const(char)** argv, ref Param params)
errorSupplemental(Loc.initial, "Use -wi if you wish to treat warnings only as informational.");
}

// 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)
{
const omitted = global.deprecations - global.params.v.errorLimit;
message(Loc.initial, "%d deprecation warning%s omitted, use `-verrors=0` to show all",
omitted, omitted == 1 ? "".ptr : "s".ptr);
}
}

/*
Generates code to check for all `params` whether any usage page
has been requested.
Expand Down Expand Up @@ -582,6 +594,9 @@ private int tryMain(size_t argc, const(char)** argv, ref Param params)
if (global.warnings)
errorOnWarning();

if (global.params.useDeprecated == DiagnosticReporting.inform)
mentionOmittedDeprecations();

// Do not attempt to generate output files if errors or warnings occurred
if (global.errors || global.warnings)
removeHdrFilesAndFail(params, modules);
Expand Down
22 changes: 22 additions & 0 deletions compiler/test/compilable/deprecationlimit.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
REQUIRED_ARGS: -verrors=3
TEST_OUTPUT:
---
compilable/deprecationlimit.d(18): Deprecation: function `deprecationlimit.f` is deprecated
compilable/deprecationlimit.d(19): Deprecation: function `deprecationlimit.f` is deprecated
compilable/deprecationlimit.d(20): Deprecation: function `deprecationlimit.f` is deprecated
1 deprecation warning omitted, use `-verrors=0` to show all
---
*/

deprecated void f()
{
}

void main()
{
f();
f();
f();
f();
}
2 changes: 1 addition & 1 deletion compiler/test/compilable/sw_transition_complex.d
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// PERMUTE_ARGS:
// REQUIRED_ARGS: -unittest
// REQUIRED_ARGS: -unittest -verrors=0

/*
TEST_OUTPUT:
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/runnable/template10.d
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// PERMUTE_ARGS: -inline
// REQUIRED_ARGS: -verrors=0
/* TEST_OUTPUT:
---
runnable/template10.d(89): Deprecation: function `template10.test1b.f0.f!(a).f` function requires a dual-context, which is deprecated
Expand Down Expand Up @@ -58,7 +59,6 @@ runnable/template10.d(741): instantiated from here: `fun!(n)`
*/

/********************************************/

void test1a()
{
int a = 1;
Expand Down

0 comments on commit 499a851

Please sign in to comment.