Skip to content

[6.2][Distributed] fix distributed thunk method descriptor mangling in IRGen #81831

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/IRGen/IRGenMangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class IRGenMangler : public Mangle::ASTMangler {
beginMangling();
appendEntity(func);
appendOperator("Tj");
if (func->isDistributedThunk())
appendSymbolKind(SymbolKind::DistributedThunk);
return finalize();
}

Expand Down Expand Up @@ -86,6 +88,8 @@ class IRGenMangler : public Mangle::ASTMangler {
beginMangling();
appendEntity(func);
appendOperator("Tq");
if (func->isDistributedThunk())
appendSymbolKind(SymbolKind::DistributedThunk);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"the fix"

return finalize();
}

Expand Down
16 changes: 16 additions & 0 deletions lib/SIL/IR/SILPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,27 @@ void SILDeclRef::print(raw_ostream &OS) const {
auto *accessor = dyn_cast<AccessorDecl>(getDecl());
if (!accessor) {
printValueDecl(getDecl(), OS);
if (isDistributed()) {
OS << "!distributed";
OS << "(" << getDecl() << ")";
}
if (isDistributedThunk()) {
OS << "!distributed_thunk";
OS << "(" << getDecl() << ")";
}
isDot = false;
break;
}

printValueDecl(accessor->getStorage(), OS);
if (isDistributed()) {
OS << "!distributed";
OS << "(" << getDecl() << ")";
}
if (isDistributedThunk()) {
OS << "!distributed_thunk";
OS << "(" << getDecl() << ")";
}
switch (accessor->getAccessorKind()) {
case AccessorKind::WillSet:
OS << "!willSet";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
// RUN: %empty-directory(%t/src)
// RUN: split-file %s %t/src

/// Build the fake actor systems lib
// RUN: %target-build-swift \
// RUN: -target %target-swift-6.0-abi-triple \
// RUN: -parse-as-library -emit-library \
// RUN: -emit-module-path %t/FakeDistributedActorSystems.swiftmodule \
// RUN: -module-name FakeDistributedActorSystems \
// RUN: %S/../Inputs/FakeDistributedActorSystems.swift \
// RUN: -enable-library-evolution \
// RUN: -Xfrontend -validate-tbd-against-ir=all \
// RUN: -o %t/%target-library-name(FakeDistributedActorSystems)

/// Build the ResilientAPILib
// RUN: %target-build-swift \
// RUN: -target %target-swift-6.0-abi-triple \
// RUN: -parse-as-library -emit-library \
// RUN: -emit-module-path %t/ResilientAPILib.swiftmodule \
// RUN: -module-name ResilientAPILib \
// RUN: -I %t \
// RUN: -L %t \
// RUN: -plugin-path %swift-plugin-dir \
// RUN: %t/src/ResilientAPILib.swift \
// RUN: %t/src/ResilientAPILibFile2.swift \
// RUN: -lFakeDistributedActorSystems \
// RUN: -enable-library-evolution \
// RUN: -Xfrontend -validate-tbd-against-ir=all \
// RUN: -o %t/%target-library-name(ResilientAPILib)

/// Build the ResilientImplLib
// RUN: %target-build-swift \
// RUN: -target %target-swift-6.0-abi-triple \
// RUN: -parse-as-library -emit-library \
// RUN: -module-name ResilientImplLib \
// RUN: -I %t \
// RUN: -L %t \
// RUN: -plugin-path %swift-plugin-dir \
// RUN: %t/src/ResilientImplLib.swift \
// RUN: -lFakeDistributedActorSystems \
// RUN: -lResilientAPILib \
// RUN: -enable-library-evolution \
// RUN: -Xfrontend -validate-tbd-against-ir=all \
// RUN: -emit-irgen \
// RUN: | %FileCheck %s --color --dump-input=always

// REQUIRES: executable_test
// REQUIRES: concurrency
// REQUIRES: distributed

// Locating the built libraries failed on Linux (construction of test case),
// but we primarily care about macOS in this test
// UNSUPPORTED: OS=linux-gnu

// %env does not seem to work on Windows
// UNSUPPORTED: OS=windows-msvc

// UNSUPPORTED: use_os_stdlib
// UNSUPPORTED: back_deployment_runtime
// UNSUPPORTED: remote_run || device_run

//--- ResilientAPILib.swift

import Distributed
import FakeDistributedActorSystems

@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
public struct Response: Codable {}

@Resolvable
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
public protocol DistributedNotificationService: DistributedActor where ActorSystem == FakeRoundtripActorSystem {
distributed func getArray(a1: [Int], a2: String?) -> [Response]
}

public protocol IdentifiableActor {
static var actorID: FakeRoundtripActorSystem.ActorID { get }
}

//--- ResilientAPILibFile2.swift

final class Another { }

//--- ResilientImplLib.swift

import ResilientAPILib

import Distributed
import FakeDistributedActorSystems

@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
public distributed actor ServiceImpl: DistributedNotificationService, IdentifiableActor {
public typealias ActorSystem = FakeRoundtripActorSystem

public static var actorID: FakeRoundtripActorSystem.ActorID {
.init(parse: "test")
}

public distributed func getArray(a1: [Int], a2: String?) -> [Response] {
[]
}
}

extension ServiceImpl {}

//--- ResilientImplLibFile2.swift

class AnotherImpl {}


// @"protocol conformance descriptor for ResilientImplLib.ServiceImpl : ResilientAPILib.DistributedNotificationService in ResilientImplLib" = constant {
// CHECK: @"$s16ResilientImplLib07ServiceB0C0A6APILib023DistributedNotificationD0AAMc" = constant {
// CHECK-SAME: i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i32, i32
// CHECK-SAME: } {
// CHECK-SAME: i32 add (
// CHECK-SAME: i32 trunc (
// CHECK-SAME: i64 sub (
// i64 ptrtoint (ptr @"got.protocol descriptor for ResilientAPILib.DistributedNotificationService" to i64),
// CHECK-SAME: i64 ptrtoint (ptr @"got.$s15ResilientAPILib30DistributedNotificationServiceMp" to i64),
// i64 ptrtoint (ptr @"protocol conformance descriptor for ResilientImplLib.ServiceImpl : ResilientAPILib.DistributedNotificationService in ResilientImplLib" to i64)
// CHECK-SAME: i64 ptrtoint (ptr @"$s16ResilientImplLib07ServiceB0C0A6APILib023DistributedNotificationD0AAMc" to i64)
// CHECK-SAME: ) to i32
// CHECK-SAME: ),
// CHECK-SAME: i32 1
// CHECK-SAME: ),
//
// CHECK-SAME: i32 trunc (
// CHECK-SAME: i64 sub (
// i64 ptrtoint (ptr @"nominal type descriptor for ResilientImplLib.ServiceImpl" to i64),
// CHECK-SAME: i64 ptrtoint (ptr @"$s16ResilientImplLib07ServiceB0CMn" to i64),
// CHECK-SAME: i64 ptrtoint (ptr getelementptr inbounds (
// CHECK-SAME: { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i32, i32 },
// CHECK-SAME: ptr @"$s16ResilientImplLib07ServiceB0C0A6APILib023DistributedNotificationD0AAMc",
// CHECK-SAME: i32 0, i32 1
// CHECK-SAME: ) to i64)
// CHECK-SAME: ) to i32
// CHECK-SAME: ),
//
// CHECK-SAME: i32 0,
// CHECK-SAME: i32 196608,
// CHECK-SAME: i32 3,
//
// CHECK-SAME: i32 add (
// CHECK-SAME: i32 trunc (
// CHECK-SAME: i64 sub (
// i64 ptrtoint (ptr @"got.base conformance descriptor for ResilientAPILib.DistributedNotificationService: Distributed.DistributedActor" to i64),
// CHECK-SAME: i64 ptrtoint (ptr @"got.$s15ResilientAPILib30DistributedNotificationServiceP0C00C5ActorTb" to i64),
// CHECK-SAME: i64 ptrtoint (ptr getelementptr inbounds (
// CHECK-SAME: { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i32, i32 },
// CHECK-SAME: ptr @"$s16ResilientImplLib07ServiceB0C0A6APILib023DistributedNotificationD0AAMc",
// CHECK-SAME: i32 0, i32 5
// CHECK-SAME: ) to i64)
// CHECK-SAME: ) to i32
// CHECK-SAME: ),
// CHECK-SAME: i32 1
// CHECK-SAME: ),
//
// CHECK-SAME: i32 trunc (
// CHECK-SAME: i64 sub (
// CHECK-SAME: i64 ptrtoint (ptr getelementptr (
// CHECK-SAME: i8, ptr @"associated conformance 16ResilientImplLib07ServiceB0C0A6APILib023DistributedNotificationD0AA0F00F5Actor",
// CHECK-SAME: i64 1
// CHECK-SAME: ) to i64),
// CHECK-SAME: i64 ptrtoint (ptr getelementptr inbounds (
// CHECK-SAME: { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i32, i32 },
// CHECK-SAME: ptr @"$s16ResilientImplLib07ServiceB0C0A6APILib023DistributedNotificationD0AAMc",
// CHECK-SAME: i32 0, i32 6
// CHECK-SAME: ) to i64)
// CHECK-SAME: ) to i32
// CHECK-SAME: ),
//
// CHECK-SAME: i32 add (
// CHECK-SAME: i32 trunc (
// CHECK-SAME: i64 sub (
// i64 ptrtoint (ptr @"got.method descriptor for ResilientAPILib.DistributedNotificationService.getArray(a1: [Swift.Int], a2: Swift.String?) -> [ResilientAPILib.Response]" to i64),
// CHECK-SAME: i64 ptrtoint (ptr @"got.$s15ResilientAPILib30DistributedNotificationServiceP8getArray2a12a2SayAA8ResponseVGSaySiG_SSSgtFTq" to i64),
// CHECK-SAME: i64 ptrtoint (ptr getelementptr inbounds (
// CHECK-SAME: { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i32, i32 },
// CHECK-SAME: ptr @"$s16ResilientImplLib07ServiceB0C0A6APILib023DistributedNotificationD0AAMc",
// CHECK-SAME: i32 0, i32 7
// CHECK-SAME: ) to i64)
// CHECK-SAME: ) to i32
// CHECK-SAME: ),
// CHECK-SAME: i32 1
// CHECK-SAME: ),
//
// CHECK-SAME: i32 trunc (
// CHECK-SAME: i64 sub (
// i64 ptrtoint (ptr @"protocol witness for ResilientAPILib.DistributedNotificationService.getArray(a1: [Swift.Int], a2: Swift.String?) -> [ResilientAPILib.Response] in conformance ResilientImplLib.ServiceImpl : ResilientAPILib.DistributedNotificationService in ResilientImplLib" to i64),
// CHECK-SAME: i64 ptrtoint (ptr @"$s16ResilientImplLib07ServiceB0C0A6APILib023DistributedNotificationD0AadEP8getArray2a12a2SayAD8ResponseVGSaySiG_SSSgtFTW" to i64),
// CHECK-SAME: i64 ptrtoint (ptr getelementptr inbounds (
// CHECK-SAME: { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i32, i32 },
// ptr @"protocol conformance descriptor for ResilientImplLib.ServiceImpl : ResilientAPILib.DistributedNotificationService in ResilientImplLib",
// CHECK-SAME: ptr @"$s16ResilientImplLib07ServiceB0C0A6APILib023DistributedNotificationD0AAMc",
// CHECK-SAME: i32 0, i32 8
// CHECK-SAME: ) to i64)
// CHECK-SAME: ) to i32
// CHECK-SAME: ),
//
// THIS ONE HAS .7 IN OUR REAL EXAMPLE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// CHECK-SAME: i32 add (
// CHECK-SAME: i32 trunc (
// CHECK-SAME: i64 sub (
// i64 ptrtoint (ptr @"got.method descriptor for ResilientAPILib.DistributedNotificationService.getArray(a1: [Swift.Int], a2: Swift.String?) async throws -> [ResilientAPILib.Response]" to i64),
// CHECK-SAME: i64 ptrtoint (ptr @"got.$s15ResilientAPILib30DistributedNotificationServiceP8getArray2a12a2SayAA8ResponseVGSaySiG_SSSgtYaKFTqTE" to i64),
// CHECK-SAME: i64 ptrtoint (ptr getelementptr inbounds (
// CHECK-SAME: { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i32, i32 },
// ptr @"protocol conformance descriptor for ResilientImplLib.ServiceImpl : ResilientAPILib.DistributedNotificationService in ResilientImplLib",
// CHECK-SAME: ptr @"$s16ResilientImplLib07ServiceB0C0A6APILib023DistributedNotificationD0AAMc",
// CHECK-SAME: i32 0, i32 9
// CHECK-SAME: ) to i64)
// CHECK-SAME: ) to i32
// CHECK-SAME: ),
// CHECK-SAME: i32 1
// CHECK-SAME: ),
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
//
// CHECK-SAME: i32 trunc (
// CHECK-SAME: i64 sub (
// i64 ptrtoint (ptr @"async function pointer to distributed thunk protocol witness for ResilientAPILib.DistributedNotificationService.getArray(a1: [Swift.Int], a2: Swift.String?) async throws -> [ResilientAPILib.Response] in conformance ResilientImplLib.ServiceImpl : ResilientAPILib.DistributedNotificationService in ResilientImplLib" to i64),
// CHECK-SAME: i64 ptrtoint (ptr @"$s16ResilientImplLib07ServiceB0C0A6APILib023DistributedNotificationD0AadEP8getArray2a12a2SayAD8ResponseVGSaySiG_SSSgtYaKFTWTETu" to i64),
// CHECK-SAME: i64 ptrtoint (ptr getelementptr inbounds (
// CHECK-SAME: { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i32, i32 },
// ptr @"protocol conformance descriptor for ResilientImplLib.ServiceImpl : ResilientAPILib.DistributedNotificationService in ResilientImplLib",
// CHECK-SAME: ptr @"$s16ResilientImplLib07ServiceB0C0A6APILib023DistributedNotificationD0AAMc",
// CHECK-SAME: i32 0, i32 10
// CHECK-SAME: ) to i64)
// CHECK-SAME: ) to i32
// CHECK-SAME: ),
//
// CHECK-SAME: i16 0,
// CHECK-SAME: i16 1,
// CHECK-SAME: i32 0,
//
// CHECK-SAME: i32 trunc (
// CHECK-SAME: i64 sub (
// i64 ptrtoint (ptr @"metadata instantiation cache for protocol conformance descriptor for ResilientImplLib.ServiceImpl : ResilientAPILib.DistributedNotificationService in ResilientImplLib" to i64),
// CHECK-SAME: i64 ptrtoint (ptr @"$s16ResilientImplLib07ServiceB0C0A6APILib023DistributedNotificationD0AAMcMK" to i64),
// CHECK-SAME: i64 ptrtoint (ptr getelementptr inbounds (
// CHECK-SAME: { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i32, i32 },
// ptr @"protocol conformance descriptor for ResilientImplLib.ServiceImpl : ResilientAPILib.DistributedNotificationService in ResilientImplLib",
// CHECK-SAME: ptr @"$s16ResilientImplLib07ServiceB0C0A6APILib023DistributedNotificationD0AAMc",
// CHECK-SAME: i32 0, i32 14
// CHECK-SAME: ) to i64)
// CHECK-SAME: ) to i32
// CHECK-SAME: )
// CHECK-SAME: }, section "__TEXT,__const", no_sanitize_address, align 4