Skip to content

Commit 1c56db8

Browse files
committed
---
yaml --- r: 345527 b: refs/heads/master c: 88c8848 h: refs/heads/master i: 345525: e737c0a 345523: 3da451d 345519: 7699ffd
1 parent b7abd8f commit 1c56db8

File tree

7 files changed

+88
-42
lines changed

7 files changed

+88
-42
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 99ea4485c711b529a4719ec32335f51ee81af018
2+
refs/heads/master: 88c884874ec2b9607efbedcde6661ca624c26449
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//===--- InstrumenterSupport.cpp - Instrumenter Support -------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file implements the supporting functions for writing instrumenters of
14+
// the Swift AST.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
#ifndef SWIFT_AST_DIAGNOSTIC_SUPPRESSION_H
19+
#define SWIFT_AST_DIAGNOSTIC_SUPPRESSION_H
20+
21+
#include <vector>
22+
23+
namespace swift {
24+
25+
class DiagnosticConsumer;
26+
class DiagnosticEngine;
27+
28+
/// RAII class that suppresses diagnostics by temporarily disabling all of
29+
/// the diagnostic consumers.
30+
class DiagnosticSuppression {
31+
DiagnosticEngine &diags;
32+
std::vector<DiagnosticConsumer *> consumers;
33+
34+
DiagnosticSuppression(const DiagnosticSuppression &) = delete;
35+
DiagnosticSuppression &operator=(const DiagnosticSuppression &) = delete;
36+
37+
public:
38+
explicit DiagnosticSuppression(DiagnosticEngine &diags);
39+
~DiagnosticSuppression();
40+
};
41+
42+
}
43+
#endif /* SWIFT_AST_DIAGNOSTIC_SUPPRESSION_H */

