Skip to content

Commit 6d6fa37

Browse files
authored
Always emit id and actorSystem in expected order
Without this change, the results of the `enumerateStoredPropertiesAndMissing` function still might return in the wrong order. Specifically, previously we would emit the stored, synthesized properties in the right order: ``` (var_decl implicit "id" type='SampleSystem.ActorID' interface type='SampleSystem.ActorID' access=public let readImpl=stored immutable (accessor_decl implicit 'anonname=0x1372fc578' interface type='(Worker_OTHER_MODULE) -> () -> SampleSystem.ActorID' ... (var_decl implicit "actorSystem" type='Worker_OTHER_MODULE.ActorSystem' interface type='Worker_OTHER_MODULE.ActorSystem' access=public let readImpl=stored immutable (accessor_decl implicit 'anonname=0x1372fc908' interface type='(Worker_OTHER_MODULE) -> () -> Worker_OTHER_MODULE.ActorSystem' ... ``` However, the results would still be in the "normal" order if the properties were from the interface (I think because the protocol conformance?), rather than the concrete nominal... This would manifest in results looking like this: ``` (var_decl implicit "actorSystem" type='Worker_OTHER_MODULE.ActorSystem' interface type='Worker_OTHER_MODULE.ActorSystem' access=public let readImpl=stored immutable (accessor_decl implicit 'anonname=0x147186770' access=public final get_for=actorSystem (parameter "self") (parameter_list))) (var_decl implicit "id" type='SampleSystem.ActorID' interface type='SampleSystem.ActorID' access=public let readImpl=stored immutable (accessor_decl implicit 'anonname=0x14718aa18' access=public final get_for=id (parameter "self") (parameter_list))) ``` Since those are not implicit, and just getters for the properties they would emitted in arbitrary order again. While this should not matter I guess... it definitely does, as fixing the order of this causes `irgen::forEachField` to emit them in the right order always. I have confirmed this in a real project where the types in IRGen now align and are consistently correct: ``` -> % cat main.ir | grep Worker | grep '= type <' %T3Lib19Worker_OTHER_MODULEC = type <{ %swift.refcounted, %swift.defaultactor, %T3Lib20THE_ACTOR_IDENTIFIERV, %T3Lib12SampleSystemC* }> -> % cat othermodule.ir | grep Worker | grep '= type <' %T3Lib19Worker_OTHER_MODULEC = type <{ %swift.refcounted, %swift.defaultactor, %T3Lib20THE_ACTOR_IDENTIFIERV, %T3Lib12SampleSystemC* }> ``` I am not very sure how to write a test covering this but will try to do this next as we would not want to regress this under any circumstances.
1 parent 42475c5 commit 6d6fa37

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

lib/Sema/TypeCheckStorage.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,12 @@ static void enumerateStoredPropertiesAndMissing(
165165
ASTContext &ctx = decl->getASTContext();
166166
for (auto *member : decl->getMembers()) {
167167
if (auto *var = dyn_cast<VarDecl>(member)) {
168-
if (!var->isStatic() && var->hasStorage() &&
169-
var->isSynthesized()) {
170-
if (var->getName() == ctx.Id_id)
168+
if (!var->isStatic() && var->hasStorage()) {
169+
if (var->getName() == ctx.Id_id) {
171170
distributedActorId = var;
172-
else if (var->getName() == ctx.Id_actorSystem)
171+
} else if (var->getName() == ctx.Id_actorSystem) {
173172
distributedActorSystem = var;
173+
}
174174
}
175175

176176
if (distributedActorId && distributedActorSystem)
@@ -186,9 +186,13 @@ static void enumerateStoredPropertiesAndMissing(
186186

187187
for (auto *member : decl->getMembers()) {
188188
if (auto *var = dyn_cast<VarDecl>(member)) {
189-
if (!var->isStatic() && var->hasStorage() &&
190-
var != distributedActorId &&
191-
var != distributedActorSystem) {
189+
if (!var->isStatic() && var->hasStorage()) {
190+
// Skip any properties that we already emitted explicitly
191+
if (var == distributedActorId)
192+
continue;
193+
if (var == distributedActorSystem)
194+
continue;
195+
192196
addStoredProperty(var);
193197
}
194198
}

0 commit comments

Comments
 (0)