Skip to content

Commit 1008ecc

Browse files
[c-interop] Use llvm::Optional instead of std::optional for now
The Attr.h is shared with SwiftCompilerSources through C++ interop and C++ interop somehow crashes with libc++'s std::optional. So use legacy llvm::Optional for now.
1 parent b27fd9a commit 1008ecc

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

include/swift/AST/Attr.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2343,25 +2343,25 @@ class ExposeAttr : public DeclAttribute {
23432343
/// the specified way to interoperate with Swift.
23442344
class ExternAttr : public DeclAttribute {
23452345
public:
2346-
ExternAttr(std::optional<StringRef> ModuleName, std::optional<StringRef> Name,
2346+
ExternAttr(llvm::Optional<StringRef> ModuleName, llvm::Optional<StringRef> Name,
23472347
SourceLoc AtLoc, SourceRange Range, ExternKind Kind, bool Implicit)
23482348
: DeclAttribute(DAK_Extern, AtLoc, Range, Implicit),
23492349
ModuleName(ModuleName), Name(Name) {
23502350
Bits.ExternAttr.kind = static_cast<unsigned>(Kind);
23512351
}
23522352

2353-
ExternAttr(std::optional<StringRef> ModuleName, std::optional<StringRef> Name,
2353+
ExternAttr(llvm::Optional<StringRef> ModuleName, llvm::Optional<StringRef> Name,
23542354
ExternKind Kind, bool Implicit)
23552355
: ExternAttr(ModuleName, Name, SourceLoc(), SourceRange(), Kind,
23562356
Implicit) {}
23572357

23582358
/// The module name to import the named declaration in it
23592359
/// Used for Wasm import declaration.
2360-
const std::optional<StringRef> ModuleName;
2360+
const llvm::Optional<StringRef> ModuleName;
23612361

23622362
/// The declaration name to import
23632363
/// std::nullopt if the declaration name is not specified with @_extern(c)
2364-
const std::optional<StringRef> Name;
2364+
const llvm::Optional<StringRef> Name;
23652365

23662366
/// Returns the kind of extern.
23672367
ExternKind getExternKind() const {

lib/Parse/ParseDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,7 @@ bool Parser::parseExternAttribute(DeclAttributes &Attributes,
14501450
}
14511451

14521452
auto parseStringLiteralArgument =
1453-
[&](std::optional<StringRef> fieldName) -> std::optional<StringRef> {
1453+
[&](std::optional<StringRef> fieldName) -> llvm::Optional<StringRef> {
14541454
if (!consumeIf(tok::comma)) {
14551455
diagnose(Loc, diag::attr_expected_comma, AttrName,
14561456
DeclAttribute::isDeclModifier(DAK_Extern));
@@ -1489,7 +1489,7 @@ bool Parser::parseExternAttribute(DeclAttributes &Attributes,
14891489

14901490
// Parse @_extern(wasm, module: "x", name: "y") or @_extern(c[, "x"])
14911491
ExternKind kind;
1492-
std::optional<StringRef> importModuleName, importName;
1492+
llvm::Optional<StringRef> importModuleName, importName;
14931493

14941494
if (kindTok.getText() == "wasm") {
14951495
kind = ExternKind::Wasm;

lib/Serialization/Deserialization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5864,7 +5864,7 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
58645864
scratch, isImplicit, rawKind, moduleNameSize, declNameSize);
58655865

58665866
ExternKind kind = (ExternKind)rawKind;
5867-
std::optional<StringRef> moduleName, declName;
5867+
llvm::Optional<StringRef> moduleName, declName;
58685868

58695869
switch (kind) {
58705870
case ExternKind::C: {

0 commit comments

Comments
 (0)