1717// /
1818// / Swift's closure model is that all local variables are capture by reference.
1919// / This produces a very simple programming model which is great to use, but
20- // / relies on the optimizer to promote by-ref captures to by-value (i.e. by-copy)
21- // / captures for decent performance. Consider this simple example:
20+ // / relies on the optimizer to promote by-ref captures to by-value (i.e.
21+ // / by-copy) captures for decent performance. Consider this simple example:
2222// /
2323// / func foo(a : () -> ()) {} // assume this has an unknown body
2424// /
3030// /
3131// / Since x is captured by-ref by the closure, x must live on the heap. By
3232// / looking at bar without any knowledge of foo, we can know that it is safe to
33- // / promote this to a by-value capture, allowing x to live on the stack under the
34- // / following conditions:
33+ // / promote this to a by-value capture, allowing x to live on the stack under
34+ // / the following conditions:
3535// /
3636// / 1. If x is not modified in the closure body and is only loaded.
3737// / 2. If we can prove that all mutations to x occur before the closure is
3838// / formed.
3939// /
40- // / Under these conditions if x is loadable then we can even load the given value
41- // / and pass it as a scalar instead of an address.
40+ // / Under these conditions if x is loadable then we can even load the given
41+ // / value and pass it as a scalar instead of an address.
4242// /
4343// ===----------------------------------------------------------------------===//
4444
4545#define DEBUG_TYPE " sil-capture-promotion"
4646#include " swift/AST/GenericEnvironment.h"
4747#include " swift/SIL/SILCloner.h"
48- #include " swift/SILOptimizer/Utils/SILOptFunctionBuilder.h"
4948#include " swift/SIL/TypeSubstCloner.h"
5049#include " swift/SILOptimizer/PassManager/Passes.h"
5150#include " swift/SILOptimizer/PassManager/Transforms.h"
51+ #include " swift/SILOptimizer/Utils/SILOptFunctionBuilder.h"
5252#include " swift/SILOptimizer/Utils/SpecializationMangler.h"
5353#include " llvm/ADT/BitVector.h"
5454#include " llvm/ADT/SmallSet.h"
@@ -365,8 +365,8 @@ computeNewArgInterfaceTypes(SILFunction *f, IndicesSet &promotableIndices,
365365 param.getSILStorageType (fnConv.silConv .getModule (), fnConv.funcTy ,
366366 TypeExpansionContext::minimal ());
367367 auto paramBoxTy = paramTy.castTo <SILBoxType>();
368- assert (paramBoxTy->getLayout ()->getFields ().size () == 1
369- && " promoting compound box not implemented yet" );
368+ assert (paramBoxTy->getLayout ()->getFields ().size () == 1 &&
369+ " promoting compound box not implemented yet" );
370370 auto paramBoxedTy =
371371 getSILBoxFieldType (TypeExpansionContext (*f), paramBoxTy, types, 0 );
372372 assert (expansion == f->getResilienceExpansion ());
@@ -452,8 +452,7 @@ ClosureCloner::initCloned(SILOptFunctionBuilder &functionBuilder,
452452
453453// / Populate the body of the cloned closure, modifying instructions as
454454// / necessary to take into consideration the promoted capture(s)
455- void
456- ClosureCloner::populateCloned () {
455+ void ClosureCloner::populateCloned () {
457456 SILFunction *cloned = getCloned ();
458457
459458 // Create arguments for the entry block
@@ -868,10 +867,10 @@ class NonEscapingUserVisitor
868867 // / the old behavior of non-top-level uses not being able to have partial
869868 // / apply and project box uses.
870869 struct detail {
871- enum IsMutating_t {
872- IsNotMutating = 0 ,
873- IsMutating = 1 ,
874- };
870+ enum IsMutating_t {
871+ IsNotMutating = 0 ,
872+ IsMutating = 1 ,
873+ };
875874 };
876875#define RECURSIVE_INST_VISITOR (MUTATING, INST ) \
877876 bool visit##INST##Inst(INST##Inst *i) { \
@@ -898,7 +897,7 @@ class NonEscapingUserVisitor
898897 // begin_access may signify a modification, but is considered nonmutating
899898 // because we will peek though it's uses to find the actual mutation.
900899 RECURSIVE_INST_VISITOR (IsNotMutating, BeginAccess)
901- RECURSIVE_INST_VISITOR (IsMutating , UncheckedTakeEnumDataAddr)
900+ RECURSIVE_INST_VISITOR (IsMutating, UncheckedTakeEnumDataAddr)
902901#undef RECURSIVE_INST_VISITOR
903902
904903 bool visitCopyAddrInst (CopyAddrInst *cai) {
0 commit comments