mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".
I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
This commit is contained in:
@@ -117,7 +117,7 @@ public:
|
||||
|
||||
void printSynthesizedExtensionPre(const ExtensionDecl *ED,
|
||||
TypeOrExtensionDecl Target,
|
||||
Optional<BracketOptions> Bracket) override {
|
||||
llvm::Optional<BracketOptions> Bracket) override {
|
||||
// When we start print a synthesized extension, record the target's USR.
|
||||
llvm::SmallString<64> Buf;
|
||||
llvm::raw_svector_ostream OS(Buf);
|
||||
@@ -130,7 +130,7 @@ public:
|
||||
void
|
||||
printSynthesizedExtensionPost(const ExtensionDecl *ED,
|
||||
TypeOrExtensionDecl Target,
|
||||
Optional<BracketOptions> Bracket) override {
|
||||
llvm::Optional<BracketOptions> Bracket) override {
|
||||
// When we leave a synthesized extension, clear target's USR.
|
||||
TargetUSR = "";
|
||||
}
|
||||
@@ -307,11 +307,11 @@ public:
|
||||
|
||||
static bool getModuleInterfaceInfo(ASTContext &Ctx,
|
||||
StringRef ModuleName,
|
||||
Optional<StringRef> Group,
|
||||
llvm::Optional<StringRef> Group,
|
||||
SwiftInterfaceGenContext::Implementation &Impl,
|
||||
std::string &ErrMsg,
|
||||
bool SynthesizedExtensions,
|
||||
Optional<StringRef> InterestedUSR) {
|
||||
llvm::Optional<StringRef> InterestedUSR) {
|
||||
ModuleDecl *&Mod = Impl.Mod;
|
||||
SourceTextInfo &Info = Impl.Info;
|
||||
|
||||
@@ -362,7 +362,7 @@ static bool getModuleInterfaceInfo(ASTContext &Ctx,
|
||||
Options.SkipInlineCXXNamespace = true;
|
||||
}
|
||||
}
|
||||
ModuleTraversalOptions TraversalOptions = None; // Don't print submodules.
|
||||
ModuleTraversalOptions TraversalOptions = llvm::None; // Don't print submodules.
|
||||
SmallString<128> Text;
|
||||
llvm::raw_svector_ostream OS(Text);
|
||||
AnnotatingPrinter Printer(Info, OS);
|
||||
@@ -431,11 +431,11 @@ SwiftInterfaceGenContextRef
|
||||
SwiftInterfaceGenContext::create(StringRef DocumentName,
|
||||
bool IsModule,
|
||||
StringRef ModuleOrHeaderName,
|
||||
Optional<StringRef> Group,
|
||||
llvm::Optional<StringRef> Group,
|
||||
CompilerInvocation Invocation,
|
||||
std::string &ErrMsg,
|
||||
bool SynthesizedExtensions,
|
||||
Optional<StringRef> InterestedUSR) {
|
||||
llvm::Optional<StringRef> InterestedUSR) {
|
||||
SwiftInterfaceGenContextRef IFaceGenCtx{ new SwiftInterfaceGenContext() };
|
||||
IFaceGenCtx->Impl.DocumentName = DocumentName.str();
|
||||
IFaceGenCtx->Impl.IsModule = IsModule;
|
||||
@@ -653,7 +653,7 @@ llvm::Optional<std::pair<unsigned, unsigned>>
|
||||
SwiftInterfaceGenContext::findUSRRange(StringRef USR) const {
|
||||
auto Pos = Impl.Info.USRMap.find(USR);
|
||||
if (Pos == Impl.Info.USRMap.end())
|
||||
return None;
|
||||
return llvm::None;
|
||||
|
||||
return std::make_pair(Pos->getValue().Range.Offset,
|
||||
Pos->getValue().Range.Length);
|
||||
@@ -736,10 +736,10 @@ void SwiftLangSupport::editorOpenTypeInterface(EditorConsumer &Consumer,
|
||||
void SwiftLangSupport::editorOpenInterface(EditorConsumer &Consumer,
|
||||
StringRef Name,
|
||||
StringRef ModuleName,
|
||||
Optional<StringRef> Group,
|
||||
llvm::Optional<StringRef> Group,
|
||||
ArrayRef<const char *> Args,
|
||||
bool SynthesizedExtensions,
|
||||
Optional<StringRef> InterestedUSR) {
|
||||
llvm::Optional<StringRef> InterestedUSR) {
|
||||
CompilerInstance CI;
|
||||
// Display diagnostics to stderr.
|
||||
PrintingDiagnosticConsumer PrintDiags;
|
||||
@@ -884,11 +884,11 @@ void SwiftLangSupport::editorOpenHeaderInterface(EditorConsumer &Consumer,
|
||||
auto IFaceGenRef = SwiftInterfaceGenContext::create(Name,
|
||||
/*IsModule=*/false,
|
||||
HeaderName,
|
||||
None,
|
||||
llvm::None,
|
||||
Invocation,
|
||||
Error,
|
||||
SynthesizedExtensions,
|
||||
None);
|
||||
llvm::None);
|
||||
if (!IFaceGenRef) {
|
||||
Consumer.handleRequestError(Error.c_str());
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user