@@ -750,10 +750,10 @@ Type TypeBase::getRValueType() {
750
750
if (!hasLValueType ())
751
751
return this ;
752
752
753
- return Type (this ).transform ([](Type t) -> Type {
754
- if (auto *lvalueTy = dyn_cast<LValueType>(t. getPointer () ))
753
+ return Type (this ).transformRec ([](TypeBase * t) -> std::optional< Type> {
754
+ if (auto *lvalueTy = dyn_cast<LValueType>(t))
755
755
return lvalueTy->getObjectType ();
756
- return t ;
756
+ return std:: nullopt ;
757
757
});
758
758
}
759
759
@@ -1863,7 +1863,7 @@ CanType TypeBase::getReducedType(GenericSignature sig) {
1863
1863
}
1864
1864
1865
1865
CanType TypeBase::getMinimalCanonicalType (const DeclContext *useDC) const {
1866
- const auto MinimalTy = getCanonicalType ().transform ([useDC](Type Ty) -> Type {
1866
+ const auto MinimalTy = getCanonicalType ().transformRec ([useDC](TypeBase * Ty) -> std::optional< Type> {
1867
1867
const CanType CanTy = CanType (Ty);
1868
1868
1869
1869
if (const auto ET = dyn_cast<ExistentialType>(CanTy)) {
@@ -1899,15 +1899,15 @@ CanType TypeBase::getMinimalCanonicalType(const DeclContext *useDC) const {
1899
1899
return Composition->getMinimalCanonicalType (useDC);
1900
1900
}
1901
1901
1902
- return CanTy ;
1902
+ return std:: nullopt ;
1903
1903
});
1904
1904
1905
1905
return CanType (MinimalTy);
1906
1906
}
1907
1907
1908
1908
TypeBase *TypeBase::reconstituteSugar (bool Recursive) {
1909
- auto Func = [Recursive](Type Ty) -> Type {
1910
- if (auto boundGeneric = dyn_cast<BoundGenericType>(Ty. getPointer () )) {
1909
+ auto Func = [Recursive](TypeBase * Ty) -> std::optional< Type> {
1910
+ if (auto boundGeneric = dyn_cast<BoundGenericType>(Ty)) {
1911
1911
1912
1912
auto getGenericArg = [&](unsigned i) -> Type {
1913
1913
auto arg = boundGeneric->getGenericArgs ()[i];
@@ -1917,27 +1917,30 @@ TypeBase *TypeBase::reconstituteSugar(bool Recursive) {
1917
1917
};
1918
1918
1919
1919
if (boundGeneric->isArray ())
1920
- return ArraySliceType::get (getGenericArg (0 ));
1920
+ return Type ( ArraySliceType::get (getGenericArg (0 ) ));
1921
1921
if (boundGeneric->isDictionary ())
1922
- return DictionaryType::get (getGenericArg (0 ), getGenericArg (1 ));
1922
+ return Type ( DictionaryType::get (getGenericArg (0 ), getGenericArg (1 ) ));
1923
1923
if (boundGeneric->isOptional ())
1924
- return OptionalType::get (getGenericArg (0 ));
1924
+ return Type ( OptionalType::get (getGenericArg (0 ) ));
1925
1925
}
1926
- return Ty ;
1926
+ return std:: nullopt ;
1927
1927
};
1928
1928
if (Recursive)
1929
- return Type (this ).transform (Func).getPointer ();
1930
- else
1931
- return Func (this ).getPointer ();
1929
+ return Type (this ).transformRec (Func).getPointer ();
1930
+
1931
+ if (auto result = Func (this ))
1932
+ return result->getPointer ();
1933
+
1934
+ return this ;
1932
1935
}
1933
1936
1934
1937
TypeBase *TypeBase::getWithoutSyntaxSugar () {
1935
- auto Func = [](Type Ty) -> Type {
1936
- if (auto *syntaxSugarType = dyn_cast<SyntaxSugarType>(Ty. getPointer () ))
1938
+ auto Func = [](TypeBase * Ty) -> std::optional< Type> {
1939
+ if (auto *syntaxSugarType = dyn_cast<SyntaxSugarType>(Ty))
1937
1940
return syntaxSugarType->getSinglyDesugaredType ()->getWithoutSyntaxSugar ();
1938
- return Ty ;
1941
+ return std:: nullopt ;
1939
1942
};
1940
- return Type (this ).transform (Func).getPointer ();
1943
+ return Type (this ).transformRec (Func).getPointer ();
1941
1944
}
1942
1945
1943
1946
#define TYPE (Id, Parent )
@@ -4156,23 +4159,6 @@ static bool transformSILParameter(
4156
4159
return false ;
4157
4160
}
4158
4161
4159
- Type Type::transform (llvm::function_ref<Type(Type)> fn) const {
4160
- return transformWithPosition (
4161
- TypePosition::Invariant,
4162
- [fn](TypeBase *type, auto ) -> std::optional<Type> {
4163
- Type transformed = fn (Type (type));
4164
- if (!transformed)
4165
- return Type ();
4166
-
4167
- // If the function didn't change the type at
4168
- // all, let transformRec() recurse.
4169
- if (transformed.getPointer () == type)
4170
- return std::nullopt ;
4171
-
4172
- return transformed;
4173
- });
4174
- }
4175
-
4176
4162
static PackType *getTransformedPack (Type substType) {
4177
4163
if (auto pack = substType->getAs <PackType>()) {
4178
4164
return pack;
0 commit comments