Commit Graph

4 Commits

Author SHA1 Message Date
Michael Gottesman
79b225ffa8 [silgen] Fix up EnumElementPatternInitialization::emitEnumMatch to use ownership.
This commit does a few things:

1. It uses SwitchEnumBuilder so we are not re-inventing any wheels.
2. Instead of hacking around not putting in a destroy for .None on the fail
pass, just *do the right thing* and recognize that we have a binary case enum
and in such a case, just emit code for the other case rather than use a default
case (meaning no cleanup on .none).

rdar://31145255
2017-03-29 15:36:41 -07:00
Michael Gottesman
bf8d941103 [silgen] Change foreach loop emission to use the new SwitchEnumBuilder.
rdar://29791263
2017-03-07 22:13:22 -08:00
practicalswift
95e74d54ad [gardening] Fix includes 2017-03-07 16:44:53 +01:00
Michael Gottesman
e849900a7b [silgen] Add a new API for building switches: SwitchEnumBuilder.
This is a closure based API for creating switches that obey ownership
convensions. The way you use it with objects is as follows:

   SwitchEnumBuilder S(...);

   S.addCase(Decl, Block, [](ManagedValue Arg) -> void {
     ...
   });
   S.addCase(Decl, Block, [](ManagedValue Arg) -> void {
     ...
   });
   S.addDefaultCase(Block, [](ManagedValue Arg) -> void {
     ...
   });
   std::move(S).emit();

What is important is that it sets up the switch_enum destination blocks with the
proper cleanups for code emitted into the destination block and also provides
the default error with the passed in value with the appropriate cleanups.

It does not handle exits from the switch_enum on purpose since diamond
switch_enum APIs form a subset of APIs. It also expects the closure to create
terminators if appropriate.

In the switch_enum_addr case you have to do a bit more work, but it is still a
nicer API than doing it by hand as we do today.

rdar://29791263
2017-03-06 13:58:33 -08:00