Skip to content
Merged
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
16 changes: 9 additions & 7 deletions include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,12 @@
#include "swift/AST/Identifier.h"
#include "swift/AST/Import.h"
#include "swift/AST/ProtocolConformanceOptions.h"
#include "swift/AST/SILOptions.h"
#include "swift/AST/SearchPathOptions.h"
#include "swift/AST/Type.h"
#include "swift/AST/TypeAlignments.h"
#include "swift/AST/Types.h"
#include "swift/Basic/BlockList.h"
#include "swift/Basic/CASOptions.h"
#include "swift/Basic/LangOptions.h"
#include "swift/Basic/Located.h"
#include "swift/Basic/Malloc.h"
#include "swift/Serialization/SerializationOptions.h"
#include "swift/SymbolGraphGen/SymbolGraphOptions.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/Basic/DarwinSDKInfo.h"
#include "llvm/ADT/ArrayRef.h"
Expand Down Expand Up @@ -77,6 +71,7 @@ namespace swift {
class AvailabilityRange;
class BoundGenericType;
class BuiltinTupleDecl;
class CASOptions;
class ClangModuleLoader;
class ClangNode;
class ClangTypeConverter;
Expand All @@ -100,20 +95,22 @@ namespace swift {
class LazyContextData;
class LazyIterableDeclContextData;
class LazyMemberLoader;
class LangOptions;
struct MacroDiscriminatorContext;
class ModuleInterfaceChecker;
class PatternBindingDecl;
class PatternBindingInitializer;
class PluginLoader;
class SourceFile;
class SourceLoc;
class SerializationOptions;
class SILOptions;
struct TemplateInstantiationError;
class Type;
class TypeVariableType;
class TupleType;
class FunctionType;
class ArchetypeType;
class Identifier;
class InheritedNameSet;
class ModuleDecl;
class PackageUnit;
Expand Down Expand Up @@ -142,6 +139,7 @@ namespace swift {
class DiagnosticEngine;
struct RawComment;
class DocComment;
class SearchPathOptions;
class SILBoxType;
class SILTransform;
class TypeAliasDecl;
Expand All @@ -165,6 +163,10 @@ namespace ide {
class TypeCheckCompletionCallback;
}

namespace symbolgraphgen {
struct SymbolGraphOptions;
}

/// Lists the set of "known" Foundation entities that are used in the
/// compiler.
///
Expand Down
4 changes: 4 additions & 0 deletions include/swift/AST/PlatformKindUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ PlatformKind targetPlatform(const LangOptions &LangOpts);
/// Returns the target variant platform for the given language options.
PlatformKind targetVariantPlatform(const LangOptions &LangOpts);

/// Returns the target platform for the given triple and options.
PlatformKind platformForTriple(const llvm::Triple &triple,
bool enableAppExtensionRestrictions);

/// Returns true when availability attributes from the "parent" platform
/// should also apply to the "child" platform for declarations without
/// an explicit attribute for the child.
Expand Down
6 changes: 6 additions & 0 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,12 @@ def block_availability_platforms: Separate<["-"], "block-availability-platforms"
HelpText<"Remove the given platforms from symbol graph availability metadata, e.g. 'macOS,Swift'">,
MetaVarName<"<platforms>">;

def active_platform_availability_only
: Flag<["-"], "active-platform-availability-only">,
Flags<[SwiftSymbolGraphExtractOption]>,
HelpText<"Only emit availability metadata for platforms that are active "
"according to the target">;

// swift-synthesize-interface-only options
def include_submodules : Flag<["-"], "include-submodules">,
Flags<[NoDriverOption, SwiftSynthesizeInterfaceOption]>,
Expand Down
4 changes: 4 additions & 0 deletions include/swift/SymbolGraphGen/SymbolGraphOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//
//===----------------------------------------------------------------------===//

#include "swift/AST/PlatformKind.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/TargetParser/Triple.h"
Expand Down Expand Up @@ -78,6 +79,9 @@ struct SymbolGraphOptions {
/// Whether `AvailabilityPlatforms` is an allow list or a block list.
bool AvailabilityIsBlockList = false;

/// If non-null, only emit availability metadata for the active platform.
std::optional<PlatformKind> ActivePlatform = std::nullopt;

/// Whether to use shortened, by using a hash of the module names, file names
/// when writing symbol graph files to `OutputDir`.
/// An additional JSON file is written at `OutputDir` that contains a mapping
Expand Down
1 change: 1 addition & 0 deletions lib/AST/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "swift/AST/PrettyStackTrace.h"
#include "swift/AST/PrintOptions.h"
#include "swift/AST/ProtocolConformance.h"
#include "swift/AST/SearchPathOptions.h"
#include "swift/AST/SourceFile.h"
#include "swift/AST/SourceFileExtras.h"
#include "swift/AST/SynthesizedFileUnit.h"
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/PlatformKindUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ bool swift::isPlatformActive(PlatformKind Platform, const LangOptions &LangOpts,
ForRuntimeQuery);
}

static PlatformKind platformForTriple(const llvm::Triple &triple,
PlatformKind swift::platformForTriple(const llvm::Triple &triple,
bool enableAppExtensionRestrictions) {
if (triple.isMacOSX()) {
return (enableAppExtensionRestrictions
Expand Down
2 changes: 2 additions & 0 deletions lib/AST/PluginLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
#include "swift/AST/ASTContext.h"
#include "swift/AST/DiagnosticEngine.h"
#include "swift/AST/DiagnosticsSema.h"
#include "swift/AST/SearchPathOptions.h"
#include "swift/Basic/Assertions.h"
#include "swift/Basic/CASOptions.h"
#include "swift/Basic/SourceManager.h"
#include "swift/Parse/Lexer.h"
#include "llvm/Config/config.h"
Expand Down
1 change: 1 addition & 0 deletions lib/ClangImporter/ClangIncludePaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "swift/AST/ASTContext.h"
#include "swift/AST/DiagnosticEngine.h"
#include "swift/AST/DiagnosticsClangImporter.h"
#include "swift/AST/SearchPathOptions.h"
#include "swift/Basic/Assertions.h"
#include "swift/Basic/Platform.h"
#include "swift/ClangImporter/ClangImporter.h"
Expand Down
5 changes: 3 additions & 2 deletions lib/ClangImporter/ClangModuleDependencyScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
#include "ImporterImpl.h"
#include "swift/AST/DiagnosticsSema.h"
#include "swift/AST/ModuleDependencies.h"
#include "swift/Basic/Assertions.h"
#include "swift/Basic/CASOptions.h"
#include "swift/Basic/SourceManager.h"
#include "swift/ClangImporter/ClangImporter.h"
#include "swift/Basic/Assertions.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/CAS/CASOptions.h"
#include "clang/Frontend/CompilerInvocation.h"
Expand All @@ -28,8 +29,8 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/StringSaver.h"

using namespace swift;
Expand Down
1 change: 1 addition & 0 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "swift/AST/Pattern.h"
#include "swift/AST/PrettyStackTrace.h"
#include "swift/AST/ProtocolConformance.h"
#include "swift/AST/SILOptions.h"
#include "swift/AST/Stmt.h"
#include "swift/AST/Type.h"
#include "swift/AST/TypeCheckRequests.h"
Expand Down
7 changes: 7 additions & 0 deletions lib/DriverTool/swift_symbolgraph_extract_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ int swift_symbolgraph_extract_main(ArrayRef<const char *> Args,
ParsedArgs.hasFlag(OPT_emit_extension_block_symbols,
OPT_omit_extension_block_symbols, /*default=*/false);
Options.AllowedReexportedModules = AllowedRexports;
if (ParsedArgs.hasArg(OPT_active_platform_availability_only)) {
// The output should only include platform availability that applies to the
// platform inferred from the -target. Include app extension availability,
// too.
Options.ActivePlatform =
platformForTriple(Target, /*enableAppExtensionRestrictions=*/true);
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.

Thanks for adding support for application extensions as well, we were tracking this as a future improvement (rdar://175796455)

Comment thread
snprajwal marked this conversation as resolved.
}

if (auto *A = ParsedArgs.getLastArg(OPT_minimum_access_level)) {
Options.MinimumAccessLevel =
Expand Down
1 change: 1 addition & 0 deletions lib/IRGen/GenType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "swift/AST/LazyResolver.h"
#include "swift/AST/IRGenOptions.h"
#include "swift/AST/PrettyStackTrace.h"
#include "swift/AST/SearchPathOptions.h"
#include "swift/AST/Types.h"
#include "swift/Basic/Assertions.h"
#include "swift/Basic/Platform.h"
Expand Down
1 change: 1 addition & 0 deletions lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "swift/AST/MacroDefinition.h"
#include "swift/AST/ParameterList.h"
#include "swift/AST/ProtocolConformance.h"
#include "swift/AST/SILOptions.h"
#include "swift/AST/TypeCheckRequests.h"
#include "swift/AST/TypeTransform.h"
#include "swift/AST/Types.h"
Expand Down
17 changes: 8 additions & 9 deletions lib/SymbolGraphGen/AvailabilityMixin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,18 @@
using namespace swift;
using namespace symbolgraphgen;

namespace {
StringRef getDomain(const SemanticAvailableAttr &AvAttr) {
StringRef Availability::getDomainDescription(AvailabilityDomain Domain) {
// FIXME: [avalailability] Move the definition of these strings into
// AvailabilityDomain so that new domains are handled automatically.

if (AvAttr.getDomain().isPackageDescription())
if (Domain.isPackageDescription())
return { "SwiftPM" };

if (AvAttr.getDomain().isSwiftLanguageMode())
if (Domain.isSwiftLanguageMode())
return { "Swift" };

// Platform-specific availability.
switch (AvAttr.getPlatform()) {
switch (Domain.getPlatformKind()) {
case swift::PlatformKind::iOS:
return { "iOS" };
case swift::PlatformKind::macCatalyst:
Expand Down Expand Up @@ -73,12 +72,12 @@ StringRef getDomain(const SemanticAvailableAttr &AvAttr) {
}
llvm_unreachable("invalid platform kind");
}
} // end anonymous namespace

Availability::Availability(const SemanticAvailableAttr &AvAttr)
: Domain(getDomain(AvAttr)), Introduced(AvAttr.getIntroduced()),
Deprecated(AvAttr.getDeprecated()), Obsoleted(AvAttr.getObsoleted()),
Message(AvAttr.getMessage()), Renamed(AvAttr.getRename()),
: Domain(getDomainDescription(AvAttr.getDomain())),
Introduced(AvAttr.getIntroduced()), Deprecated(AvAttr.getDeprecated()),
Obsoleted(AvAttr.getObsoleted()), Message(AvAttr.getMessage()),
Renamed(AvAttr.getRename()),
IsUnconditionallyDeprecated(AvAttr.isUnconditionallyDeprecated()),
IsUnconditionallyUnavailable(AvAttr.isUnconditionallyUnavailable()) {
assert(!Domain.empty());
Expand Down
2 changes: 2 additions & 0 deletions lib/SymbolGraphGen/AvailabilityMixin.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ struct Availability {
/// If \c true, is unconditionally unavailable in this \c Domain.
bool IsUnconditionallyUnavailable;

static StringRef getDomainDescription(AvailabilityDomain Domain);

Availability(const SemanticAvailableAttr &AvAttr);

/// Update this availability from a duplicate @available
Expand Down
Loading