Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions include/swift/AST/DefineDiagnosticMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#ifdef DEFINE_DIAGNOSTIC_MACROS

#if !(defined(DIAG) || (defined(GROUPED_ERROR) && defined(GROUPED_WARNING) && \
defined(NOTE) && defined(REMARK)))
#error Must define either DIAG or the set {GROUPED_ERROR,GROUPED_WARNING,NOTE,REMARK}
defined(NOTE) && defined(GROUPED_REMARK)))
#error Must define either DIAG or the set {GROUPED_ERROR,GROUPED_WARNING,NOTE,GROUPED_REMARK}
#endif

#ifndef GROUPED_ERROR
Expand Down Expand Up @@ -47,9 +47,14 @@
DIAG(NOTE, ID, no_group, Options, Text, Signature)
#endif

#ifndef GROUPED_REMARK
#define GROUPED_REMARK(ID, Group, Options, Text, Signature) \
DIAG(REMARK, ID, Group, Options, Text, Signature)
#endif

#ifndef REMARK
#define REMARK(ID, Options, Text, Signature) \
DIAG(REMARK, ID, no_group, Options, Text, Signature)
GROUPED_REMARK(ID, no_group, Options, Text, Signature)
#endif

#ifndef FIXIT
Expand All @@ -69,6 +74,7 @@
#endif

