Skip to content

Commit

Permalink
Stateful ErrorSinks can now react to compilation ending. (#17051)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxhaton authored Nov 4, 2024
1 parent d33ffce commit ccd589d
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compiler/src/dmd/errors.d
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,8 @@ extern (C++) void fatal()
if (fatalErrorHandler && fatalErrorHandler())
return;

global.plugErrorSinks();

exit(EXIT_FAILURE);
}

Expand Down
9 changes: 9 additions & 0 deletions compiler/src/dmd/errorsink.d
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ abstract class ErrorSink
void deprecation(const ref Loc loc, const(char)* format, ...);

void deprecationSupplemental(const ref Loc loc, const(char)* format, ...);

/**
* This will be called to indicate compilation has either
* finished or terminated, no more errors are possible - it's
* now the time to print any stored errors.
*
* The default implementation does nothing since most error sinks have no state
*/
void plugSink() {}
}

/*****************************************
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dmd/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -8511,6 +8511,7 @@ struct Global final
bool endGagging(uint32_t oldGagged);
void increaseErrorCount();
void _init();
void plugErrorSinks();
uint32_t versionNumber();
const char* const versionChars();
Global() :
Expand Down
11 changes: 11 additions & 0 deletions compiler/src/dmd/globals.d
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,17 @@ extern (C++) struct Global
return major * 1000 + minor;
}

/**
* Indicate to stateful error sinks that no more errors can be produced.
* This is to support error sinks that collect information to produce a
* single (say) report.
*/
extern(C++) void plugErrorSinks()
{
global.errorSink.plugSink();
global.errorSinkNull.plugSink();
}

/**
Returns: the version as the number that would be returned for __VERSION__
*/
Expand Down
7 changes: 7 additions & 0 deletions compiler/src/dmd/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,13 @@ struct Global

void _init();

/**
* Indicate to stateful error sinks that no more errors can be produced.
* This is to support error sinks that collect information to produce a
* single (say) report.
*/
void plugErrorSinks();

/**
Returns: the version as the number that would be returned for __VERSION__
*/
Expand Down
8 changes: 8 additions & 0 deletions compiler/src/dmd/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ private int tryMain(size_t argc, const(char)** argv, ref Param params)
Strings files;
Strings libmodules;
global._init();

scope(exit)
{
// If we are here then compilation has ended
// gracefully as opposed to with `fatal`
global.plugErrorSinks();
}

target.setTargetBuildDefaults();

if (parseCommandlineAndConfig(argc, argv, params, files))
Expand Down

0 comments on commit ccd589d

Please sign in to comment.