Skip to content

Commit f858309

Browse files
committed
Sema: EmittedMembersRequest forces SynthesizeMainFunctionRequest
1 parent 50632d2 commit f858309

File tree

5 files changed

+50
-0
lines changed

5 files changed

+50
-0
lines changed

lib/Sema/TypeCheckDecl.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -2523,6 +2523,12 @@ EmittedMembersRequest::evaluate(Evaluator &evaluator,
25232523
forceConformance(Context.getProtocol(KnownProtocolKind::Hashable));
25242524
forceConformance(Context.getProtocol(KnownProtocolKind::Differentiable));
25252525

2526+
// If the class has a @main attribute, we need to force synthesis of the
2527+
// $main function.
2528+
(void) evaluateOrDefault(Context.evaluator,
2529+
SynthesizeMainFunctionRequest{CD},
2530+
nullptr);
2531+
25262532
for (auto *member : CD->getMembers()) {
25272533
if (auto *var = dyn_cast<VarDecl>(member)) {
25282534
// The projected storage wrapper ($foo) might have dynamically-dispatched

test/SILGen/attr_main_class.swift

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %target-swift-emit-silgen -parse-as-library %s | %FileCheck %s
2+
3+
@main class Horse {
4+
static func main() {}
5+
}
6+
7+
// CHECK-LABEL: sil hidden [ossa] @$s15attr_main_class5HorseC5$mainyyFZ : $@convention(method) (@thick Horse.Type) -> () {
8+
9+
// CHECK-LABEL: sil [ossa] @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
10+
// CHECK: function_ref @$s15attr_main_class5HorseC5$mainyyFZ : $@convention(method) (@thick Horse.Type) -> ()
11+
// CHECK: }

test/SILGen/attr_main_class_2.swift

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %target-swift-emit-silgen -parse-as-library %s | %FileCheck %s
2+
3+
@main class Horse {
4+
class func main() {}
5+
}
6+
7+
// CHECK-LABEL: sil hidden [ossa] @$s17attr_main_class_25HorseC5$mainyyFZ : $@convention(method) (@thick Horse.Type) -> () {
8+
9+
// CHECK-LABEL: sil [ossa] @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
10+
// CHECK: function_ref @$s17attr_main_class_25HorseC5$mainyyFZ : $@convention(method) (@thick Horse.Type) -> ()
11+
// CHECK: }

test/SILGen/attr_main_enum.swift

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %target-swift-emit-silgen -parse-as-library %s | %FileCheck %s
2+
3+
@main enum Horse {
4+
static func main() {}
5+
}
6+
7+
// CHECK-LABEL: sil hidden [ossa] @$s14attr_main_enum5HorseO5$mainyyFZ : $@convention(method) (@thin Horse.Type) -> () {
8+
9+
// CHECK-LABEL: sil [ossa] @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
10+
// CHECK: function_ref @$s14attr_main_enum5HorseO5$mainyyFZ : $@convention(method) (@thin Horse.Type) -> ()
11+
// CHECK: }

test/SILGen/attr_main_struct.swift

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %target-swift-emit-silgen -parse-as-library %s | %FileCheck %s
2+
3+
@main struct Horse {
4+
static func main() {}
5+
}
6+
7+
// CHECK-LABEL: sil hidden [ossa] @$s16attr_main_struct5HorseV5$mainyyFZ : $@convention(method) (@thin Horse.Type) -> () {
8+
9+
// CHECK-LABEL: sil [ossa] @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
10+
// CHECK: function_ref @$s16attr_main_struct5HorseV5$mainyyFZ : $@convention(method) (@thin Horse.Type) -> ()
11+
// CHECK: }

0 commit comments

Comments
 (0)