Skip to content

Commit 577727a

Browse files
committed
Remove DiagnosticsEditorMode
Migrate the last diagnostic to be independent of `DiagnosticEditorMode` and remove that option. rdar://133111163
1 parent 915b531 commit 577727a

27 files changed

+55
-154
lines changed

docs/Diagnostics.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,6 @@ The correct spelling of this feature is "fix-it" rather than "fixit". In [camelc
8484

8585
[camelcased]: https://en.wikipedia.org/wiki/Camel_case
8686

87-
88-
### "Editor Mode" ###
89-
90-
The Swift compiler has a setting (under LangOptions) called `DiagnosticsEditorMode`. When set, diagnostics should be customized for an interactive editor that can display and apply complex fix-its, and worry less about the appearance in build logs and command-line environments.
91-
92-
Most diagnostics have no reason to change behavior under editor mode. An example of an exception is the "protocol requirements not satisfied diagnostic"; on the command line, it may be better to show all unsatisfied requirements, while in an IDE a single multi-line fix-it would be preferred.
93-
9487
### Educational Notes ###
9588

9689
Educational notes are short-form documentation attached to a diagnostic which explain relevant language concepts. They are intended to further Swift's goal of progressive disclosure by providing a learning resource at the point of use when encountering an error message for the first time. In very limited circumstances, they also allow the main diagnostic message to use precise terminology (e.g. nominal types) which would otherwise be too unfriendly for beginners.

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2813,11 +2813,10 @@ ERROR(conditional_conformances_cannot_imply_conformances,none,
28132813
NOTE(note_explicitly_state_conditional_conformance_different,none,
28142814
"did you mean to explicitly state the conformance with different bounds?", ())
28152815
NOTE(note_explicitly_state_conditional_conformance_relaxed,none,
2816-
"did you mean to explicitly state the conformance with relaxed bounds?", ())
2816+
"did you mean to explicitly state the conformance with relaxed bounds using '%0'?",
2817+
(StringRef))
28172818
NOTE(note_explicitly_state_conditional_conformance_same,none,
2818-
"did you mean to explicitly state the conformance with the same bounds?", ())
2819-
NOTE(note_explicitly_state_conditional_conformance_noneditor,none,
2820-
"did you mean to explicitly state the conformance like '%0where ...'?",
2819+
"did you mean to explicitly state the conformance with the same bounds using '%0'?",
28212820
(StringRef))
28222821
ERROR(protocol_has_missing_requirements,none,
28232822
"type %0 cannot conform to protocol %1 because it has requirements that "

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,6 @@ namespace swift {
458458
/// [TODO: Clang-type-plumbing] Turn on for feature rollout.
459459
bool UseClangFunctionTypes = false;
460460

461-
/// If set to true, the diagnosis engine can assume the emitted diagnostics
462-
/// will be used in editor. This usually leads to more aggressive fixit.
463-
bool DiagnosticsEditorMode = false;
464-
465461
/// Access or distribution level of the whole module being parsed.
466462
LibraryLevel LibraryLevel = LibraryLevel::Other;
467463

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -779,9 +779,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
779779

780780
Opts.UseMalloc |= Args.hasArg(OPT_use_malloc);
781781

782-
Opts.DiagnosticsEditorMode |= Args.hasArg(OPT_diagnostics_editor_mode,
783-
OPT_serialize_diagnostics_path);
784-
785782
Opts.EnableExperimentalConcurrency |=
786783
Args.hasArg(OPT_enable_experimental_concurrency);
787784

lib/IDETool/CompilerInvocation.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ bool ide::initCompilerInvocation(
223223

224224
auto &LangOpts = Invocation.getLangOptions();
225225
LangOpts.AttachCommentsToDecls = true;
226-
LangOpts.DiagnosticsEditorMode = true;
227226
LangOpts.CollectParsedToken = true;
228227
#if defined(_WIN32)
229228
// Source files that might be open in an editor should not be memory mapped on Windows,

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,21 +2173,11 @@ static void diagnoseConformanceImpliedByConditionalConformance(
21732173
<< indent;
21742174
}
21752175

2176-
if (!ctxt.LangOpts.DiagnosticsEditorMode) {
2177-
// The fixits below are too complicated for the command line: the suggested
2178-
// code ends up not being displayed, and the text by itself doesn't help. So
2179-
// instead we skip all that and just have some text.
2180-
Diags.diagnose(loc,
2181-
diag::note_explicitly_state_conditional_conformance_noneditor,
2182-
prefix.str());
2183-
return;
2184-
}
2185-
21862176
// First, we do the fixit for "matching" requirements (i.e. X: P where T: P).
21872177
bool matchingIsValid = true;
2188-
llvm::SmallString<128> matchingFixit = prefix;
2178+
llvm::SmallString<128> matchingWhereClause;
21892179
{
2190-
llvm::raw_svector_ostream matchingStream(matchingFixit);
2180+
llvm::raw_svector_ostream matchingStream(matchingWhereClause);
21912181
matchingStream << "where ";
21922182
bool first = true;
21932183
for (const auto &req : implyingConf->getConditionalRequirements()) {
@@ -2207,35 +2197,30 @@ static void diagnoseConformanceImpliedByConditionalConformance(
22072197
}
22082198

22092199
if (matchingIsValid) {
2210-
matchingFixit += suffix;
22112200
Diags
22122201
.diagnose(loc,
2213-
diag::note_explicitly_state_conditional_conformance_relaxed)
2214-
.fixItInsert(loc, matchingFixit);
2202+
diag::note_explicitly_state_conditional_conformance_relaxed, matchingWhereClause)
2203+
.fixItInsert(loc, (prefix + matchingWhereClause + suffix).str());
22152204
}
22162205

22172206
// Next, do the fixit for using the same requirements, but be resilient to a
22182207
// missing `where` clause: this is one of a few fixits that get emitted here,
22192208
// and so is a very low priority diagnostic, and so shouldn't crash.
22202209
if (auto TWC = ext->getTrailingWhereClause()) {
2221-
llvm::SmallString<128> sameFixit = prefix;
2210+
llvm::SmallString<128> sameWhereClause;
22222211
auto CSR =
22232212
Lexer::getCharSourceRangeFromSourceRange(SM, TWC->getSourceRange());
2224-
sameFixit += SM.extractText(CSR);
2225-
sameFixit += suffix;
2213+
sameWhereClause += SM.extractText(CSR);
22262214
Diags
2227-
.diagnose(loc, diag::note_explicitly_state_conditional_conformance_same)
2228-
.fixItInsert(loc, sameFixit);
2215+
.diagnose(loc, diag::note_explicitly_state_conditional_conformance_same, sameWhereClause)
2216+
.fixItInsert(loc, (prefix + sameWhereClause + suffix).str());
22292217
}
22302218

22312219
// And finally, just the generic new-requirements one:
2232-
llvm::SmallString<128> differentFixit = prefix;
2233-
differentFixit += "where <#requirements#>";
2234-
differentFixit += suffix;
22352220
Diags
22362221
.diagnose(loc,
22372222
diag::note_explicitly_state_conditional_conformance_different)
2238-
.fixItInsert(loc, differentFixit);
2223+
.fixItInsert(loc, (prefix + "where <#requirements#>" + suffix).str());
22392224
}
22402225

22412226
/// Determine whether there are additional semantic checks for conformance

test/AssociatedTypeInference/associated_type_inference_proto_ext.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ extension Pair: Codable where A: Codable, B: Codable {}
1111

1212
extension Pair: Collection where A == B {
1313
// expected-error@-1 {{conditional conformance of type 'Pair<A, B>' to protocol 'Collection' does not imply conformance to inherited protocol 'Sequence'}}
14-
// expected-note@-2 {{did you mean to explicitly state the conformance like 'extension Pair: Sequence where ...'?}}
14+
// expected-note@-2 {{did you mean to explicitly state the conformance with the same bounds using 'where A == B'?}}
15+
// expected-note@-3 {{did you mean to explicitly state the conformance with different bounds?}}
1516
typealias Element = A
1617

1718
var startIndex: Int { return 0 }

test/AssociatedTypeInference/missing_conformance.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,9 @@ struct CountSteps1<T> : Collection {
148148
extension CountSteps1 // expected-error {{type 'CountSteps1<T>' does not conform to protocol 'RandomAccessCollection'}}
149149
// expected-note@-1 {{add stubs for conformance}}
150150
// expected-error@-2 {{conditional conformance of type 'CountSteps1<T>' to protocol 'RandomAccessCollection' does not imply conformance to inherited protocol 'BidirectionalCollection'}}
151-
// expected-note@-3 {{did you mean to explicitly state the conformance like 'extension CountSteps1: BidirectionalCollection where ...'?}}
152-
// expected-error@-4 {{type 'CountSteps1<T>' does not conform to protocol 'BidirectionalCollection'}}
151+
// expected-note@-3 {{did you mean to explicitly state the conformance with the same bounds using 'where T : Equatable'?}}
152+
// expected-note@-4 {{did you mean to explicitly state the conformance with different bounds?}}
153+
// expected-error@-5 {{type 'CountSteps1<T>' does not conform to protocol 'BidirectionalCollection'}}
153154
: RandomAccessCollection
154155
where T : Equatable
155156
{

test/Concurrency/implied_sendable_conformance_swift6.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@ struct One<T> { // expected-note {{consider making generic parameter 'T' confor
99

1010
extension One: P where T: P {}
1111
// expected-error@-1 {{conditional conformance of type 'One<T>' to protocol 'P' does not imply conformance to inherited protocol 'Sendable'}}
12-
// expected-note@-2 {{did you mean to explicitly state the conformance like 'extension One: Sendable where ...'}}
12+
// expected-note@-2 {{did you mean to explicitly state the conformance with relaxed bounds using 'where T: Sendable'?}}
13+
// expected-note@-3 {{did you mean to explicitly state the conformance with the same bounds using 'where T: P'?}}
14+
// expected-note@-4 {{did you mean to explicitly state the conformance with different bounds?}}
1315

1416
struct Both<T> { // expected-note {{consider making generic parameter 'T' conform to the 'Sendable' protocol}}
1517
var t: T // expected-error {{stored property 't' of 'Sendable'-conforming generic struct 'Both' has non-sendable type 'T'}}
1618
}
1719

1820
extension Both: P where T: P {}
1921
// expected-error@-1 {{conditional conformance of type 'Both<T>' to protocol 'P' does not imply conformance to inherited protocol 'Sendable'}}
20-
// expected-note@-2 {{did you mean to explicitly state the conformance like 'extension Both: Sendable where ...'}}
22+
// expected-note@-2 {{did you mean to explicitly state the conformance with relaxed bounds using 'where T: Sendable'?}}
23+
// expected-note@-3 {{did you mean to explicitly state the conformance with the same bounds using 'where T: P'?}}
24+
// expected-note@-4 {{did you mean to explicitly state the conformance with different bounds?}}
2125

2226
extension Both: Q where T: Q {}
2327

test/FixCode/batch-mode.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not %swift -typecheck -target %target-triple -primary-file %s -emit-fixits-path %t.main.remap -primary-file %S/Inputs/batch-mode-helper.swift -emit-fixits-path %t.helper.remap -diagnostics-editor-mode
1+
// RUN: not %swift -typecheck -target %target-triple -primary-file %s -emit-fixits-path %t.main.remap -primary-file %S/Inputs/batch-mode-helper.swift -emit-fixits-path %t.helper.remap
22
// RUN: %FileCheck -check-prefix=CHECK-MAIN %s < %t.main.remap
33
// RUN: %FileCheck -check-prefix=NEGATIVE-MAIN %s < %t.main.remap
44
// RUN: %FileCheck -check-prefix=CHECK-HELPER %s < %t.helper.remap

0 commit comments

Comments
 (0)