@@ -58,6 +58,18 @@ enum class OptGroup {
58
58
Lowering
59
59
};
60
60
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
+
61
73
} // end anonymous namespace
62
74
63
75
static llvm::cl::opt<std::string>
@@ -105,20 +117,20 @@ static llvm::cl::opt<bool>
105
117
EnableExperimentalConcurrency (" enable-experimental-concurrency" ,
106
118
llvm::cl::desc (" Enable experimental concurrency model." ));
107
119
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 ),
110
122
llvm::cl::desc(" Enable lexical lifetimes. Mutually exclusive with "
111
123
" enable-lexical-borrow-scopes and "
112
124
" disable-lexical-lifetimes." ));
113
125
114
- static llvm::cl::opt<bool >
126
+ static llvm::cl::opt<llvm::cl::boolOrDefault >
115
127
EnableLexicalBorrowScopes (" enable-lexical-borrow-scopes" ,
116
- llvm::cl::init (true ),
128
+ llvm::cl::init (llvm::cl::BOU_UNSET ),
117
129
llvm::cl::desc(" Enable lexical borrow scopes." ));
118
130
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." ));
122
134
123
135
static llvm::cl::opt<bool >
124
136
EnableExperimentalDistributed (" enable-experimental-distributed" ,
@@ -520,8 +532,11 @@ int main(int argc, char **argv) {
520
532
EnableExperimentalConcurrency;
521
533
Invocation.getLangOptions ().EnableExperimentalDistributed =
522
534
EnableExperimentalDistributed;
523
- Invocation.getLangOptions ().EnableExperimentalMoveOnly =
524
- EnableExperimentalMoveOnly;
535
+ Optional<bool > enableExperimentalMoveOnly =
536
+ toOptionalBool (EnableExperimentalMoveOnly);
537
+ if (enableExperimentalMoveOnly)
538
+ Invocation.getLangOptions ().EnableExperimentalMoveOnly =
539
+ *enableExperimentalMoveOnly;
525
540
526
541
Invocation.getLangOptions ().EnableObjCInterop =
527
542
EnableObjCInterop ? true :
@@ -623,22 +638,34 @@ int main(int argc, char **argv) {
623
638
if (SILOpts.CopyPropagation == CopyPropagationOption::Off)
624
639
SILOpts.LexicalLifetimes = LexicalLifetimesOption::DiagnosticMarkersOnly;
625
640
641
+ Optional<bool > enableLexicalLifetimes =
642
+ toOptionalBool (EnableLexicalLifetimes);
643
+ Optional<bool > enableLexicalBorrowScopes =
644
+ toOptionalBool (EnableLexicalBorrowScopes);
645
+
626
646
// Enable lexical lifetimes if it is set or if experimental move only is
627
647
// enabled. This is because move only depends on lexical lifetimes being
628
648
// 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) {
632
654
fprintf (
633
655
stderr,
634
656
" Error! Cannot specify both -enable-lexical-borrow-scopes=false and "
635
657
" either -enable-lexical-lifetimes or -enable-experimental-move-only." );
636
658
exit (-1 );
637
659
}
638
660
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;
642
669
643
670
serialization::ExtendedValidationInfo extendedInfo;
644
671
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileBufOrErr =
0 commit comments