15
15
//
16
16
// ===----------------------------------------------------------------------===//
17
17
18
- #include " swift/Subsystems.h"
19
18
#include " swift/AST/DiagnosticsFrontend.h"
20
19
#include " swift/AST/SILOptions.h"
21
20
#include " swift/Basic/FileTypes.h"
22
- #include " swift/Basic/LLVMInitialize.h"
23
21
#include " swift/Basic/InitializeSwiftModules.h"
22
+ #include " swift/Basic/LLVMInitialize.h"
24
23
#include " swift/Basic/QuotedString.h"
25
24
#include " swift/Frontend/DiagnosticVerifier.h"
26
25
#include " swift/Frontend/Frontend.h"
27
26
#include " swift/Frontend/PrintingDiagnosticConsumer.h"
27
+ #include " swift/IRGen/IRGenPublic.h"
28
+ #include " swift/IRGen/IRGenSILPasses.h"
29
+ #include " swift/Parse/ParseVersion.h"
28
30
#include " swift/SIL/SILRemarkStreamer.h"
29
31
#include " swift/SILOptimizer/Analysis/Analysis.h"
30
- #include " swift/SILOptimizer/PassManager/Passes.h"
31
32
#include " swift/SILOptimizer/PassManager/PassManager.h"
33
+ #include " swift/SILOptimizer/PassManager/Passes.h"
34
+ #include " swift/Serialization/SerializationOptions.h"
32
35
#include " swift/Serialization/SerializedModuleLoader.h"
33
36
#include " swift/Serialization/SerializedSILLoader.h"
34
- #include " swift/Serialization/SerializationOptions .h"
37
+ #include " swift/Subsystems .h"
35
38
#include " swift/SymbolGraphGen/SymbolGraphOptions.h"
36
- #include " swift/IRGen/IRGenPublic.h"
37
- #include " swift/IRGen/IRGenSILPasses.h"
38
39
#include " llvm/ADT/Statistic.h"
39
40
#include " llvm/Support/CommandLine.h"
40
41
#include " llvm/Support/FileSystem.h"
@@ -77,8 +78,30 @@ enum class EnforceExclusivityMode {
77
78
DynamicOnly,
78
79
None,
79
80
};
81
+
82
+ enum class SILOptStrictConcurrency {
83
+ None = 0 ,
84
+ Complete,
85
+ Targeted,
86
+ Minimal,
87
+ };
88
+
80
89
} // end anonymous namespace
81
90
91
+ std::optional<StrictConcurrency>
92
+ convertSILOptToRawStrictConcurrencyLevel (SILOptStrictConcurrency level) {
93
+ switch (level) {
94
+ case SILOptStrictConcurrency::None:
95
+ return {};
96
+ case SILOptStrictConcurrency::Complete:
97
+ return StrictConcurrency::Complete;
98
+ case SILOptStrictConcurrency::Targeted:
99
+ return StrictConcurrency::Targeted;
100
+ case SILOptStrictConcurrency::Minimal:
101
+ return StrictConcurrency::Minimal;
102
+ }
103
+ }
104
+
82
105
namespace llvm {
83
106
84
107
inline raw_ostream &
@@ -363,6 +386,12 @@ struct SILOptOptions {
363
386
llvm::cl::desc (" verify diagnostics against expected-"
364
387
" {error|warning|note} annotations" ));
365
388
389
+ llvm::cl::list<std::string> VerifyAdditionalPrefixes =
390
+ llvm::cl::list<std::string>(
391
+ " verify-additional-prefix" ,
392
+ llvm::cl::desc (" Check for diagnostics with the prefix "
393
+ " expected-<PREFIX> as well as expected-" ));
394
+
366
395
llvm::cl::opt<unsigned >
367
396
AssertConfId = llvm::cl::opt<unsigned >(" assert-conf-id" , llvm::cl::Hidden,
368
397
llvm::cl::init (0 ));
@@ -482,15 +511,19 @@ struct SILOptOptions {
482
511
cl::value_desc(" format" ), cl::init(" yaml" ));
483
512
484
513
// Strict Concurrency
485
- llvm::cl::opt<StrictConcurrency > StrictConcurrencyLevel =
486
- llvm::cl::opt<StrictConcurrency >(
514
+ llvm::cl::opt<SILOptStrictConcurrency > StrictConcurrencyLevel =
515
+ llvm::cl::opt<SILOptStrictConcurrency >(
487
516
" strict-concurrency" , cl::desc(" strict concurrency level" ),
488
- llvm::cl::values (clEnumValN(StrictConcurrency::Complete, " complete" ,
489
- " Enable complete strict concurrency" ),
490
- clEnumValN(StrictConcurrency::Targeted, " targeted" ,
491
- " Enable targeted strict concurrency" ),
492
- clEnumValN(StrictConcurrency::Minimal, " minimal" ,
493
- " Enable minimal strict concurrency" )));
517
+ llvm::cl::init (SILOptStrictConcurrency::None),
518
+ llvm::cl::values(
519
+ clEnumValN (SILOptStrictConcurrency::Complete, " complete" ,
520
+ " Enable complete strict concurrency" ),
521
+ clEnumValN(SILOptStrictConcurrency::Targeted, " targeted" ,
522
+ " Enable targeted strict concurrency" ),
523
+ clEnumValN(SILOptStrictConcurrency::Minimal, " minimal" ,
524
+ " Enable minimal strict concurrency" ),
525
+ clEnumValN(SILOptStrictConcurrency::None, " disabled" ,
526
+ " Strict concurrency disabled" )));
494
527
495
528
llvm::cl::opt<bool >
496
529
EnableCxxInterop = llvm::cl::opt<bool >(" enable-experimental-cxx-interop" ,
@@ -542,6 +575,11 @@ struct SILOptOptions {
542
575
llvm::cl::opt<bool >(
543
576
" disable-region-based-isolation-with-strict-concurrency" ,
544
577
llvm::cl::init (false ));
578
+
579
+ llvm::cl::opt<std::string> SwiftVersionString = llvm::cl::opt<std::string>(
580
+ " swift-version" ,
581
+ llvm::cl::desc (
582
+ " The swift version to assume AST declarations correspond to" ));
545
583
};
546
584
547
585
// / Regular expression corresponding to the value given in one of the
@@ -641,6 +679,23 @@ int sil_opt_main(ArrayRef<const char *> argv, void *MainAddr) {
641
679
// cache.
642
680
Invocation.getClangImporterOptions ().ModuleCachePath = options.ModuleCachePath ;
643
681
Invocation.setParseStdlib ();
682
+ if (options.SwiftVersionString .size ()) {
683
+ auto vers = VersionParser::parseVersionString (options.SwiftVersionString ,
684
+ SourceLoc (), nullptr );
685
+ bool isValid = false ;
686
+ if (vers.has_value ()) {
687
+ if (auto effectiveVers = vers.value ().getEffectiveLanguageVersion ()) {
688
+ Invocation.getLangOptions ().EffectiveLanguageVersion =
689
+ effectiveVers.value ();
690
+ isValid = true ;
691
+ }
692
+ }
693
+ if (!isValid) {
694
+ llvm::errs () << " error: invalid swift version "
695
+ << options.SwiftVersionString << ' \n ' ;
696
+ exit (-1 );
697
+ }
698
+ }
644
699
Invocation.getLangOptions ().DisableAvailabilityChecking = true ;
645
700
Invocation.getLangOptions ().EnableAccessControl = false ;
646
701
Invocation.getLangOptions ().EnableObjCAttrRequiresFoundation = false ;
@@ -664,15 +719,26 @@ int sil_opt_main(ArrayRef<const char *> argv, void *MainAddr) {
664
719
options.BypassResilienceChecks ;
665
720
Invocation.getDiagnosticOptions ().PrintDiagnosticNames =
666
721
options.DebugDiagnosticNames ;
722
+
667
723
for (auto &featureName : options.UpcomingFeatures ) {
668
- if (auto feature = getUpcomingFeature (featureName)) {
669
- Invocation.getLangOptions ().enableFeature (*feature);
670
- } else {
724
+ auto feature = getUpcomingFeature (featureName);
725
+ if (!feature) {
671
726
llvm::errs () << " error: unknown upcoming feature "
672
727
<< QuotedString (featureName) << " \n " ;
673
728
exit (-1 );
674
729
}
730
+
731
+ if (auto firstVersion = getFeatureLanguageVersion (*feature)) {
732
+ if (Invocation.getLangOptions ().isSwiftVersionAtLeast (*firstVersion)) {
733
+ llvm::errs () << " error: upcoming feature " << QuotedString (featureName)
734
+ << " is already enabled as of Swift version "
735
+ << *firstVersion << ' \n ' ;
736
+ exit (-1 );
737
+ }
738
+ }
739
+ Invocation.getLangOptions ().enableFeature (*feature);
675
740
}
741
+
676
742
for (auto &featureName : options.ExperimentalFeatures ) {
677
743
if (auto feature = getExperimentalFeature (featureName)) {
678
744
Invocation.getLangOptions ().enableFeature (*feature);
@@ -706,17 +772,35 @@ int sil_opt_main(ArrayRef<const char *> argv, void *MainAddr) {
706
772
707
773
Invocation.getLangOptions ().UnavailableDeclOptimizationMode =
708
774
options.UnavailableDeclOptimization ;
709
- if (options.StrictConcurrencyLevel .hasArgStr ()) {
775
+
776
+ // Enable strict concurrency if we have the feature specified or if it was
777
+ // specified via a command line option to sil-opt.
778
+ if (Invocation.getLangOptions ().hasFeature (Feature::StrictConcurrency)) {
710
779
Invocation.getLangOptions ().StrictConcurrencyLevel =
711
- options.StrictConcurrencyLevel ;
712
- if (options.StrictConcurrencyLevel == StrictConcurrency::Complete &&
713
- !options.DisableRegionBasedIsolationWithStrictConcurrency ) {
714
- Invocation.getLangOptions ().enableFeature (Feature::RegionBasedIsolation);
715
- }
780
+ StrictConcurrency::Complete;
781
+ } else if (auto level = convertSILOptToRawStrictConcurrencyLevel (
782
+ options.StrictConcurrencyLevel )) {
783
+ // If strict concurrency was enabled from the cmdline so the feature flag as
784
+ // well.
785
+ if (*level == StrictConcurrency::Complete)
786
+ Invocation.getLangOptions ().enableFeature (Feature::StrictConcurrency);
787
+ Invocation.getLangOptions ().StrictConcurrencyLevel = *level;
788
+ }
789
+
790
+ // If we have strict concurrency set as a feature and were told to turn off
791
+ // region based isolation... do so now.
792
+ if (Invocation.getLangOptions ().hasFeature (Feature::StrictConcurrency) &&
793
+ !options.DisableRegionBasedIsolationWithStrictConcurrency ) {
794
+ Invocation.getLangOptions ().enableFeature (Feature::RegionBasedIsolation);
716
795
}
717
796
718
797
Invocation.getDiagnosticOptions ().VerifyMode =
719
- options.VerifyMode ? DiagnosticOptions::Verify : DiagnosticOptions::NoVerify;
798
+ options.VerifyMode ? DiagnosticOptions::Verify
799
+ : DiagnosticOptions::NoVerify;
800
+ for (auto &additionalPrefixes : options.VerifyAdditionalPrefixes ) {
801
+ Invocation.getDiagnosticOptions ()
802
+ .AdditionalDiagnosticVerifierPrefixes .push_back (additionalPrefixes);
803
+ }
720
804
721
805
ClangImporterOptions &clangImporterOptions =
722
806
Invocation.getClangImporterOptions ();
0 commit comments