Skip to content

Commit 1b8b706

Browse files
authored
Merge pull request #62405 from DougGregor/macro-diagnostics
2 parents ef8c34e + a2dfd90 commit 1b8b706

26 files changed

+392
-852
lines changed

include/swift/AST/ASTContext.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ namespace swift {
132132
class IndexSubset;
133133
struct SILAutoDiffDerivativeFunctionKey;
134134
struct InterfaceSubContextDelegate;
135-
class CompilerPlugin;
136135

137136
enum class KnownProtocolKind : uint8_t;
138137

include/swift/AST/CASTBridging.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,49 @@ typedef struct {
8686
// FIXME: Handle Layout Requirements
8787
} BridgedRequirementRepr;
8888

89+
/// Diagnostic severity when reporting diagnostics.
90+
typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedDiagnosticSeverity : long {
91+
BridgedFatalError,
92+
BridgedError,
93+
BridgedWarning,
94+
BridgedRemark,
95+
BridgedNote,
96+
} BridgedDiagnosticSeverity;
97+
98+
typedef void* BridgedDiagnostic;
99+
89100
#ifdef __cplusplus
90101
extern "C" {
91102

92103
#define _Bool bool
93104

94105
#endif
95106

107+
// Diagnostics
108+
109+
/// Create a new diagnostic with the given severity, location, and diagnostic
110+
/// text.
111+
///
112+
/// \returns a diagnostic instance that can be extended with additional
113+
/// information and then must be finished via \c SwiftDiagnostic_finish.
114+
BridgedDiagnostic SwiftDiagnostic_create(
115+
void *diagnosticEngine, BridgedDiagnosticSeverity severity,
116+
void *_Nullable sourceLoc,
117+
const uint8_t *_Nullable text, long textLen);
118+
119+
/// Highlight a source range as part of the diagnostic.
120+
void SwiftDiagnostic_highlight(
121+
BridgedDiagnostic diag, void *_Nullable startLoc, void *_Nullable endLoc);
122+
123+
/// Add a Fix-It to replace a source range as part of the diagnostic.
124+
void SwiftDiagnostic_fixItReplace(
125+
BridgedDiagnostic diag,
126+
void *_Nullable replaceStartLoc, void *_Nullable replaceEndLoc,
127+
const uint8_t *_Nullable newText, long newTextLen);
128+
129+
/// Finish the given diagnostic and emit it.
130+
void SwiftDiagnostic_finish(BridgedDiagnostic diag);
131+
96132
BridgedIdentifier SwiftASTContext_getIdentifier(void *ctx,
97133
const uint8_t *_Nullable str,
98134
long len);

include/swift/AST/CompilerPlugin.h

Lines changed: 0 additions & 106 deletions
This file was deleted.

include/swift/AST/Decl.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8282,11 +8282,12 @@ class MissingMemberDecl : public Decl {
82828282

82838283
/// Provides a declaration of a macro.
82848284
///
8285+
/// Macros are declared within the source code with the `macro` introducer.
8286+
///
82858287
/// Macros are defined externally via conformances to the 'Macro' type
82868288
/// that is part of swift-syntax, and are introduced into the compiler via
8287-
/// various mechanisms (built-in macros are linked in directly, plugin macros
8288-
/// are introduced via compiler plugins, and so on). They have no explicit
8289-
/// representation in the source code, but are still declarations.
8289+
/// various mechanisms (e.g., in-process macros provided as builtins or
8290+
/// loaded via shared library, and so on).
82908291
class MacroDecl : public GenericContext, public ValueDecl {
82918292
public:
82928293
/// The location of the 'macro' keyword.

include/swift/AST/DiagnosticsCommon.def

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,5 +214,15 @@ REMARK(remark_save_cache, none,
214214
ERROR(unknown_attribute,none,
215215
"unknown attribute '%0'", (StringRef))
216216

217+
//------------------------------------------------------------------------------
218+
// MARK: bridged diagnostics
219+
//------------------------------------------------------------------------------
220+
221+
NOTE(bridged_note, none, "%0", (StringRef))
222+
WARNING(bridged_warning, none,"%0", (StringRef))
223+
ERROR(bridged_error, none, "%0", (StringRef))
224+
ERROR(bridged_fatal_error, Fatal, "%0", (StringRef))
225+
REMARK(bridged_remark, none, "%0", (StringRef))
226+
217227
#define UNDEFINE_DIAGNOSTIC_MACROS
218228
#include "DefineDiagnosticMacros.h"

include/swift/AST/KnownIdentifiers.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,6 @@ IDENTIFIER(unsafe)
333333
// The singleton instance of TupleTypeDecl in the Builtin module
334334
IDENTIFIER(TheTupleType)
335335

336-
// Macros / compiler plugins
337-
IDENTIFIER_(CompilerPluginSupport)
338-
339336
#undef IDENTIFIER
340337
#undef IDENTIFIER_
341338
#undef IDENTIFIER_WITH_NAME

include/swift/AST/KnownProtocols.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@ PROTOCOL(AsyncIteratorProtocol)
116116

117117
PROTOCOL(FloatingPoint)
118118

119-
// Compiler Plugins
120-
PROTOCOL_(CompilerPlugin)
121-
122119
EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByArrayLiteral, "Array", false)
123120
EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByBooleanLiteral, "BooleanLiteralType", true)
124121
EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByDictionaryLiteral, "Dictionary", false)

include/swift/AST/MacroDefinition.h

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222

2323
namespace swift {
2424

25-
class CompilerPlugin;
26-
2725
/// Provides the definition of a macro.
2826
struct MacroDefinition {
2927
/// The kind of macro, which determines how it can be used in source code.
@@ -34,12 +32,9 @@ struct MacroDefinition {
3432

3533
/// Describes how the macro is implemented.
3634
enum class ImplementationKind: uint8_t {
37-
/// The macro is built-in to the compiler, linked against the same
38-
/// underlying syntax tree libraries.
39-
Builtin,
40-
41-
/// The macro was defined in a compiler plugin.
42-
Plugin,
35+
/// The macro is in the same process as the compiler, whether built-in or
36+
/// loaded via a compiler plugin.
37+
InProcess,
4338
};
4439

4540
public:
@@ -55,39 +50,22 @@ struct MacroDefinition {
5550
public:
5651
static MacroDefinition forInvalid() {
5752
return MacroDefinition{
58-
Kind::Expression, ImplementationKind::Builtin, nullptr
53+
Kind::Expression, ImplementationKind::InProcess, nullptr
5954
};
6055
}
6156

62-
static MacroDefinition forBuiltin(Kind kind, void *opaqueHandle) {
63-
return MacroDefinition{kind, ImplementationKind::Builtin, opaqueHandle};
64-
}
65-
66-
static MacroDefinition forCompilerPlugin(Kind kind, CompilerPlugin *plugin) {
67-
return MacroDefinition{kind, ImplementationKind::Plugin, plugin};
57+
static MacroDefinition forInProcess(Kind kind, void *opaqueHandle) {
58+
return MacroDefinition{kind, ImplementationKind::InProcess, opaqueHandle};
6859
}
6960

7061
bool isInvalid() const { return opaqueHandle == nullptr; }
7162

7263
explicit operator bool() const { return !isInvalid(); }
7364

74-
void *getAsBuiltin() const {
65+
void *getAsInProcess() const {
7566
switch (implKind) {
76-
case ImplementationKind::Builtin:
67+
case ImplementationKind::InProcess:
7768
return opaqueHandle;
78-
79-
case ImplementationKind::Plugin:
80-
return nullptr;
81-
}
82-
}
83-
84-
CompilerPlugin *getAsCompilerPlugin() const {
85-
switch (implKind) {
86-
case ImplementationKind::Builtin:
87-
return nullptr;
88-
89-
case ImplementationKind::Plugin:
90-
return (CompilerPlugin *)opaqueHandle;
9169
}
9270
}
9371
};

lib/AST/ASTContext.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "ForeignRepresentationInfo.h"
2020
#include "SubstitutionMapStorage.h"
2121
#include "swift/AST/ClangModuleLoader.h"
22-
#include "swift/AST/CompilerPlugin.h"
2322
#include "swift/AST/ConcreteDeclRef.h"
2423
#include "swift/AST/DiagnosticEngine.h"
2524
#include "swift/AST/DiagnosticsFrontend.h"
@@ -1125,9 +1124,6 @@ ProtocolDecl *ASTContext::getProtocol(KnownProtocolKind kind) const {
11251124
case KnownProtocolKind::UnsafeCxxRandomAccessIterator:
11261125
M = getLoadedModule(Id_Cxx);
11271126
break;
1128-
case KnownProtocolKind::CompilerPlugin:
1129-
M = getLoadedModule(Id_CompilerPluginSupport);
1130-
break;
11311127
default:
11321128
M = getStdlibModule();
11331129
break;

0 commit comments

Comments
 (0)