Skip to content

Migrate llvm::Optional to std::optional #71368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2024

Conversation

bnbarham
Copy link
Contributor

@bnbarham bnbarham commented Feb 3, 2024

LLVM has removed llvm::Optional, move over to std::optional. Also clang-format to fix up all the renamed #includes.

@bnbarham
Copy link
Contributor Author

bnbarham commented Feb 3, 2024

@swift-ci please test

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

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

Seems pretty mechanical. Thank you for clang-formatting the patch!

@bnbarham bnbarham force-pushed the std-optional-all-the-things branch from 81e9eaf to e3026dc Compare February 3, 2024 19:27
@bnbarham
Copy link
Contributor Author

bnbarham commented Feb 3, 2024

@swift-ci please test

@bnbarham bnbarham force-pushed the std-optional-all-the-things branch 2 times, most recently from 0d1781a to df0f936 Compare February 3, 2024 20:39
@bnbarham
Copy link
Contributor Author

bnbarham commented Feb 3, 2024

@swift-ci please test

@bnbarham bnbarham force-pushed the std-optional-all-the-things branch from df0f936 to a29341e Compare February 4, 2024 02:26
@bnbarham bnbarham closed this Feb 4, 2024
@al45tair
Copy link
Contributor

al45tair commented Feb 4, 2024

(On Windows) looks like maybe a missing #include <optional> somewhere:

C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\include\swift/Basic/Lazy.h(36,3): error: no template named 'optional' in namespace 'std'; did you mean 'llvm::Optional'?
   36 |   std::optional<T> Value;
      |   ^~~~~~~~~~~~~
      |   llvm::Optional
C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\stdlib\include\llvm/ADT/Optional.h(251,29): note: 'llvm::Optional' declared here
  251 | template <typename T> class Optional {
      |                             ^
1 error generated.
[107/308][ 34%][6.689s] Building CXX object stdlib\public\CMakeFiles\swiftDemangling-windows-x86_64.dir\__\__\lib\Demangling\Demangler.cpp.obj
[108/308][ 35%][6.792s] Building CXX object stdlib\public\runtime\CMakeFiles\swiftRuntime-windows-x86_64.dir\GenericMetadataBuilder.cpp.obj
In file included from C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\stdlib\public\runtime\GenericMetadataBuilder.cpp:17:
C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\include\swift/Runtime/GenericMetadataBuilder.h(400,11): warning: unused variable 'pattern' [-Wunused-variable]
  400 |     auto *pattern = patternBuffer.ptr;
      |           ^~~~~~~
C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\stdlib\public\runtime\GenericMetadataBuilder.cpp(296,25): note: in instantiation of member function 'swift::GenericMetadataBuilder<InProcessReaderWriter>::buildGenericValueMetadata' requested here
  296 |   auto result = builder.buildGenericValueMetadata({description}, arguments,
      |                         ^
1 warning generated.

Copy link
Contributor

@al45tair al45tair left a comment

Choose a reason for hiding this comment

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

Looks pretty mechanical. I've skimmed over most of it, but what I looked at all seemed good. There's a Windows issue, but that looks like a missing <optional> somewhere (probably some difference in the C++ library that causes it to be pulled in on the other platforms but not on the version we're using on Windows).

I'll be especially pleased to see the back of llvm::None as that causes problems adding None cases to enums.

Copy link
Contributor

@mikeash mikeash left a comment

Choose a reason for hiding this comment

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

That's a big ol' diff. I didn't read it all, but assuming it's all s/llvm::Optional/std::optional/ then I'm happy.

@bnbarham
Copy link
Contributor Author

bnbarham commented Feb 5, 2024

Looks pretty mechanical. I've skimmed over most of it, but what I looked at all seemed good. There's a Windows issue, but that looks like a missing somewhere (probably some difference in the C++ library that causes it to be pulled in on the other platforms but not on the version we're using on Windows).

Yeah, MSVC doesn't end up pulling in <optional> from <functional> like macOS does (I didn't check where it's pulled in on Linux). I can easily fix this by adding <optional> into Basic/Lazy.h but I find it strange that the stdlib uses Basic at all TBH - I certainly wouldn't expect a Basic change to possibly impact ABI (and no, I don't know if we are using it in ABI somewhere, it just makes it very easy to).

I'll be especially pleased to see the back of llvm::None as that causes problems adding None cases to enums.

Heh. So just to be clear - this still doesn't remove it from a bunch of directories, namely ABI/Demangling/Remote*/Threading. These end up being used from the stdlib (and maybe ABI somewhere) as well as from tools. Technically those are all currently using std::optional though since that's what llvm::Optional is aliased to on main.

That's a big ol' diff. I didn't read it all, but assuming it's all s/llvm::Optional/std::optional/ then I'm happy.

If only. Unfortunately:

  1. More Optional were added with a using namespace llvm
  2. SourceKit and unittests both had the unqualified versions still
  3. There's also None and NoneType

But... close enough :)

Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

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

Went through most of the Sema.

@bnbarham bnbarham force-pushed the std-optional-all-the-things branch from 070cd58 to 291ff75 Compare February 8, 2024 04:43
@bnbarham bnbarham requested a review from a team as a code owner February 8, 2024 04:43
@bnbarham
Copy link
Contributor Author

bnbarham commented Feb 8, 2024

swiftlang/llvm-project#8120

@swift-ci please test

@bnbarham bnbarham force-pushed the std-optional-all-the-things branch 2 times, most recently from d8684e6 to f8301e6 Compare February 8, 2024 19:35
@bnbarham bnbarham requested a review from eeckstein as a code owner February 8, 2024 19:35
@bnbarham bnbarham force-pushed the std-optional-all-the-things branch 2 times, most recently from 0744069 to 1c43212 Compare February 8, 2024 22:43
@bnbarham
Copy link
Contributor Author

bnbarham commented Feb 8, 2024

swiftlang/llvm-project#8120

@swift-ci please test

@bnbarham bnbarham force-pushed the std-optional-all-the-things branch from 1c43212 to 01938a8 Compare February 9, 2024 00:04
@bnbarham
Copy link
Contributor Author

bnbarham commented Feb 9, 2024

swiftlang/llvm-project#8120

@swift-ci please test

@bnbarham bnbarham force-pushed the std-optional-all-the-things branch from 01938a8 to d30a3e5 Compare February 9, 2024 01:43
@bnbarham
Copy link
Contributor Author

bnbarham commented Feb 9, 2024

swiftlang/llvm-project#8120

@swift-ci please test

@bnbarham bnbarham force-pushed the std-optional-all-the-things branch from d30a3e5 to 792d103 Compare February 12, 2024 22:46
@bnbarham
Copy link
Contributor Author

swiftlang/llvm-project#8120

@swift-ci please test

@bnbarham
Copy link
Contributor Author

@swift-ci please test

@bnbarham bnbarham force-pushed the std-optional-all-the-things branch from 792d103 to 5257121 Compare February 21, 2024 05:24
@bnbarham
Copy link
Contributor Author

@swift-ci please test

LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
@bnbarham
Copy link
Contributor Author

@swift-ci please smoke test

@bnbarham bnbarham force-pushed the std-optional-all-the-things branch from 5257121 to ef8825b Compare February 21, 2024 19:20
@bnbarham
Copy link
Contributor Author

@swift-ci please test Windows platform

@bnbarham bnbarham merged commit 5637284 into swiftlang:main Feb 22, 2024
@bnbarham bnbarham deleted the std-optional-all-the-things branch February 22, 2024 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants