Skip to content

Commit 7cad780

Browse files
authored
[AST] Sink ModuleDecl's flags down into the shared Decl bitfields (#20051)
Saves 4 bytes per ModuleDecl. No functionality change.
1 parent c3a9498 commit 7cad780

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed

include/swift/AST/Decl.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,8 @@ class alignas(1 << DeclAlignInBits) Decl {
463463
HasStubImplementation : 1
464464
);
465465

466-
SWIFT_INLINE_BITFIELD_EMPTY(AbstractTypeParamDecl, ValueDecl);
466+
SWIFT_INLINE_BITFIELD_EMPTY(TypeDecl, ValueDecl);
467+
SWIFT_INLINE_BITFIELD_EMPTY(AbstractTypeParamDecl, TypeDecl);
467468

468469
SWIFT_INLINE_BITFIELD_FULL(GenericTypeParamDecl, AbstractTypeParamDecl, 16+16,
469470
: NumPadBits,
@@ -472,7 +473,7 @@ class alignas(1 << DeclAlignInBits) Decl {
472473
Index : 16
473474
);
474475

475-
SWIFT_INLINE_BITFIELD_EMPTY(GenericTypeDecl, ValueDecl);
476+
SWIFT_INLINE_BITFIELD_EMPTY(GenericTypeDecl, TypeDecl);
476477

477478
SWIFT_INLINE_BITFIELD(TypeAliasDecl, GenericTypeDecl, 1+1,
478479
/// Whether the typealias forwards perfectly to its underlying type.
@@ -572,6 +573,22 @@ class alignas(1 << DeclAlignInBits) Decl {
572573
HasAnyUnavailableValues : 1
573574
);
574575

576+
SWIFT_INLINE_BITFIELD(ModuleDecl, TypeDecl, 1+1+1+1,
577+
/// If the module was or is being compiled with `-enable-testing`.
578+
TestingEnabled : 1,
579+
580+
/// If the module failed to load
581+
FailedToLoad : 1,
582+
583+
/// Whether the module is resilient.
584+
///
585+
/// \sa ResilienceStrategy
586+
RawResilienceStrategy : 1,
587+
588+
/// Whether all imports have been resolved. Used to detect circular imports.
589+
HasResolvedImports : 1
590+
);
591+
575592
SWIFT_INLINE_BITFIELD(PrecedenceGroupDecl, Decl, 1+2,
576593
/// Is this an assignment operator?
577594
IsAssignment : 1,

include/swift/AST/Module.h

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,6 @@ class ModuleDecl : public DeclContext, public TypeDecl {
241241
/// \see EntryPointInfoTy
242242
EntryPointInfoTy EntryPointInfo;
243243

244-
struct {
245-
unsigned TestingEnabled : 1;
246-
unsigned FailedToLoad : 1;
247-
unsigned ResilienceStrategy : 1;
248-
unsigned HasResolvedImports : 1;
249-
} Flags;
250-
251244
ModuleDecl(Identifier name, ASTContext &ctx);
252245

253246
public:
@@ -284,32 +277,32 @@ class ModuleDecl : public DeclContext, public TypeDecl {
284277

285278
/// Returns true if this module was or is being compiled for testing.
286279
bool isTestingEnabled() const {
287-
return Flags.TestingEnabled;
280+
return Bits.ModuleDecl.TestingEnabled;
288281
}
289282
void setTestingEnabled(bool enabled = true) {
290-
Flags.TestingEnabled = enabled;
283+
Bits.ModuleDecl.TestingEnabled = enabled;
291284
}
292285

293286
/// Returns true if there was an error trying to load this module.
294287
bool failedToLoad() const {
295-
return Flags.FailedToLoad;
288+
return Bits.ModuleDecl.FailedToLoad;
296289
}
297290
void setFailedToLoad(bool failed = true) {
298-
Flags.FailedToLoad = failed;
291+
Bits.ModuleDecl.FailedToLoad = failed;
299292
}
300293

301294
bool hasResolvedImports() const {
302-
return Flags.HasResolvedImports;
295+
return Bits.ModuleDecl.HasResolvedImports;
303296
}
304297
void setHasResolvedImports() {
305-
Flags.HasResolvedImports = true;
298+
Bits.ModuleDecl.HasResolvedImports = true;
306299
}
307300

308301
ResilienceStrategy getResilienceStrategy() const {
309-
return ResilienceStrategy(Flags.ResilienceStrategy);
302+
return ResilienceStrategy(Bits.ModuleDecl.RawResilienceStrategy);
310303
}
311304
void setResilienceStrategy(ResilienceStrategy strategy) {
312-
Flags.ResilienceStrategy = unsigned(strategy);
305+
Bits.ModuleDecl.RawResilienceStrategy = unsigned(strategy);
313306
}
314307

315308
/// Look up a (possibly overloaded) value set at top-level scope

lib/AST/Module.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ void SourceLookupCache::invalidate() {
353353

354354
ModuleDecl::ModuleDecl(Identifier name, ASTContext &ctx)
355355
: DeclContext(DeclContextKind::Module, nullptr),
356-
TypeDecl(DeclKind::Module, &ctx, name, SourceLoc(), { }),
357-
Flags() {
356+
TypeDecl(DeclKind::Module, &ctx, name, SourceLoc(), { }) {
357+
358358
ctx.addDestructorCleanup(*this);
359359
setImplicit();
360360
setInterfaceType(ModuleType::get(this));

0 commit comments

Comments
 (0)