Skip to content

Commit 4115be5

Browse files
[FrontendTool] Use a null diagconsumer for verify instance
Use a null diagnostic consumer in the deterministic verify instance. The constraint system will skip work if there are no consumer in the diagnostic engine. Use a null consumer to make sure the same amount of work is done for two runs.
1 parent b8879ee commit 4115be5

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/FrontendTool/FrontendTool.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "swift/AST/ASTDumper.h"
2727
#include "swift/AST/ASTMangler.h"
2828
#include "swift/AST/AvailabilityScope.h"
29+
#include "swift/AST/DiagnosticConsumer.h"
2930
#include "swift/AST/DiagnosticsFrontend.h"
3031
#include "swift/AST/DiagnosticsSema.h"
3132
#include "swift/AST/FileSystem.h"
@@ -2100,6 +2101,11 @@ int swift::performFrontend(ArrayRef<const char *> Args,
21002101
// Setup a verfication instance to run.
21012102
std::unique_ptr<CompilerInstance> VerifyInstance =
21022103
std::make_unique<CompilerInstance>();
2104+
// Add a null diagnostic consumer to the diagnostic engine so the
2105+
// compilation will exercise all the diagnose code path but not emitting
2106+
// anything.
2107+
NullDiagnosticConsumer DC;
2108+
VerifyInstance->getDiags().addConsumer(DC);
21032109
std::string InstanceSetupError;
21042110
// This should not fail because it passed already.
21052111
(void)VerifyInstance->setup(Invocation, InstanceSetupError, Args);

test/Frontend/output_determinism_check.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
// PCM_OUTPUT: remark: produced matching output file '{{.*}}{{/|\\}}test.pcm'
3838

3939
public var x = 1
40-
public func test() {}
40+
public func test() {
41+
precondition(x == 1, "dummy check")
42+
}
4143

4244
class A {
4345
var a = 0

0 commit comments

Comments
 (0)