Commit Graph

10 Commits

Author SHA1 Message Date
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Evan Wilde
f3ff561c6f [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.
2023-06-27 09:03:52 -07:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Andrew Trick
8f53a927b0 SILGen OSSA support for switch_enum/checked_cast_br, related cleanup
Use APIs for creating terminator results that handle forwarding
ownership consistently.

Add ManagedValue::forForwardedRValue(SILValue) to handle cleanups
consistently based on ownership forwarding.

Add SILGenBuilder::createForwardedTermResult(SILType type) for
creating termator results with the correct ownership and cleanups.

Add SILGenBuilder::createTermResult(SILType type, ValueOwnershipKind
ownership) that handles cleanup based on terminator result ownership.

Add SILGenBuilder::createOptionalSomeResult(SwitchEnumInst) so a lot
of code doesn't need to deal with unwrapping Optional types,
terminator results, and ownership rules.

Replace the existing "phi" APIs with a single
SILGenBuilder::createPhi(SILType, ValueOwnershipKind) that handles
cleanup based on phi ownership.

Phis and terminator results are fundamentally different and need to be handled differently everywhere. Remove the confusion where terminator results were generated with a "phi argument" API.
2021-09-07 22:50:46 -07:00
Varun Gandhi
4195859630 [NFC] Rename SwitchEnumBuilder's optional field to subjectExprOperand. 2020-12-11 18:31:05 -08:00
Michael Gottesman
f84f48eb5a [silgen] Make SwitchCaseFullExpr use an ArgumentScope instead of just a Scope.
Otherwise, if we move in a formal access cleanup value into switch emission
using a cleanup cloner, we will improperly have a formal access cleanup that
will be invalidated by a normal Scope which violates SILGen invariants. Also in
a certain sense the bindings performed by SILGenPattern that do this type of
forwarding are arguments in a certain sense so it seems reasonable to do this.

<rdar://problem/70736924>
2020-11-12 23:31:13 -08:00
Michael Gottesman
797fe6085d [+0-all-args] Teach SwitchEnumBuilder how to handle cases with a jump dest continuation. 2018-03-15 17:28:47 -07:00
Michael Gottesman
aa9b27802a [silgen] Add helper methods to SwitchEnumBuilder for creating .Some, .None cases.
I also used it to clean up a few uses of SwitchEnumBuilder.
2018-03-15 17:28:47 -07:00
Michael Gottesman
6b2ca79381 [silgen] Make NormalCaseHandler and DefaultCaseHandler take SwitchCaseFullExpr as movable rvalues.
This fits more with the notion of the API, that the user is being given a scope
that was already setup for them and that they must decide when to pop.
2018-03-15 17:28:47 -07:00
Michael Gottesman
76af5c5b16 [silgen] Centralize SwitchEnumBuilder and SwitchCaseFullExpr into the same file: SwitchEnumBuilder.{h,cpp}.
Previously SwitchEnumBuilder was in SILGenBuilder.{h,cpp} and
SwitchEnumCaseFullExpr was in its own file. This really made no sense since:

1. The two classes are inherently related to each other so really should be
together in the source base.
2. SwitchEnumBuilder uses a SILGenBuilder, but is really a separate independent
concept/entity, so there really is no reason to keep it in SILGenBuilder.cpp.

Just a quick fix to eliminate something that was bugging me.

NFC.
2018-02-17 13:09:23 -08:00