Skip to content

Commit d82880a

Browse files
authored
Merge pull request swiftlang#31721 from CodaFi/const-of-proportionality
Const-Qualify LangOptions and TypeCheckerOptions
2 parents f90e030 + 2bca013 commit d82880a

28 files changed

+151
-98
lines changed

include/swift/AST/ASTContext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,10 @@ class ASTContext final {
238238
UnifiedStatsReporter *Stats = nullptr;
239239

240240
/// The language options used for translation.
241-
LangOptions &LangOpts;
241+
const LangOptions &LangOpts;
242242

243243
/// The type checker options.
244-
TypeCheckerOptions &TypeCheckerOpts;
244+
const TypeCheckerOptions &TypeCheckerOpts;
245245

246246
/// The search path options used by this AST context.
247247
SearchPathOptions &SearchPathOpts;

include/swift/AST/Decl.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ class alignas(1 << DeclAlignInBits) Decl {
575575
HasAnyUnavailableValues : 1
576576
);
577577

578-
SWIFT_INLINE_BITFIELD(ModuleDecl, TypeDecl, 1+1+1+1+1+1+1+1,
578+
SWIFT_INLINE_BITFIELD(ModuleDecl, TypeDecl, 1+1+1+1+1+1+1+1+1,
579579
/// If the module was or is being compiled with `-enable-testing`.
580580
TestingEnabled : 1,
581581

@@ -601,7 +601,10 @@ class alignas(1 << DeclAlignInBits) Decl {
601601

602602
/// Whether the module was imported from Clang (or, someday, maybe another
603603
/// language).
604-
IsNonSwiftModule : 1
604+
IsNonSwiftModule : 1,
605+
606+
/// Whether this module is the main module.
607+
IsMainModule : 1
605608
);
606609

607610
SWIFT_INLINE_BITFIELD(PrecedenceGroupDecl, Decl, 1+2,

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,5 +379,10 @@ ERROR(expectation_missing_opening_braces,none,
379379
ERROR(expectation_missing_closing_braces,none,
380380
"didn't find '}}' to match '{{' in expectation", ())
381381

382+
WARNING(module_incompatible_with_skip_function_bodies,none,
383+
"module '%0' cannot be built with "
384+
"-experimental-skip-non-inlinable-function-bodies; this option has "
385+
"been automatically disabled", (StringRef))
386+
382387
#define UNDEFINE_DIAGNOSTIC_MACROS
383388
#include "DefineDiagnosticMacros.h"

include/swift/AST/Module.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,13 @@ class ModuleDecl : public DeclContext, public TypeDecl {
347347
return new (ctx) ModuleDecl(name, ctx, importInfo);
348348
}
349349

350+
static ModuleDecl *
351+
createMainModule(ASTContext &ctx, Identifier name, ImplicitImportInfo iinfo) {
352+
auto *Mod = ModuleDecl::create(name, ctx, iinfo);
353+
Mod->Bits.ModuleDecl.IsMainModule = true;
354+
return Mod;
355+
}
356+
350357
using Decl::getASTContext;
351358

352359
/// Retrieves information about which modules are implicitly imported by
@@ -542,6 +549,10 @@ class ModuleDecl : public DeclContext, public TypeDecl {
542549
Bits.ModuleDecl.IsNonSwiftModule = flag;
543550
}
544551

552+
bool isMainModule() const {
553+
return Bits.ModuleDecl.IsMainModule;
554+
}
555+
545556
/// Retrieve the top-level module. If this module is already top-level, this
546557
/// returns itself. If this is a submodule such as \c Foo.Bar.Baz, this
547558
/// returns the module \c Foo.

include/swift/AST/PlatformKind.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ StringRef prettyPlatformString(PlatformKind platform);
5454
/// If ForTargetVariant is true then for zippered builds the target-variant
5555
/// triple will be used rather than the target to determine whether the
5656
/// platform is active.
57-
bool isPlatformActive(PlatformKind Platform, LangOptions &LangOpts,
57+
bool isPlatformActive(PlatformKind Platform, const LangOptions &LangOpts,
5858
bool ForTargetVariant = false);
5959

6060
/// Returns the target platform for the given language options.
61-
PlatformKind targetPlatform(LangOptions &LangOpts);
61+
PlatformKind targetPlatform(const LangOptions &LangOpts);
6262

6363
/// Returns true when availability attributes from the "parent" platform
6464
/// should also apply to the "child" platform for declarations without

lib/AST/Module.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,16 @@ ModuleDecl::ModuleDecl(Identifier name, ASTContext &ctx,
475475
setInterfaceType(ModuleType::get(this));
476476

477477
setAccess(AccessLevel::Public);
478+
479+
Bits.ModuleDecl.TestingEnabled = 0;
480+
Bits.ModuleDecl.FailedToLoad = 0;
481+
Bits.ModuleDecl.RawResilienceStrategy = 0;
482+
Bits.ModuleDecl.HasResolvedImports = 0;
483+
Bits.ModuleDecl.PrivateImportsEnabled = 0;
484+
Bits.ModuleDecl.ImplicitDynamicEnabled = 0;
485+
Bits.ModuleDecl.IsSystemModule = 0;
486+
Bits.ModuleDecl.IsNonSwiftModule = 0;
487+
Bits.ModuleDecl.IsMainModule = 0;
478488
}
479489

480490
ArrayRef<ImplicitImport> ModuleDecl::getImplicitImports() const {

lib/AST/PlatformKind.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static bool isPlatformActiveForTarget(PlatformKind Platform,
9292
llvm_unreachable("bad PlatformKind");
9393
}
9494

95-
bool swift::isPlatformActive(PlatformKind Platform, LangOptions &LangOpts,
95+
bool swift::isPlatformActive(PlatformKind Platform, const LangOptions &LangOpts,
9696
bool ForTargetVariant) {
9797
llvm::Triple TT = LangOpts.Target;
9898

@@ -105,7 +105,7 @@ bool swift::isPlatformActive(PlatformKind Platform, LangOptions &LangOpts,
105105
LangOpts.EnableAppExtensionRestrictions);
106106
}
107107

108-
PlatformKind swift::targetPlatform(LangOptions &LangOpts) {
108+
PlatformKind swift::targetPlatform(const LangOptions &LangOpts) {
109109
if (LangOpts.Target.isMacOSX()) {
110110
return (LangOpts.EnableAppExtensionRestrictions
111111
? PlatformKind::OSXApplicationExtension

lib/ClangImporter/ClangImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1877,7 +1877,7 @@ ClangImporter::getWrapperForModule(const clang::Module *mod,
18771877
return clangUnit->getParentModule();
18781878
}
18791879

1880-
PlatformAvailability::PlatformAvailability(LangOptions &langOpts)
1880+
PlatformAvailability::PlatformAvailability(const LangOptions &langOpts)
18811881
: platformKind(targetPlatform(langOpts)) {
18821882
switch (platformKind) {
18831883
case PlatformKind::iOS:

lib/ClangImporter/ImporterImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ struct PlatformAvailability {
255255
/// API is now unavailable.
256256
std::string deprecatedAsUnavailableMessage;
257257

258-
PlatformAvailability(LangOptions &opts);
258+
PlatformAvailability(const LangOptions &opts);
259259

260260
private:
261261
PlatformAvailability(const PlatformAvailability&) = delete;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,11 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
629629
}
630630
}
631631

632+
if (FrontendOpts.RequestedAction == FrontendOptions::ActionType::EmitSyntax) {
633+
Opts.BuildSyntaxTree = true;
634+
Opts.VerifySyntaxTree = true;
635+
}
636+
632637
return HadError || UnsupportedOS || UnsupportedArch;
633638
}
634639

@@ -677,6 +682,17 @@ static bool ParseTypeCheckerArgs(TypeCheckerOptions &Opts, ArgList &Args,
677682
// body skipping.
678683
Opts.SkipNonInlinableFunctionBodies |= Args.hasArg(OPT_tbd_is_installapi);
679684

685+
if (Opts.SkipNonInlinableFunctionBodies &&
686+
FrontendOpts.ModuleName == SWIFT_ONONE_SUPPORT) {
687+
// Disable this optimization if we're compiling SwiftOnoneSupport, because
688+
// we _definitely_ need to look inside every declaration to figure out
689+
// what gets prespecialized.
690+
Opts.SkipNonInlinableFunctionBodies = false;
691+
Diags.diagnose(SourceLoc(),
692+
diag::module_incompatible_with_skip_function_bodies,
693+
SWIFT_ONONE_SUPPORT);
694+
}
695+
680696
Opts.DisableConstraintSolverPerformanceHacks |=
681697
Args.hasArg(OPT_disable_constraint_solver_performance_hacks);
682698

@@ -903,12 +919,14 @@ void parseExclusivityEnforcementOptions(const llvm::opt::Arg *A,
903919

904920
static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
905921
IRGenOptions &IRGenOpts,
906-
FrontendOptions &FEOpts,
922+
const FrontendOptions &FEOpts,
923+
const TypeCheckerOptions &TCOpts,
907924
DiagnosticEngine &Diags,
908925
const llvm::Triple &Triple,
909926
ClangImporterOptions &ClangOpts) {
910927
using namespace options;
911928

929+
912930
if (const Arg *A = Args.getLastArg(OPT_sil_inline_threshold)) {
913931
if (StringRef(A->getValue()).getAsInteger(10, Opts.InlineThreshold)) {
914932
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
@@ -951,8 +969,9 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
951969
if (Args.hasArg(OPT_sil_merge_partial_modules))
952970
Opts.MergePartialModules = true;
953971

954-
if (Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies))
955-
Opts.SkipNonInlinableFunctionBodies = true;
972+
// Propagate the typechecker's understanding of
973+
// -experimental-skip-non-inlinable-function-bodies to SIL.
974+
Opts.SkipNonInlinableFunctionBodies = TCOpts.SkipNonInlinableFunctionBodies;
956975

957976
// Parse the optimization level.
958977
// Default to Onone settings if no option is passed.
@@ -1624,7 +1643,8 @@ bool CompilerInvocation::parseArgs(
16241643
return true;
16251644
}
16261645

1627-
if (ParseSILArgs(SILOpts, ParsedArgs, IRGenOpts, FrontendOpts, Diags,
1646+
if (ParseSILArgs(SILOpts, ParsedArgs, IRGenOpts, FrontendOpts,
1647+
TypeCheckerOpts, Diags,
16281648
LangOpts.Target, ClangImporterOpts)) {
16291649
return true;
16301650
}

0 commit comments

Comments
 (0)