#undef REMARK
#undef GROUPED_REMARK
#undef NOTE
#undef WARNING
#undef GROUPED_WARNING
Expand Down
37 changes: 36 additions & 1 deletion include/swift/AST/DiagnosticEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "swift/Localization/LocalizationFormat.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Support/Allocator.h"
Expand All @@ -53,6 +54,7 @@ namespace swift {
class SourceFile;
class ParamDecl;
class AnyPattern;
class DiagnosticOptions;

/// Enumeration describing all of possible diagnostics.
///
Expand Down Expand Up @@ -639,6 +641,9 @@ namespace swift {
/// values of this map to Swift clients.
WarningGroupBehaviorMap warningGroupBehaviorMap;

/// Groups with remarks enabled. All remarks are disabled by default.
llvm::SmallSet<swift::DiagGroupID, 4> enabledRemarkGroups;

/// For compiler-internal purposes only, track which diagnostics should
/// be ignored completely. For example, this is used by LLDB to
/// suppress certain errors in expression evaluation.
Expand Down Expand Up @@ -721,6 +726,17 @@ namespace swift {
return ruleRefArray;
}

void enableRemarkGroup(DiagGroupID Group) {
if (!enabledRemarkGroups.insert(Group).second)
return;
for (auto SubGroup : getDiagGroupInfoByID(Group).subgroups)
enableRemarkGroup(SubGroup);
}

bool isRemarkGroupEnabled(DiagGroupID Group) const {
return enabledRemarkGroups.contains(Group);
}

void resetHadAnyError() {
anyErrorOccurred = false;
fatalErrorOccurred = false;
Expand All @@ -742,6 +758,7 @@ namespace swift {
std::swap(suppressNotes, other.suppressNotes);
std::swap(suppressRemarks, other.suppressRemarks);
std::swap(warningGroupBehaviorMap, other.warningGroupBehaviorMap);
std::swap(enabledRemarkGroups, other.enabledRemarkGroups);
std::swap(fatalErrorOccurred, other.fatalErrorOccurred);
std::swap(anyErrorOccurred, other.anyErrorOccurred);
std::swap(previousBehavior, other.previousBehavior);
Expand Down Expand Up @@ -987,6 +1004,14 @@ namespace swift {
return state.getWarningGroupBehaviorControlRefArray();
}

void enableRemarkGroup(DiagGroupID Group) {
state.enableRemarkGroup(Group);
}

bool isRemarkGroupEnabled(DiagGroupID Group) const {
return state.isRemarkGroupEnabled(Group);
}

/// Whether to print diagnostic names after their messages
void setPrintDiagnosticNamesMode(PrintDiagnosticNamesMode val) {
printDiagnosticNamesMode = val;
Expand Down Expand Up @@ -1282,7 +1307,17 @@ namespace swift {
void forwardTentativeDiagnosticsTo(DiagnosticEngine &targetEngine);

public:
DiagnosticKind declaredDiagnosticKindFor(const DiagID id);
static DiagnosticKind declaredDiagnosticKindFor(const DiagID id);

/// Returns diagnostic documentation path, using the user-provided path if
/// explicitly set, or falling back to the docs.swift.org URL.
static std::string
resolveDiagnosticDocumentationPath(const DiagnosticOptions &opts);

/// Returns the local diagnostic documentation path derived from the
/// compiler's executable path.
static std::string
resolveLocalDiagnosticDocumentationPath(llvm::StringRef mainExecutablePath);

/// Get a localized format string for the given `DiagID`. If no localization
/// is available, returns the default string.
Expand Down
28 changes: 21 additions & 7 deletions include/swift/AST/DiagnosticGroups.def
Original file line number Diff line number Diff line change
Expand Up @@ -40,61 +40,73 @@

GROUP(no_group,none,"")

GROUP(AccessNote,ToolchainLocalDocumentation,"access-note")
GROUP(ActorIsolatedCall,none,"actor-isolated-call")
GROUP(ActorIsolatedMutatingAsync,none,"actor-isolated-mutating-async")
GROUP(AlwaysAvailableDomain,none,"always-available-domain")
GROUP(AvailabilityUnrecognizedName,none,"availability-unrecognized-name")
GROUP(ClangDeclarationImport,none,"clang-declaration-import")
GROUP(CompilationCaching,none,"compilation-caching")
GROUP(ConformanceIsolation,none,"conformance-isolation")
GROUP(ForeignReferenceType,none,"foreign-reference-type")
GROUP(CrossImport,ToolchainLocalDocumentation,"cross-import")
GROUP(DependencyScan,ToolchainLocalDocumentation | FrontendOnly,"dependency-scan")
GROUP(DependencyScanCache,ToolchainLocalDocumentation | FrontendOnly,"dependency-scan-cache")
GROUP(DeprecatedDeclaration,none,"deprecated-declaration")
GROUP(DynamicExclusivity,DefaultIgnoreWarnings,"dynamic-exclusivity")
GROUP(DynamicCallable,none,"dynamic-callable-requirements")
GROUP(DynamicExclusivity,DefaultIgnoreWarnings,"dynamic-exclusivity")
GROUP(EmbeddedRestrictions,DefaultIgnoreWarnings,"embedded-restrictions")
GROUP(ErrorInFutureSwiftVersion,none,"error-in-future-swift-version")
GROUP(ExclusivityViolation,none,"exclusivity-violation")
GROUP(ExistentialAny,none,"existential-any")
GROUP(ExistentialMemberAccess,none,"existential-member-access-limitations")
GROUP(ExistentialType,ToolchainLocalDocumentation,"existential-type")
GROUP(ExplicitSendable,DefaultIgnoreWarnings,"explicit-sendable-annotations")
GROUP(ForeignReferenceType,none,"foreign-reference-type")
GROUP(ImplementationOnlyDeprecated,none,"implementation-only-deprecated")
GROUP(ImplicitStrongCapture,none,"implicit-strong-capture")
GROUP(IndexingSystemModule,ToolchainLocalDocumentation,"indexing-system-module")
GROUP(IsolatedConformances,none,"isolated-conformances")
GROUP(MacroExpansions,ToolchainLocalDocumentation | FrontendOnly,"macro-expansions")
GROUP(MacroLoading,ToolchainLocalDocumentation,"macro-loading")
GROUP(MemberImportVisibility,none,"member-import-visibility")
GROUP(MissingModuleOnKnownPaths,none,"missing-module-on-known-paths")
GROUP(OptionObsoletedByModuleSelectors,none,"option-obsoleted-by-module-selectors")
GROUP(ModularizationIssue,ToolchainLocalDocumentation,"modularization-issue")
GROUP(ModuleAPIImport,ToolchainLocalDocumentation,"module-api-import")
GROUP(ModuleInterfaceRebuild,ToolchainLocalDocumentation | FrontendOnly,"module-interface-rebuild")
GROUP(ModuleLoading,ToolchainLocalDocumentation,"module-loading")
GROUP(ModuleNotTestable,none,"module-not-testable")
GROUP(ModuleSerialization,ToolchainLocalDocumentation,"module-serialization")
GROUP(ModuleVersionMissing,none,"module-version-missing")
GROUP(MultipleInheritance,none,"multiple-inheritance")
GROUP(MutableGlobalVariable,none,"mutable-global-variable")
GROUP(NominalTypes,none,"nominal-types")
GROUP(NonisolatedNonsendingByDefault,none,"nonisolated-nonsending-by-default")
GROUP(OpaqueTypeInference,none,"opaque-type-inference")
GROUP(OldSuppressedAssociatedTypes,none,"old-suppressed-associatedtypes")
GROUP(OSLog,none,"oslog")
GROUP(OpaqueTypeInference,none,"opaque-type-inference")
GROUP(OptionObsoletedByModuleSelectors,none,"option-obsoleted-by-module-selectors")
GROUP(PerformanceHints,DefaultIgnoreWarnings,"performance-hints")
GROUP(PreconcurrencyImport,DefaultIgnoreWarnings,"preconcurrency-import")
GROUP(PropertyWrappers,none,"property-wrapper-requirements")
GROUP(ProtocolTypeNonConformance,none,"protocol-type-non-conformance")
GROUP(RegionIsolation,none,"region-isolation")
GROUP(ResultBuilderMethods,none,"result-builder-methods")
GROUP(ReturnTypeImplicitCopy,ToolchainLocalDocumentation,"return-type-implicit-copy")
GROUP(SemanticCopies,DefaultIgnoreWarnings,"semantic-copies")
GROUP(SendableClosureCaptures,none,"sendable-closure-captures")
GROUP(SendableMetatypes,none,"sendable-metatypes")
GROUP(SemanticCopies,DefaultIgnoreWarnings,"semantic-copies")
GROUP(SendingClosureRisksDataRace,none,"sending-closure-risks-data-race")
GROUP(SendingRisksDataRace,none,"sending-risks-data-race")
GROUP(StrictLanguageFeatures,none,"strict-language-features")
GROUP(UnrecognizedStrictLanguageFeatures,DefaultIgnoreWarnings,"strict-language-features")
GROUP(StrictMemorySafety,none,"strict-memory-safety")
GROUP(StringInterpolationConformance,none,"string-interpolation-conformance")
GROUP(TemporaryPointers,none,"temporary-pointers")
GROUP(TrailingClosureMatching,none,"trailing-closure-matching")
GROUP(UnknownWarningGroup,none,"unknown-warning-group")
GROUP(UnrecognizedStrictLanguageFeatures,DefaultIgnoreWarnings,"strict-language-features")
GROUP(UntypedThrows,DefaultIgnoreWarnings,"untyped-throws")
GROUP(UseAnyAppleOSAvailability,DefaultIgnoreWarnings,"use-any-apple-os-availability")
GROUP(WeakMutability,none,"weak-mutability")
GROUP(OldSuppressedAssociatedTypes,none,"old-suppressed-associatedtypes")

GROUP_LINK(PerformanceHints,ExistentialType)
GROUP_LINK(PerformanceHints,ReturnTypeImplicitCopy)
Expand All @@ -105,5 +117,7 @@ GROUP_LINK(RegionIsolation,SendingRisksDataRace)

GROUP_LINK(StrictLanguageFeatures, UnrecognizedStrictLanguageFeatures)

GROUP_LINK(DependencyScan,DependencyScanCache)

#define UNDEFINE_DIAGNOSTIC_GROUPS_MACROS
#include "swift/AST/DefineDiagnosticGroupsMacros.h"
29 changes: 25 additions & 4 deletions include/swift/AST/DiagnosticGroups.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "llvm/ADT/ArrayRef.h"
#include <array>
#include <string_view>
#include <unordered_map>

namespace swift {
enum class DiagnosticGroupOptions {
Expand All @@ -36,6 +35,9 @@ enum class DiagnosticGroupOptions {
/// The documentation file for this diagnostic group is distributed in the toolchain
/// directly.
ToolchainLocalDocumentation = 1 << 1,

/// This diagnostic group is not accessible through the compiler driver.
FrontendOnly = 1 << 2,
};

enum class DiagID : uint32_t;
Expand All @@ -61,18 +63,21 @@ struct DiagGroupInfo {
llvm::ArrayRef<DiagID> diagnostics;
bool defaultIgnoreWarnings : 1;
bool toolchainLocalDocumentation : 1;
bool frontendOnly : 1;

constexpr DiagGroupInfo(DiagGroupID groupID, std::string_view name,
std::string_view documentationFile,
llvm::ArrayRef<DiagGroupID> supergroups,
llvm::ArrayRef<DiagGroupID> subgroups,
llvm::ArrayRef<DiagID> diagnostics,
bool defaultIgnoreWarnings,
bool toolchainLocalDocumentation)
bool toolchainLocalDocumentation,
bool frontendOnly)
: id(groupID), name(name), documentationFile(documentationFile),
supergroups(supergroups), subgroups(subgroups), diagnostics(diagnostics),
defaultIgnoreWarnings(defaultIgnoreWarnings),
toolchainLocalDocumentation(toolchainLocalDocumentation) {}
toolchainLocalDocumentation(toolchainLocalDocumentation),
frontendOnly(frontendOnly) {}

constexpr DiagGroupInfo(DiagGroupID groupID, std::string_view name,
OptionSet<DiagnosticGroupOptions> options,
Expand All @@ -83,20 +88,36 @@ struct DiagGroupInfo {
: DiagGroupInfo(groupID, name, documentationFile, supergroups,
subgroups, diagnostics,
options.contains(DiagnosticGroupOptions::DefaultIgnoreWarnings),
options.contains(DiagnosticGroupOptions::ToolchainLocalDocumentation)) {}
options.contains(DiagnosticGroupOptions::ToolchainLocalDocumentation),
options.contains(DiagnosticGroupOptions::FrontendOnly)) {}

void traverseDepthFirst(
llvm::function_ref<void(const DiagGroupInfo &)> func) const;

/// Returns the documentation URL for a diagnostic group, using the local
/// toolchain path for toolchain-local groups or the remote URL otherwise.
std::string getDocumentationURL(llvm::StringRef docsPath,
llvm::StringRef localDocsPath) const;

/// Returns true if this group contains GROUPED_REMARK diagnostics. Does NOT
/// consider subgroups (see hasTransitiveRemarks).
bool hasDirectRemarks() const;

/// Returns true if this group or any of its subgroups contain GROUPED_REMARK
/// diagnostics.
bool hasTransitiveRemarks() const;
};

// Add OptionSet aliases so that the '|' operator in the `DiagnosticGroups.def`
// file does the right thing.
static constexpr OptionSet<DiagnosticGroupOptions> none = DiagnosticGroupOptions::none;
static constexpr OptionSet<DiagnosticGroupOptions> DefaultIgnoreWarnings = DiagnosticGroupOptions::DefaultIgnoreWarnings;
static constexpr OptionSet<DiagnosticGroupOptions> ToolchainLocalDocumentation = DiagnosticGroupOptions::ToolchainLocalDocumentation;
static constexpr OptionSet<DiagnosticGroupOptions> FrontendOnly = DiagnosticGroupOptions::FrontendOnly;
extern const std::array<DiagGroupInfo, DiagGroupsCount> diagnosticGroupsInfo;
const DiagGroupInfo &getDiagGroupInfoByID(DiagGroupID id);
std::optional<DiagGroupID> getDiagGroupIDByName(std::string_view name);
std::optional<llvm::StringRef> getCustomRemarkOptionForGroup(DiagGroupID id);

} // end namespace swift

Expand Down
19 changes: 8 additions & 11 deletions include/swift/AST/DiagnosticsCommon.def
Original file line number Diff line number Diff line change
Expand Up @@ -222,33 +222,30 @@ NOTE(scanner_cycle_source_target_shadow_module, none,
ERROR(error_scanner_extra, none,
"failed inside dependency scanner: '%0'", (StringRef))

REMARK(warn_scanner_deserialize_failed, none,
GROUPED_REMARK(warn_scanner_deserialize_failed, DependencyScanCache, none,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be possible to have an un-grouped remark with this change? i.e. should all remarks just be REMARK and require a group?

"Incremental module scan: Failed to load module scanning dependency cache from: '%0', re-building scanner cache from scratch.", (StringRef))

REMARK(remark_reuse_cache, none,
GROUPED_REMARK(remark_reuse_cache, DependencyScanCache, none,
"Incremental module scan: Re-using serialized module scanning dependency cache from: '%0'.", (StringRef))

REMARK(remark_scanner_uncached_lookups, none,
"Module Dependency Scanner queries executed: '%0'.", (unsigned))

REMARK(remark_save_cache, none,
GROUPED_REMARK(remark_save_cache, DependencyScanCache, none,
"Incremental module scan: Serializing module scanning dependency cache to: '%0'.", (StringRef))

REMARK(remark_scanner_stale_result_invalidate, none,
GROUPED_REMARK(remark_scanner_stale_result_invalidate, DependencyScanCache, none,
"Incremental module scan: Dependency info for module '%0' invalidated due to a modified input"
" since last scan: '%1'.", (StringRef, StringRef))

REMARK(remark_scanner_invalidate_upstream, none,
GROUPED_REMARK(remark_scanner_invalidate_upstream, DependencyScanCache, none,
"Incremental module scan: Dependency info for module '%0' invalidated due to an out-of-date"
" dependency.", (StringRef))

REMARK(remark_scanner_invalidate_configuration, none,
GROUPED_REMARK(remark_scanner_invalidate_configuration, DependencyScanCache, none,
"Incremental module scan: Dependency info for module '%0' invalidated due to wrong configuration.", (StringRef))

REMARK(remark_scanner_invalidate_cas_error, none,
GROUPED_REMARK(remark_scanner_invalidate_cas_error, DependencyScanCache, none,
"Incremental module scan: Dependency info for module '%0' invalidated due to cas error: %1", (StringRef, StringRef))

REMARK(remark_scanner_invalidate_missing_cas, none,
GROUPED_REMARK(remark_scanner_invalidate_missing_cas, DependencyScanCache, none,
"Incremental module scan: Dependency info for module '%0' invalidated due to missing CAS input '%1'.", (StringRef, StringRef))

//------------------------------------------------------------------------------
Expand Down
20 changes: 14 additions & 6 deletions include/swift/AST/DiagnosticsFrontend.def
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ ERROR(error_index_failed_status_check,none,
"failed file status check: %0", (StringRef))
ERROR(error_index_inputs_more_than_outputs,none,
"index output filenames do not match input source files", ())
REMARK(remark_indexing_system_module,none,
GROUPED_REMARK(remark_indexing_system_module,IndexingSystemModule,none,
"indexing system module at %0"
"%select{|; skipping because of a broken swiftinterface}1",
(StringRef, bool))
Expand Down Expand Up @@ -434,7 +434,7 @@ WARNING(warning_module_shadowing_may_break_module_interface,none,
"https://github.com/apple/swift/issues/56573 for workarounds",
(DescriptiveDeclKind, FullyQualified<Type>,
/*shadowedModule=*/ModuleDecl *, /*interfaceModule*/ModuleDecl *))
REMARK(rebuilding_module_from_interface,none,
GROUPED_REMARK(rebuilding_module_from_interface,ModuleInterfaceRebuild,none,
"rebuilding module '%0' from interface '%1'", (StringRef, StringRef))
NOTE(sdk_version_pbm_version,none,
"SDK build version is '%0'; prebuilt modules were "
Expand Down Expand Up @@ -478,10 +478,10 @@ ERROR(error_creating_remark_serializer,none,
ERROR(invalid_can_import_module_version,none,
"invalid version passed to -module-can-import-version: '%0'", (StringRef))

REMARK(interface_file_lock_failure,none,
GROUPED_REMARK(interface_file_lock_failure,ModuleInterfaceRebuild,none,
"building module interface without lock file", ())

REMARK(interface_file_lock_timed_out,none,
GROUPED_REMARK(interface_file_lock_timed_out,ModuleInterfaceRebuild,none,
"timed out waiting to acquire lock file for module interface '%0'", (StringRef))

ERROR(error_option_required,none, "option '%0' is required", (StringRef))
Expand Down Expand Up @@ -510,8 +510,8 @@ GROUPED_ERROR(error_caching_no_cas_fs, CompilationCaching, none,
GROUPED_ERROR(error_option_incompatible, CompilationCaching, none,
"'%0' is incompatible with '%1'", (StringRef, StringRef))

REMARK(replay_output, none, "replay output file '%0': key '%1'", (StringRef, StringRef))
REMARK(output_cache_miss, none, "cache miss for input file '%0': key '%1'", (StringRef, StringRef))
GROUPED_REMARK(replay_output, CompilationCaching, none, "replay output file '%0': key '%1'", (StringRef, StringRef))
GROUPED_REMARK(output_cache_miss, CompilationCaching, none, "cache miss for input file '%0': key '%1'", (StringRef, StringRef))

// CAS related diagnostics
GROUPED_ERROR(error_invalid_cas_id, CompilationCaching, none, "CAS cannot parse id '%0': %1", (StringRef, StringRef))
Expand Down Expand Up @@ -638,5 +638,13 @@ NOTE(dependency_scan_unexpected_variant_extra_arg_note, none,
ERROR(bridging_header_and_pch_internal_mismatch,none,
"bridging header and precompiled header options mismatch on internal vs. public import", ())

ERROR(error_remark_group_not_found,none,
"no diagnostic group found with name '%0'", (StringRef))
ERROR(error_remarkless_group,none,
"diagnostic group '%0' contains no remark diagnostics", (StringRef))
ERROR(error_remark_option_redirect,none,
"diagnostic group '%0' cannot be enabled with '-R %0' since it requires "
"an additional argument; use '%1' instead", (StringRef, StringRef))

#define UNDEFINE_DIAGNOSTIC_MACROS
#include "DefineDiagnosticMacros.h"
Loading