Skip to content

Commit 04aeaca

Browse files
authored
Merge pull request swiftlang#20539 from aschwaighofer/some_enable_implicit_dynamic_fixes
2 parents c266662 + 1019e34 commit 04aeaca

File tree

4 files changed

+88
-1
lines changed

4 files changed

+88
-1
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2466,7 +2466,8 @@ void TypeChecker::addImplicitDynamicAttribute(Decl *D) {
24662466
isa<AccessorDecl>(D))
24672467
return;
24682468

2469-
if (!D->getAttrs().hasAttribute<DynamicAttr>()) {
2469+
if (!D->getAttrs().hasAttribute<DynamicAttr>() &&
2470+
!D->getAttrs().hasAttribute<DynamicReplacementAttr>()) {
24702471
auto attr = new (D->getASTContext()) DynamicAttr(/*implicit=*/true);
24712472
D->getAttrs().add(attr);
24722473
}

test/Interpreter/Inputs/dynamic_replacement_module.swift

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,71 @@ public enum PublicEnumeration<Q> {
6363
return "public_enum_generic_func"
6464
}
6565
}
66+
#elseif MODULENODYNAMIC
67+
public func public_global_func() -> String {
68+
return "public_global_func"
69+
}
70+
71+
public func public_global_generic_func<T>(_ t: T.Type) -> String {
72+
return "public_global_generic_func"
73+
}
74+
75+
public class PublicClass {
76+
public var str : String = ""
77+
public init() {}
78+
public init(x: Int) { str = "public_class_init" }
79+
80+
public func function() -> String {
81+
return "public_class_func"
82+
}
83+
public func genericFunction<T>(_ t: T.Type) -> String {
84+
return "public_class_generic_func"
85+
}
86+
}
87+
88+
public struct PublicStruct {
89+
public var str = ""
90+
public init() {}
91+
92+
public init(x: Int) { str = "public_struct_init" }
93+
94+
public func function() -> String {
95+
return "public_struct_func"
96+
}
97+
public func genericFunction<T>(_ t: T.Type) -> String {
98+
return "public_struct_generic_func"
99+
}
100+
public var public_stored_property : String = "public_stored_property"
66101

102+
public subscript(_ x: Int) -> String {
103+
get {
104+
return "public_subscript_get"
105+
}
106+
set {
107+
str = newValue
108+
}
109+
}
110+
public subscript(y x: Int) -> String {
111+
_read {
112+
yield "public_subscript_get_modify_read"
113+
}
114+
_modify {
115+
yield &str
116+
}
117+
}
118+
}
119+
120+
public enum PublicEnumeration<Q> {
121+
case A
122+
case B
123+
124+
public func function() -> String {
125+
return "public_enum_func"
126+
}
127+
public func genericFunction<T>(_ t: T.Type) -> String {
128+
return "public_enum_generic_func"
129+
}
130+
}
67131
#elseif MODULE2
68132

69133
import Module1

test/Interpreter/dynamic_replacement.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,23 @@
2929
// RUN: %target-codesign %t/main %t/libModule1.%target-dylib-extension %t/libModule2.%target-dylib-extension
3030
// RUN: %target-run %t/main %t/libModule1.%target-dylib-extension %t/libModule2.%target-dylib-extension
3131

32+
// Test the -enable-implicit-dynamic flag.
33+
34+
// RUN: %empty-directory(%t)
35+
// RUN: %target-build-swift-dylib(%t/libModule1.%target-dylib-extension) -DMODULENODYNAMIC -module-name Module1 -emit-module -emit-module-path %t/Module1.swiftmodule -swift-version 5 %S/Inputs/dynamic_replacement_module.swift -Xfrontend -enable-implicit-dynamic
36+
// RUN: %target-build-swift-dylib(%t/libModule2.%target-dylib-extension) -I%t -L%t -lModule1 -Xlinker -rpath -Xlinker %t -DMODULE2 -module-name Module2 -emit-module -emit-module-path %t/Module2.swiftmodule -swift-version 5 %S/Inputs/dynamic_replacement_module.swift
37+
// RUN: %target-build-swift -I%t -L%t -lModule1 -DMAIN -o %t/main -Xlinker -rpath -Xlinker %t %s -swift-version 5
38+
// RUN: %target-codesign %t/main %t/libModule1.%target-dylib-extension %t/libModule2.%target-dylib-extension
39+
// RUN: %target-run %t/main %t/libModule1.%target-dylib-extension %t/libModule2.%target-dylib-extension
40+
41+
// Test the -enable-implicit-dynamic flag in optimized wholemodule mode.
42+
// RUN: %empty-directory(%t)
43+
// RUN: %target-build-swift-dylib(%t/libModule1.%target-dylib-extension) -O -wmo -DMODULENODYNAMIC -module-name Module1 -emit-module -emit-module-path %t/Module1.swiftmodule -swift-version 5 %S/Inputs/dynamic_replacement_module.swift -Xfrontend -enable-implicit-dynamic
44+
// RUN: %target-build-swift-dylib(%t/libModule2.%target-dylib-extension) -O -wmo -I%t -L%t -lModule1 -Xlinker -rpath -Xlinker %t -DMODULE2 -module-name Module2 -emit-module -emit-module-path %t/Module2.swiftmodule -swift-version 5 %S/Inputs/dynamic_replacement_module.swift
45+
// RUN: %target-build-swift -O -wmo -I%t -L%t -lModule1 -DMAIN -o %t/main -Xlinker -rpath -Xlinker %t %s -swift-version 5
46+
// RUN: %target-codesign %t/main %t/libModule1.%target-dylib-extension %t/libModule2.%target-dylib-extension
47+
// RUN: %target-run %t/main %t/libModule1.%target-dylib-extension %t/libModule2.%target-dylib-extension
48+
3249

3350
// REQUIRES: executable_test
3451

test/SILGen/dynamically_replaceable.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
// RUN: %target-swift-emit-silgen -enable-sil-ownership -swift-version 5 %s | %FileCheck %s
2+
// RUN: %target-swift-emit-silgen -enable-sil-ownership -swift-version 5 %s -enable-implicit-dynamic | %FileCheck %s --check-prefix=IMPLICIT
23

4+
// CHECK-LABEL: sil hidden @$s23dynamically_replaceable014maybe_dynamic_B0yyF : $@convention(thin) () -> () {
5+
// IMPLICIT-LABEL: sil hidden [dynamically_replacable] @$s23dynamically_replaceable014maybe_dynamic_B0yyF : $@convention(thin) () -> () {
6+
func maybe_dynamic_replaceable() {
7+
}
38

49
// CHECK-LABEL: sil hidden [dynamically_replacable] @$s23dynamically_replaceable08dynamic_B0yyF : $@convention(thin) () -> () {
510
dynamic func dynamic_replaceable() {

0 commit comments

Comments
 (0)