From 47684cb2a1527eb419cd2104288671e3a7264ac8 Mon Sep 17 00:00:00 2001 From: Pavel Yaskevich Date: Fri, 22 Aug 2025 13:59:31 -0700 Subject: [PATCH 1/2] Revert "AST: Re-enable TypeSubstituter::transformSubstitutionMap() again" This reverts commit 81bf4490aebecb976ea792405385a7268fc6e710. --- lib/AST/TypeSubstitution.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/AST/TypeSubstitution.cpp b/lib/AST/TypeSubstitution.cpp index f7b1f8c62ca6d..0749288f2e7e5 100644 --- a/lib/AST/TypeSubstitution.cpp +++ b/lib/AST/TypeSubstitution.cpp @@ -358,7 +358,7 @@ class TypeSubstituter : public TypeTransform { std::optional transformLocalArchetypeType(LocalArchetypeType *local, TypePosition pos); - SubstitutionMap transformSubstitutionMap(SubstitutionMap subs); + // SubstitutionMap transformSubstitutionMap(SubstitutionMap subs); CanType transformSILField(CanType fieldTy, TypePosition pos); }; @@ -474,10 +474,13 @@ Type TypeSubstituter::transformDependentMemberType(DependentMemberType *dependen return result; } +// FIXME: This exposes a scalability issue; see test/SILGen/opaque_result_type_slow.swift. +/* SubstitutionMap TypeSubstituter::transformSubstitutionMap(SubstitutionMap subs) { // FIXME: Take level into account? Move level down into IFS? return subs.subst(IFS); } +*/ CanType TypeSubstituter::transformSILField(CanType fieldTy, TypePosition pos) { // Type substitution does not walk into the SILBoxType's field types, because From beb05fb3d02424c4cbca2212ce1353a429bc45a2 Mon Sep 17 00:00:00 2001 From: Pavel Yaskevich Date: Fri, 22 Aug 2025 14:00:31 -0700 Subject: [PATCH 2/2] [Tests] NFC: Add a test-case for regression when `TypeSubstituter::transformSubstitutionMap()` is enabled --- test/Generics/rdar158774099.swift | 74 +++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 test/Generics/rdar158774099.swift diff --git a/test/Generics/rdar158774099.swift b/test/Generics/rdar158774099.swift new file mode 100644 index 0000000000000..d4c824f3a7cb6 --- /dev/null +++ b/test/Generics/rdar158774099.swift @@ -0,0 +1,74 @@ +// RUN: %empty-directory(%t) +// RUN: split-file %s %t + +// RUN: %target-swift-frontend -typecheck -verify \ +// RUN: %t/View.swift %t/Modifier.swift %t/MyStorage.swift %t/Storage.swift %t/WrappedStorage.swift + +//--- Storage.swift + +protocol Representable { + associatedtype Outputs + typealias Context = RepresentableContext +} + +struct RepresentableContext {} + +struct Inputs { +} + +protocol Storage { + associatedtype Value + associatedtype R: Representable + + func body(content: Content) -> Value + + typealias Content = Inputs +} + +//--- WrappedStorage.swift +private struct WrappedStorage: Storage where Base.Value == MyStorage.Value { + typealias R = Base.R + + init(base: Base, body: @escaping (Base.Value) -> Void) { + } + + func body(content: Content) -> Base.Value { fatalError() } +} + +extension Storage where Value == MyStorage.Value { + func withStorage(body: @escaping (Value) -> Void) -> some Storage { + WrappedStorage(base: self, body: body) + } +} + +//--- MyStorage.swift +struct MyRepresentable: Representable { + struct Outputs {} +} + +struct MyStorage: Storage { + typealias R = MyRepresentable + + struct Value: Equatable {} + + func body(content: Content) -> Value { + fatalError() + } +} + +//--- Modifier.swift +extension P { + func storage(_: some Storage) -> some P { Test() } +} + +//--- View.swift +protocol P { +} + +struct Test: P { +} + +func test() -> some P { + let storage = MyStorage().withStorage { value in } + return Test().storage(storage) +}