trunk/lib/AST/DiagnosticEngine.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "swift/AST/ASTContext.h"
2020
#include "swift/AST/ASTPrinter.h"
2121
#include "swift/AST/Decl.h"
22+
#include "swift/AST/DiagnosticSuppression.h"
2223
#include "swift/AST/Module.h"
2324
#include "swift/AST/Pattern.h"
2425
#include "swift/AST/PrintOptions.h"
@@ -831,3 +832,14 @@ void DiagnosticEngine::emitDiagnostic(const Diagnostic &diagnostic) {
831832
const char *DiagnosticEngine::diagnosticStringFor(const DiagID id) {
832833
return diagnosticStrings[(unsigned)id];
833834
}
835+
836+
DiagnosticSuppression::DiagnosticSuppression(DiagnosticEngine &diags)
837+
: diags(diags)
838+
{
839+
consumers = diags.takeConsumers();
840+
}
841+
842+
DiagnosticSuppression::~DiagnosticSuppression() {
843+
for (auto consumer : consumers)
844+
diags.addConsumer(*consumer);
845+
}

trunk/lib/Sema/InstrumenterSupport.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
//===----------------------------------------------------------------------===//
1717

1818
#include "InstrumenterSupport.h"
19+
#include "swift/AST/DiagnosticSuppression.h"
1920

2021
using namespace swift;
2122
using namespace swift::instrumenter_support;
@@ -77,10 +78,10 @@ void InstrumenterBase::anchor() {}
7778

7879
bool InstrumenterBase::doTypeCheckImpl(ASTContext &Ctx, DeclContext *DC,
7980
Expr * &parsedExpr) {
80-
DiagnosticEngine diags(Ctx.SourceMgr);
81-
ErrorGatherer errorGatherer(diags);
81+
DiagnosticSuppression suppression(Ctx.Diags);
82+
ErrorGatherer errorGatherer(Ctx.Diags);
8283

83-
TypeChecker TC(Ctx, diags);
84+
TypeChecker TC(Ctx);
8485

8586
TC.typeCheckExpression(parsedExpr, DC);
8687

trunk/lib/Sema/TypeChecker.cpp

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "swift/AST/ASTWalker.h"
2525
#include "swift/AST/ASTVisitor.h"
2626
#include "swift/AST/Attr.h"
27+
#include "swift/AST/DiagnosticSuppression.h"
2728
#include "swift/AST/ExistentialLayout.h"
2829
#include "swift/AST/Identifier.h"
2930
#include "swift/AST/Initializer.h"
@@ -49,8 +50,8 @@
4950

5051
using namespace swift;
5152

52-
TypeChecker::TypeChecker(ASTContext &Ctx, DiagnosticEngine &Diags)
53-
: Context(Ctx), Diags(Diags)
53+
TypeChecker::TypeChecker(ASTContext &Ctx)
54+
: Context(Ctx), Diags(Ctx.Diags)
5455
{
5556
auto clangImporter =
5657
static_cast<ClangImporter *>(Context.getClangModuleLoader());
@@ -750,13 +751,10 @@ bool swift::performTypeLocChecking(ASTContext &Ctx, TypeLoc &T,
750751
options |= TypeResolutionFlags::SILType;
751752

752753
auto resolution = TypeResolution::forContextual(DC, GenericEnv);
753-
if (ProduceDiagnostics) {
754-
return TypeChecker(Ctx).validateType(T, resolution, options);
755-
} else {
756-
// Set up a diagnostics engine that swallows diagnostics.
757-
DiagnosticEngine Diags(Ctx.SourceMgr);
758-
return TypeChecker(Ctx, Diags).validateType(T, resolution, options);
759-
}
754+
Optional<DiagnosticSuppression> suppression;
755+
if (!ProduceDiagnostics)
756+
suppression.emplace(Ctx.Diags);
757+
return TypeChecker(Ctx).validateType(T, resolution, options);
760758
}
761759

762760
/// Expose TypeChecker's handling of GenericParamList to SIL parsing.
@@ -769,9 +767,8 @@ swift::handleSILGenericParams(ASTContext &Ctx, GenericParamList *genericParams,
769767
void swift::typeCheckCompletionDecl(Decl *D) {
770768
auto &Ctx = D->getASTContext();
771769

772-
// Set up a diagnostics engine that swallows diagnostics.
773-
DiagnosticEngine Diags(Ctx.SourceMgr);
774-
TypeChecker TC(Ctx, Diags);
770+
DiagnosticSuppression suppression(Ctx.Diags);
771+
TypeChecker TC(Ctx);
775772

776773
if (auto ext = dyn_cast<ExtensionDecl>(D))
777774
TC.validateExtension(ext);
@@ -827,15 +824,14 @@ Optional<Type> swift::getTypeOfCompletionContextExpr(
827824
CompletionTypeCheckKind kind,
828825
Expr *&parsedExpr,
829826
ConcreteDeclRef &referencedDecl) {
827+
DiagnosticSuppression suppression(Ctx.Diags);
830828

831829
if (Ctx.getLazyResolver()) {
832830
TypeChecker *TC = static_cast<TypeChecker *>(Ctx.getLazyResolver());
833831
return ::getTypeOfCompletionContextExpr(*TC, DC, kind, parsedExpr,
834832
referencedDecl);
835833
} else {
836-
// Set up a diagnostics engine that swallows diagnostics.
837-
DiagnosticEngine diags(Ctx.SourceMgr);
838-
TypeChecker TC(Ctx, diags);
834+
TypeChecker TC(Ctx);
839835
// Try to solve for the actual type of the expression.
840836
return ::getTypeOfCompletionContextExpr(TC, DC, kind, parsedExpr,
841837
referencedDecl);
@@ -844,29 +840,27 @@ Optional<Type> swift::getTypeOfCompletionContextExpr(
844840

845841
bool swift::typeCheckCompletionSequence(DeclContext *DC, Expr *&parsedExpr) {
846842
auto &ctx = DC->getASTContext();
843+
DiagnosticSuppression suppression(ctx.Diags);
847844
if (ctx.getLazyResolver()) {
848845
TypeChecker *TC = static_cast<TypeChecker *>(ctx.getLazyResolver());
849846
return TC->typeCheckCompletionSequence(parsedExpr, DC);
850847
} else {
851-
// Set up a diagnostics engine that swallows diagnostics.
852-
DiagnosticEngine diags(ctx.SourceMgr);
853-
TypeChecker TC(ctx, diags);
848+
TypeChecker TC(ctx);
854849
return TC.typeCheckCompletionSequence(parsedExpr, DC);
855850
}
856851
}
857852

858853
bool swift::typeCheckExpression(DeclContext *DC, Expr *&parsedExpr) {
859854
auto &ctx = DC->getASTContext();
855+
DiagnosticSuppression suppression(ctx.Diags);
860856
if (ctx.getLazyResolver()) {
861857
TypeChecker *TC = static_cast<TypeChecker *>(ctx.getLazyResolver());
862858
auto resultTy = TC->typeCheckExpression(parsedExpr, DC, TypeLoc(),
863859
ContextualTypePurpose::CTP_Unused,
864860
TypeCheckExprFlags::SuppressDiagnostics);
865861
return !resultTy;
866862
} else {
867-
// Set up a diagnostics engine that swallows diagnostics.
868-
DiagnosticEngine diags(ctx.SourceMgr);
869-
TypeChecker TC(ctx, diags);
863+
TypeChecker TC(ctx);
870864
auto resultTy = TC.typeCheckExpression(parsedExpr, DC, TypeLoc(),
871865
ContextualTypePurpose::CTP_Unused,
872866
TypeCheckExprFlags::SuppressDiagnostics);
@@ -877,35 +871,26 @@ bool swift::typeCheckExpression(DeclContext *DC, Expr *&parsedExpr) {
877871
bool swift::typeCheckAbstractFunctionBodyUntil(AbstractFunctionDecl *AFD,
878872
SourceLoc EndTypeCheckLoc) {
879873
auto &Ctx = AFD->getASTContext();
874+
DiagnosticSuppression suppression(Ctx.Diags);
880875

881-
// Set up a diagnostics engine that swallows diagnostics.
882-
DiagnosticEngine Diags(Ctx.SourceMgr);
883-
884-
TypeChecker TC(Ctx, Diags);
876+
TypeChecker TC(Ctx);
885877
return !TC.typeCheckAbstractFunctionBodyUntil(AFD, EndTypeCheckLoc);
886878
}
887879

888880
bool swift::typeCheckTopLevelCodeDecl(TopLevelCodeDecl *TLCD) {
889881
auto &Ctx = static_cast<Decl *>(TLCD)->getASTContext();
890-
891-
// Set up a diagnostics engine that swallows diagnostics.
892-
DiagnosticEngine Diags(Ctx.SourceMgr);
893-
894-
TypeChecker TC(Ctx, Diags);
882+
DiagnosticSuppression suppression(Ctx.Diags);
883+
TypeChecker TC(Ctx);
895884
TC.typeCheckTopLevelCodeDecl(TLCD);
896885
return true;
897886
}
898887

899-
static void deleteTypeCheckerAndDiags(LazyResolver *resolver) {
900-
DiagnosticEngine &diags = static_cast<TypeChecker*>(resolver)->Diags;
888+
static void deleteTypeChecker(LazyResolver *resolver) {
901889
delete resolver;
902-
delete &diags;
903890
}
904891

905892
OwnedResolver swift::createLazyResolver(ASTContext &Ctx) {
906-
auto diags = new DiagnosticEngine(Ctx.SourceMgr);
907-
return OwnedResolver(new TypeChecker(Ctx, *diags),
908-
&deleteTypeCheckerAndDiags);
893+
return OwnedResolver(new TypeChecker(Ctx), &deleteTypeChecker);
909894
}
910895

911896
// checkForForbiddenPrefix is for testing purposes.

trunk/lib/Sema/TypeChecker.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,8 +726,7 @@ class TypeChecker final : public LazyResolver {
726726
Expr* constructCallToSuperInit(ConstructorDecl *ctor, ClassDecl *ClDecl);
727727

728728
public:
729-
TypeChecker(ASTContext &Ctx) : TypeChecker(Ctx, Ctx.Diags) { }
730-
TypeChecker(ASTContext &Ctx, DiagnosticEngine &Diags);
729+
TypeChecker(ASTContext &Ctx);
731730
TypeChecker(const TypeChecker&) = delete;
732731
TypeChecker& operator=(const TypeChecker&) = delete;
733732
~TypeChecker();

trunk/test/IRGen/playground.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ import Swift
99

1010
@objc class C { }
1111

12+
private func __builtin_log_scope_entry(_ startLine: Int, _ startColumn: Int,
13+
_ endLine: Int, _ endColumn: Int) { }
14+
private func __builtin_log_scope_exit(_ startLine: Int, _ startColumn: Int,
15+
_ endLine: Int, _ endColumn: Int) { }
16+
private func __builtin_send_data<T>(_ object: T) { }
17+
1218
public func anchor() {}
1319

1420
anchor()

0 commit comments

Comments
 (0)