Skip to content

Commit 89b2f27

Browse files
committed
AST: Mark implicit destructor as synthesized to fix non-deterministic function order
We can synthesize the default init() and the implicit deinit in a class in any order, depending on the order of primary files and how that class was used in other primary files. Make sure that EmittedMembersRequest puts the destructor at the end with all other synthesized members, so that we produce the same object file in any case.
1 parent 055b3a8 commit 89b2f27

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

lib/AST/Decl.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -4318,6 +4318,10 @@ GetDestructorRequest::evaluate(Evaluator &evaluator, ClassDecl *CD) const {
43184318
if (ctx.LangOpts.EnableObjCInterop)
43194319
CD->recordObjCMethod(DD, DD->getObjCSelector());
43204320

4321+
// Mark it as synthesized to make its location in getEmittedMembers()
4322+
// deterministic.
4323+
DD->setSynthesized(true);
4324+
43214325
return DD;
43224326
}
43234327

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public func makeAHorse() -> Horse {
2+
return Horse()
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %target-swift-emit-silgen -module-name horse -primary-file %S/Inputs/deterministic-dtor-ordering-other.swift -primary-file %s -module-name horse | %FileCheck %s
2+
// RUN: %target-swift-emit-silgen -module-name horse %S/Inputs/deterministic-dtor-ordering-other.swift -primary-file %s -module-name horse | %FileCheck %s
3+
4+
public class Horse {}
5+
6+
// CHECK-LABEL: sil hidden [exact_self_class] [ossa] @$s5horse5HorseCACycfC : $@convention(method) (@thick Horse.Type) -> @owned Horse {
7+
// CHECK-LABEL: sil hidden [ossa] @$s5horse5HorseCACycfc : $@convention(method) (@owned Horse) -> @owned Horse {
8+
// CHECK-LABEL: sil [ossa] @$s5horse5HorseCfd : $@convention(method) (@guaranteed Horse) -> @owned Builtin.NativeObject {
9+
// CHECK-LABEL: sil [ossa] @$s5horse5HorseCfD : $@convention(method) (@owned Horse) -> () {
10+

test/SILGen/objc_thunks.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -454,13 +454,13 @@ class Wotsit<T> : Gizmo {
454454
return "Hello, world."
455455
}
456456

457-
// Ivar destroyer
458-
// CHECK-LABEL: sil hidden [ossa] @$s11objc_thunks6WotsitCfETo
459-
460457
// CHECK-LABEL: sil hidden [thunk] [ossa] @$s11objc_thunks6WotsitCACyxGSgycfcTo : $@convention(objc_method) <T> (@owned Wotsit<T>) -> @owned Optional<Wotsit<T>>
461458

462459
// CHECK-LABEL: sil hidden [thunk] [ossa] @$s11objc_thunks6WotsitC7bellsOnACyxGSgSi_tcfcTo : $@convention(objc_method) <T> (Int, @owned Wotsit<T>) -> @owned Optional<Wotsit<T>>
463460

461+
// Ivar destroyer
462+
// CHECK-LABEL: sil hidden [ossa] @$s11objc_thunks6WotsitCfETo
463+
464464
}
465465

466466
// CHECK-NOT: sil hidden [thunk] [ossa] @_TToF{{.*}}Wotsit{{.*}}

0 commit comments

Comments
 (0)