From dea74135356745b7da1068056690a06fa834da7a Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 8 Oct 2025 15:52:45 -0400 Subject: [PATCH 1/2] SIL: The inner type of a SILMoveOnlyWrappedType is a lowered position Fixes rdar://161968922. --- lib/SIL/IR/SILTypeSubstitution.cpp | 8 ++++++++ .../specialize_move_only_wrapped_type.swift | 15 +++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 test/SILOptimizer/specialize_move_only_wrapped_type.swift diff --git a/lib/SIL/IR/SILTypeSubstitution.cpp b/lib/SIL/IR/SILTypeSubstitution.cpp index bd3e5718c6846..dab536f664c83 100644 --- a/lib/SIL/IR/SILTypeSubstitution.cpp +++ b/lib/SIL/IR/SILTypeSubstitution.cpp @@ -420,6 +420,14 @@ class SILTypeSubstituter : substObjectType)); } + /// MoveOnlyWrappedTypes need to have their inner types substituted + /// by these rules. + CanType visitSILMoveOnlyWrappedType(CanSILMoveOnlyWrappedType origType) { + CanType origInnerType = origType->getInnerType(); + CanType substInnerType = visit(origInnerType); + return CanType(SILMoveOnlyWrappedType::get(substInnerType)); + } + /// Any other type would be a valid type in the AST. Just apply the /// substitution on the AST level and then lower that. CanType visitType(CanType origType) { diff --git a/test/SILOptimizer/specialize_move_only_wrapped_type.swift b/test/SILOptimizer/specialize_move_only_wrapped_type.swift new file mode 100644 index 0000000000000..d6c36f4fd47f0 --- /dev/null +++ b/test/SILOptimizer/specialize_move_only_wrapped_type.swift @@ -0,0 +1,15 @@ +// RUN: %target-swift-frontend -emit-sil -O %s + +public struct Mutex { + public init(_: T) {} +} + +public struct Locked { + public let mutex: Mutex + + public init(_ rawValue: consuming T) { + mutex = Mutex(rawValue) + } +} + +_ = Locked { } From b55a141d7b6cc6a5edf05ee4101d2ab518eb0e0e Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 8 Oct 2025 15:53:11 -0400 Subject: [PATCH 2/2] SIL: Upgrade assert() to ASSERT() --- include/swift/SIL/SILType.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/swift/SIL/SILType.h b/include/swift/SIL/SILType.h index 41fdfae5daba3..de96a05269914 100644 --- a/include/swift/SIL/SILType.h +++ b/include/swift/SIL/SILType.h @@ -20,6 +20,7 @@ #include "swift/AST/SILLayout.h" #include "swift/AST/Types.h" +#include "swift/Basic/Assertions.h" #include "swift/SIL/AbstractionPattern.h" #include "swift/SIL/Lifetime.h" #include "llvm/ADT/Hashing.h" @@ -109,7 +110,7 @@ class SILType { SILType(CanType ty, SILValueCategory category) : value(ty.getPointer(), unsigned(category)) { if (!ty) return; - assert(ty->isLegalSILType() && + ASSERT(ty->isLegalSILType() && "constructing SILType with type that should have been " "eliminated by SIL lowering"); }