Skip to content

Commit 72f710c

Browse files
committed
Merge #38335
1 parent a5ade00 commit 72f710c

File tree

13 files changed

+55
-10
lines changed

13 files changed

+55
-10
lines changed

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,8 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
10641064
set(SWIFT_USE_LINKER_default "")
10651065
elseif(DISTRO_NAME STREQUAL "Amazon Linux 2023")
10661066
set(SWIFT_USE_LINKER_default "lld")
1067+
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
1068+
set(SWIFT_USE_LINKER_default "lld")
10671069
else()
10681070
get_gold_version(gold_version)
10691071
if(NOT gold_version)

include/swift/AST/AutoDiff.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,14 @@ class DerivativeFunctionTypeError
422422
Kind kind;
423423

424424
/// The type and index of a differentiability parameter or result.
425-
using TypeAndIndex = std::pair<Type, unsigned>;
425+
/// std::pair does not have a trivial copy constructor on FreeBSD <= 14 for
426+
/// ABI reasons, so we have to define our own type here instead
427+
struct TypeAndIndex {
428+
Type first;
429+
unsigned second;
430+
431+
TypeAndIndex(Type type, unsigned index) : first(type), second(index) {}
432+
};
426433

427434
private:
428435
union Value {

include/swift/AST/PlatformKinds.def

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ AVAILABILITY_PLATFORM(visionOSApplicationExtension, "application extensions for
3434
AVAILABILITY_PLATFORM(macOSApplicationExtension, "application extensions for macOS")
3535
AVAILABILITY_PLATFORM(macCatalyst, "Mac Catalyst")
3636
AVAILABILITY_PLATFORM(macCatalystApplicationExtension, "application extensions for Mac Catalyst")
37+
AVAILABILITY_PLATFORM(FreeBSD, "FreeBSD")
3738
AVAILABILITY_PLATFORM(OpenBSD, "OpenBSD")
3839
AVAILABILITY_PLATFORM(Windows, "Windows")
3940

include/swift/SILOptimizer/Differentiation/DifferentiationInvoker.h

+12-4
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,17 @@ struct DifferentiationInvoker {
7171

7272
/// The parent `apply` instruction and the witness associated with the
7373
/// `IndirectDifferentiation` case.
74-
std::pair<ApplyInst *, SILDifferentiabilityWitness *>
75-
indirectDifferentiation;
74+
/// Note: This used to be a std::pair, but on FreeBSD <= 14, libc++ is
75+
/// configured with _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR
76+
/// and hence does not have a trivial copy constructor
77+
struct IndirectDifferentiation {
78+
ApplyInst *applyInst;
79+
SILDifferentiabilityWitness *witness;
80+
};
81+
IndirectDifferentiation indirectDifferentiation;
82+
7683
Value(ApplyInst *applyInst, SILDifferentiabilityWitness *witness)
77-
: indirectDifferentiation({applyInst, witness}) {}
84+
: indirectDifferentiation({applyInst, witness}) {}
7885

7986
/// The witness associated with the `SILDifferentiabilityWitnessInvoker`
8087
/// case.
@@ -111,7 +118,8 @@ struct DifferentiationInvoker {
111118
std::pair<ApplyInst *, SILDifferentiabilityWitness *>
112119
getIndirectDifferentiation() const {
113120
assert(kind == Kind::IndirectDifferentiation);
114-
return value.indirectDifferentiation;
121+
return std::make_pair(value.indirectDifferentiation.applyInst,
122+
value.indirectDifferentiation.witness);
115123
}
116124

117125
SILDifferentiabilityWitness *getSILDifferentiabilityWitnessInvoker() const {

lib/AST/PlatformKind.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ swift::basePlatformForExtensionPlatform(PlatformKind Platform) {
116116
case PlatformKind::tvOS:
117117
case PlatformKind::watchOS:
118118
case PlatformKind::visionOS:
119+
case PlatformKind::FreeBSD:
119120
case PlatformKind::OpenBSD:
120121
case PlatformKind::Windows:
121122
case PlatformKind::none:
@@ -160,6 +161,8 @@ static bool isPlatformActiveForTarget(PlatformKind Platform,
160161
return Target.isXROS();
161162
case PlatformKind::OpenBSD:
162163
return Target.isOSOpenBSD();
164+
case PlatformKind::FreeBSD:
165+
return Target.isOSFreeBSD();
163166
case PlatformKind::Windows:
164167
return Target.isOSWindows();
165168
case PlatformKind::none:
@@ -278,6 +281,7 @@ bool swift::isPlatformSPI(PlatformKind Platform) {
278281
case PlatformKind::visionOS:
279282
case PlatformKind::visionOSApplicationExtension:
280283
case PlatformKind::OpenBSD:
284+
case PlatformKind::FreeBSD:
281285
case PlatformKind::Windows:
282286
case PlatformKind::none:
283287
return false;

lib/AST/Type.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -4634,7 +4634,8 @@ AnyFunctionType::getAutoDiffDerivativeFunctionLinearMapType(
46344634
if (!resultTan)
46354635
return llvm::make_error<DerivativeFunctionTypeError>(
46364636
this, DerivativeFunctionTypeError::Kind::NonDifferentiableResult,
4637-
std::make_pair(originalResultType, unsigned(originalResult.index)));
4637+
DerivativeFunctionTypeError::TypeAndIndex(
4638+
originalResultType, unsigned(originalResult.index)));
46384639

46394640
if (!originalResult.isSemanticResultParameter)
46404641
resultTanTypes.push_back(resultTan->getType());
@@ -4664,7 +4665,7 @@ AnyFunctionType::getAutoDiffDerivativeFunctionLinearMapType(
46644665
this,
46654666
DerivativeFunctionTypeError::Kind::
46664667
NonDifferentiableDifferentiabilityParameter,
4667-
std::make_pair(paramType, i));
4668+
DerivativeFunctionTypeError::TypeAndIndex(paramType, i));
46684669

46694670
differentialParams.push_back(AnyFunctionType::Param(
46704671
paramTan->getType(), Identifier(), diffParam.getParameterFlags()));
@@ -4712,7 +4713,7 @@ AnyFunctionType::getAutoDiffDerivativeFunctionLinearMapType(
47124713
this,
47134714
DerivativeFunctionTypeError::Kind::
47144715
NonDifferentiableDifferentiabilityParameter,
4715-
std::make_pair(paramType, i));
4716+
DerivativeFunctionTypeError::TypeAndIndex(paramType, i));
47164717

47174718
if (diffParam.isAutoDiffSemanticResult()) {
47184719
if (paramType->isVoid())

lib/ClangImporter/ClangImporter.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -2549,6 +2549,10 @@ PlatformAvailability::PlatformAvailability(const LangOptions &langOpts)
25492549
case PlatformKind::visionOSApplicationExtension:
25502550
break;
25512551

2552+
case PlatformKind::FreeBSD:
2553+
deprecatedAsUnavailableMessage = "";
2554+
break;
2555+
25522556
case PlatformKind::OpenBSD:
25532557
deprecatedAsUnavailableMessage = "";
25542558
break;
@@ -2596,6 +2600,9 @@ bool PlatformAvailability::isPlatformRelevant(StringRef name) const {
25962600
return name == "xros" || name == "xros_app_extension" ||
25972601
name == "visionos" || name == "visionos_app_extension";
25982602

2603+
case PlatformKind::FreeBSD:
2604+
return name == "freebsd";
2605+
25992606
case PlatformKind::OpenBSD:
26002607
return name == "openbsd";
26012608

@@ -2667,6 +2674,10 @@ bool PlatformAvailability::treatDeprecatedAsUnavailable(
26672674
// No deprecation filter on xrOS
26682675
return false;
26692676

2677+
case PlatformKind::FreeBSD:
2678+
// No deprecation filter on FreeBSD
2679+
return false;
2680+
26702681
case PlatformKind::OpenBSD:
26712682
// No deprecation filter on OpenBSD
26722683
return false;

lib/IRGen/TBDGen.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ getLinkerPlatformId(OriginallyDefinedInAttr::ActiveVersion Ver,
245245
llvm_unreachable("cannot find platform kind");
246246
case swift::PlatformKind::OpenBSD:
247247
llvm_unreachable("not used for this platform");
248+
case swift::PlatformKind::FreeBSD:
249+
llvm_unreachable("not used for this platform");
248250
case swift::PlatformKind::Windows:
249251
llvm_unreachable("not used for this platform");
250252
case swift::PlatformKind::iOS:

lib/Option/SanitizerOptions.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ OptionSet<SanitizerKind> swift::parseSanitizerArgValues(
168168
}
169169

170170
// Check that we're one of the known supported targets for sanitizers.
171-
if (!(Triple.isOSDarwin() || Triple.isOSLinux() || Triple.isOSWindows())) {
171+
if (!(Triple.isOSDarwin() || Triple.isOSLinux() || Triple.isOSWindows()
172+
|| Triple.isOSFreeBSD())) {
172173
SmallString<128> b;
173174
Diags.diagnose(SourceLoc(), diag::error_unsupported_opt_for_target,
174175
(A->getOption().getPrefixedName() +

lib/PrintAsClang/DeclAndTypePrinter.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1778,6 +1778,9 @@ class DeclAndTypePrinter::Implementation
17781778
case PlatformKind::visionOSApplicationExtension:
17791779
plat = "visionos_app_extension";
17801780
break;
1781+
case PlatformKind::FreeBSD:
1782+
plat = "freebsd";
1783+
break;
17811784
case PlatformKind::OpenBSD:
17821785
plat = "openbsd";
17831786
break;

lib/SymbolGraphGen/AvailabilityMixin.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ StringRef getDomain(const AvailableAttr &AvAttr) {
6262
return { "watchOSAppExtension" };
6363
case swift::PlatformKind::visionOSApplicationExtension:
6464
return { "visionOSAppExtension" };
65+
case swift::PlatformKind::FreeBSD:
66+
return { "FreeBSD" };
6567
case swift::PlatformKind::OpenBSD:
6668
return { "OpenBSD" };
6769
case swift::PlatformKind::Windows:

stdlib/public/SwiftShims/swift/shims/SwiftStdint.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
// Clang has been defining __INTxx_TYPE__ macros for a long time.
2626
// __UINTxx_TYPE__ are defined only since Clang 3.5.
27-
#if !defined(__APPLE__) && !defined(__linux__) && !defined(__OpenBSD__) && !defined(__wasi__)
27+
#if !defined(__APPLE__) && !defined(__linux__) && !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__wasi__)
2828
#include <stdint.h>
2929
typedef int64_t __swift_int64_t;
3030
typedef uint64_t __swift_uint64_t;

tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,7 @@ static void reportAttributes(ASTContext &Ctx,
686686
static UIdent PlatformOSXAppExt("source.availability.platform.osx_app_extension");
687687
static UIdent PlatformtvOSAppExt("source.availability.platform.tvos_app_extension");
688688
static UIdent PlatformWatchOSAppExt("source.availability.platform.watchos_app_extension");
689+
static UIdent PlatformFreeBSD("source.availability.platform.freebsd");
689690
static UIdent PlatformOpenBSD("source.availability.platform.openbsd");
690691
static UIdent PlatformWindows("source.availability.platform.windows");
691692
std::vector<const DeclAttribute*> Scratch;
@@ -722,6 +723,8 @@ static void reportAttributes(ASTContext &Ctx,
722723
case PlatformKind::visionOSApplicationExtension:
723724
// FIXME: Formal platform support in SourceKit is needed.
724725
PlatformUID = UIdent(); break;
726+
case PlatformKind::FreeBSD:
727+
PlatformUID = PlatformFreeBSD; break;
725728
case PlatformKind::OpenBSD:
726729
PlatformUID = PlatformOpenBSD; break;
727730
case PlatformKind::Windows:

0 commit comments

Comments
 (0)