@@ -58,6 +58,18 @@ enum class OptGroup {
5858 Lowering
5959};
6060
61+ Optional<bool > toOptionalBool (llvm::cl::boolOrDefault defaultable) {
62+ switch (defaultable) {
63+ case llvm::cl::BOU_TRUE:
64+ return true ;
65+ case llvm::cl::BOU_FALSE:
66+ return false ;
67+ case llvm::cl::BOU_UNSET:
68+ return None;
69+ }
70+ llvm_unreachable (" Bad case for llvm::cl::boolOrDefault!" );
71+ }
72+
6173} // end anonymous namespace
6274
6375static llvm::cl::opt<std::string>
@@ -105,20 +117,20 @@ static llvm::cl::opt<bool>
105117EnableExperimentalConcurrency (" enable-experimental-concurrency" ,
106118 llvm::cl::desc (" Enable experimental concurrency model." ));
107119
108- static llvm::cl::opt<bool > EnableLexicalLifetimes (
109- " enable-lexical-lifetimes" , llvm::cl::init(false ),
120+ static llvm::cl::opt<llvm::cl::boolOrDefault > EnableLexicalLifetimes (
121+ " enable-lexical-lifetimes" , llvm::cl::init(llvm::cl::BOU_UNSET ),
110122 llvm::cl::desc(" Enable lexical lifetimes. Mutually exclusive with "
111123 " enable-lexical-borrow-scopes and "
112124 " disable-lexical-lifetimes." ));
113125
114- static llvm::cl::opt<bool >
126+ static llvm::cl::opt<llvm::cl::boolOrDefault >
115127 EnableLexicalBorrowScopes (" enable-lexical-borrow-scopes" ,
116- llvm::cl::init (true ),
128+ llvm::cl::init (llvm::cl::BOU_UNSET ),
117129 llvm::cl::desc(" Enable lexical borrow scopes." ));
118130
119- static llvm::cl::opt<bool >
120- EnableExperimentalMoveOnly ( " enable-experimental-move-only" ,
121- llvm::cl::desc (" Enable experimental distributed actors." ));
131+ static llvm::cl::opt<llvm::cl::boolOrDefault> EnableExperimentalMoveOnly (
132+ " enable-experimental-move-only" , llvm::cl::init(llvm::cl::BOU_UNSET) ,
133+ llvm::cl::desc(" Enable experimental distributed actors." ));
122134
123135static llvm::cl::opt<bool >
124136EnableExperimentalDistributed (" enable-experimental-distributed" ,
@@ -520,8 +532,11 @@ int main(int argc, char **argv) {
520532 EnableExperimentalConcurrency;
521533 Invocation.getLangOptions ().EnableExperimentalDistributed =
522534 EnableExperimentalDistributed;
523- Invocation.getLangOptions ().EnableExperimentalMoveOnly =
524- EnableExperimentalMoveOnly;
535+ Optional<bool > enableExperimentalMoveOnly =
536+ toOptionalBool (EnableExperimentalMoveOnly);
537+ if (enableExperimentalMoveOnly)
538+ Invocation.getLangOptions ().EnableExperimentalMoveOnly =
539+ *enableExperimentalMoveOnly;
525540
526541 Invocation.getLangOptions ().EnableObjCInterop =
527542 EnableObjCInterop ? true :
@@ -623,22 +638,34 @@ int main(int argc, char **argv) {
623638 if (SILOpts.CopyPropagation == CopyPropagationOption::Off)
624639 SILOpts.LexicalLifetimes = LexicalLifetimesOption::DiagnosticMarkersOnly;
625640
641+ Optional<bool > enableLexicalLifetimes =
642+ toOptionalBool (EnableLexicalLifetimes);
643+ Optional<bool > enableLexicalBorrowScopes =
644+ toOptionalBool (EnableLexicalBorrowScopes);
645+
626646 // Enable lexical lifetimes if it is set or if experimental move only is
627647 // enabled. This is because move only depends on lexical lifetimes being
628648 // enabled and it saved some typing ; ).
629- bool enableLexicalLifetimes =
630- EnableLexicalLifetimes | EnableExperimentalMoveOnly;
631- if (enableLexicalLifetimes && !EnableLexicalBorrowScopes) {
649+ bool specifiedLexicalLifetimesEnabled =
650+ enableExperimentalMoveOnly && *enableExperimentalMoveOnly &&
651+ enableLexicalLifetimes && *enableLexicalLifetimes;
652+ if (specifiedLexicalLifetimesEnabled && enableLexicalBorrowScopes &&
653+ !*enableLexicalBorrowScopes) {
632654 fprintf (
633655 stderr,
634656 " Error! Cannot specify both -enable-lexical-borrow-scopes=false and "
635657 " either -enable-lexical-lifetimes or -enable-experimental-move-only." );
636658 exit (-1 );
637659 }
638660 if (enableLexicalLifetimes)
639- SILOpts.LexicalLifetimes = LexicalLifetimesOption::On;
640- if (!EnableLexicalBorrowScopes)
641- SILOpts.LexicalLifetimes = LexicalLifetimesOption::Off;
661+ SILOpts.LexicalLifetimes =
662+ *enableLexicalLifetimes ? LexicalLifetimesOption::On
663+ : LexicalLifetimesOption::DiagnosticMarkersOnly;
664+ if (enableLexicalBorrowScopes)
665+ SILOpts.LexicalLifetimes =
666+ *enableLexicalBorrowScopes
667+ ? LexicalLifetimesOption::DiagnosticMarkersOnly
668+ : LexicalLifetimesOption::Off;
642669
643670 serialization::ExtendedValidationInfo extendedInfo;
644671 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileBufOrErr =
0 commit comments