Skip to content

Commit c3230df

Browse files
committed
Add the implicit dynamic attribute in the IsDynamicRequest query
1 parent f7d8515 commit c3230df

File tree

10 files changed

+28
-19
lines changed

10 files changed

+28
-19
lines changed

include/swift/AST/Decl.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ class alignas(1 << DeclAlignInBits) Decl {
570570
HasAnyUnavailableValues : 1
571571
);
572572

573-
SWIFT_INLINE_BITFIELD(ModuleDecl, TypeDecl, 1+1+1+1+1,
573+
SWIFT_INLINE_BITFIELD(ModuleDecl, TypeDecl, 1+1+1+1+1+1,
574574
/// If the module was or is being compiled with `-enable-testing`.
575575
TestingEnabled : 1,
576576

@@ -586,7 +586,10 @@ class alignas(1 << DeclAlignInBits) Decl {
586586
HasResolvedImports : 1,
587587

588588
// If the module was or is being compiled with `-enable-private-imports`.
589-
PrivateImportsEnabled : 1
589+
PrivateImportsEnabled : 1,
590+
591+
// If the module is compiled with `-enable-implicit-dynamic`.
592+
ImplicitDynamicEnabled : 1
590593
);
591594

592595
SWIFT_INLINE_BITFIELD(PrecedenceGroupDecl, Decl, 1+2,

include/swift/AST/Module.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,14 @@ class ModuleDecl : public DeclContext, public TypeDecl {
283283
Bits.ModuleDecl.TestingEnabled = enabled;
284284
}
285285

286+
// Returns true if this module is compiled with implicit dynamic.
287+
bool isImplicitDynamicEnabled() const {
288+
return Bits.ModuleDecl.ImplicitDynamicEnabled;
289+
}
290+
void setImplicitDynamicEnabled(bool enabled = true) {
291+
Bits.ModuleDecl.ImplicitDynamicEnabled = enabled;
292+
}
293+
286294
/// Returns true if this module was or is begin compile with
287295
/// `-enable-private-imports`.
288296
bool arePrivateImportsEnabled() const {

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,6 @@ namespace swift {
144144
/// was not compiled with -enable-testing.
145145
bool EnableTestableAttrRequiresTestableModule = true;
146146

147-
/// If true, the 'dynamic' attribute is added to all applicable
148-
/// declarations.
149-
bool EnableImplicitDynamic = false;
150-
151147
///
152148
/// Flags for developers
153149
///

include/swift/Frontend/FrontendOptions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ class FrontendOptions {
197197
/// \see ModuleDecl::arePrivateImportsEnabled
198198
bool EnablePrivateImports = false;
199199

200+
201+
/// Indicates whether we add implicit dynamic.
202+
///
203+
/// \see ModuleDecl::isImplicitDynamicEnabled
204+
bool EnableImplicitDynamic = false;
205+
200206
/// Enables the "fully resilient" resilience strategy.
201207
///
202208
/// \see ResilienceStrategy::Resilient

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ bool ArgsToFrontendOptionsConverter::convert(
6969
Opts.EnableTesting |= Args.hasArg(OPT_enable_testing);
7070
Opts.EnablePrivateImports |= Args.hasArg(OPT_enable_private_imports);
7171
Opts.EnableResilience |= Args.hasArg(OPT_enable_resilience);
72+
Opts.EnableImplicitDynamic |= Args.hasArg(OPT_enable_implicit_dynamic);
7273

7374
Opts.TrackSystemDeps |= Args.hasArg(OPT_track_system_dependencies);
7475

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
274274
Opts.DebugConstraintSolver |= Args.hasArg(OPT_debug_constraints);
275275
Opts.NamedLazyMemberLoading &= !Args.hasArg(OPT_disable_named_lazy_member_loading);
276276
Opts.DebugGenericSignatures |= Args.hasArg(OPT_debug_generic_signatures);
277-
Opts.EnableImplicitDynamic |= Args.hasArg(OPT_enable_implicit_dynamic);
278277

279278
if (Args.hasArg(OPT_verify_syntax_tree)) {
280279
Opts.BuildSyntaxTree = true;

lib/Frontend/Frontend.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,8 @@ ModuleDecl *CompilerInstance::getMainModule() {
488488
MainModule->setTestingEnabled();
489489
if (Invocation.getFrontendOptions().EnablePrivateImports)
490490
MainModule->setPrivateImportsEnabled();
491+
if (Invocation.getFrontendOptions().EnableImplicitDynamic)
492+
MainModule->setImplicitDynamicEnabled();
491493

492494
if (Invocation.getFrontendOptions().EnableResilience)
493495
MainModule->setResilienceStrategy(ResilienceStrategy::Resilient);

lib/Sema/TypeCheckAttr.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2451,9 +2451,6 @@ TypeChecker::diagnosticIfDeclCannotBePotentiallyUnavailable(const Decl *D) {
24512451
}
24522452

24532453
void TypeChecker::addImplicitDynamicAttribute(Decl *D) {
2454-
if (!getLangOpts().EnableImplicitDynamic)
2455-
return;
2456-
24572454
// Add the attribute if the decl kind allows it and it is not an accessor
24582455
// decl. Accessor decls should always infer the var/subscript's attribute.
24592456
if (!DeclAttribute::canAttributeAppearOnDecl(DAK_Dynamic, D) ||

lib/Sema/TypeCheckDecl.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,11 @@ IsDynamicRequest::evaluate(Evaluator &evaluator, ValueDecl *decl) const {
12141214
if (!DeclAttribute::canAttributeAppearOnDecl(DAK_Dynamic, decl))
12151215
return false;
12161216

1217+
// Add dynamic if -enable-implicit-dynamic was requested.
1218+
if (decl->getModuleContext()->isImplicitDynamicEnabled()) {
1219+
TypeChecker::addImplicitDynamicAttribute(decl);
1220+
}
1221+
12171222
// If 'dynamic' was explicitly specified, check it.
12181223
if (decl->getAttrs().hasAttribute<DynamicAttr>()) {
12191224
if (decl->getASTContext().LangOpts.isSwiftVersionAtLeast(5))
@@ -2470,7 +2475,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
24702475

24712476
void visitBoundVariable(VarDecl *VD) {
24722477
TC.validateDecl(VD);
2473-
TC.addImplicitDynamicAttribute(VD);
24742478

24752479
// Set up accessors.
24762480
maybeAddAccessorsToStorage(TC, VD);
@@ -2727,8 +2731,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
27272731
}
27282732

27292733
void visitSubscriptDecl(SubscriptDecl *SD) {
2730-
TC.addImplicitDynamicAttribute(SD);
2731-
27322734
TC.validateDecl(SD);
27332735

27342736
if (!SD->isInvalid()) {
@@ -3198,8 +3200,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
31983200
}
31993201

32003202
void visitVarDecl(VarDecl *VD) {
3201-
TC.addImplicitDynamicAttribute(VD);
3202-
32033203
// Delay type-checking on VarDecls until we see the corresponding
32043204
// PatternBindingDecl.
32053205

@@ -3251,8 +3251,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
32513251
}
32523252

32533253
void visitFuncDecl(FuncDecl *FD) {
3254-
TC.addImplicitDynamicAttribute(FD);
3255-
32563254
TC.validateDecl(FD);
32573255

32583256
if (!FD->isInvalid()) {
@@ -3369,7 +3367,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
33693367
}
33703368

33713369
void visitConstructorDecl(ConstructorDecl *CD) {
3372-
TC.addImplicitDynamicAttribute(CD);
33733370
TC.validateDecl(CD);
33743371

33753372
if (!CD->isInvalid()) {

lib/Sema/TypeChecker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ class TypeChecker final : public LazyResolver {
10951095
void typeCheckDecl(Decl *D);
10961096

10971097
void checkDeclAttributesEarly(Decl *D);
1098-
void addImplicitDynamicAttribute(Decl *D);
1098+
static void addImplicitDynamicAttribute(Decl *D);
10991099
void checkDeclAttributes(Decl *D);
11001100
void checkDynamicReplacementAttribute(ValueDecl *D);
11011101
void checkTypeModifyingDeclAttributes(VarDecl *var);

0 commit comments

Comments
 (0)