@@ -750,10 +750,10 @@ Type TypeBase::getRValueType() {
750750 if (!hasLValueType ())
751751 return this ;
752752
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))
755755 return lvalueTy->getObjectType ();
756- return t ;
756+ return std:: nullopt ;
757757 });
758758}
759759
@@ -1863,7 +1863,7 @@ CanType TypeBase::getReducedType(GenericSignature sig) {
18631863}
18641864
18651865CanType 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> {
18671867 const CanType CanTy = CanType (Ty);
18681868
18691869 if (const auto ET = dyn_cast<ExistentialType>(CanTy)) {
@@ -1899,15 +1899,15 @@ CanType TypeBase::getMinimalCanonicalType(const DeclContext *useDC) const {
18991899 return Composition->getMinimalCanonicalType (useDC);
19001900 }
19011901
1902- return CanTy ;
1902+ return std:: nullopt ;
19031903 });
19041904
19051905 return CanType (MinimalTy);
19061906}
19071907
19081908TypeBase *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)) {
19111911
19121912 auto getGenericArg = [&](unsigned i) -> Type {
19131913 auto arg = boundGeneric->getGenericArgs ()[i];
@@ -1917,27 +1917,30 @@ TypeBase *TypeBase::reconstituteSugar(bool Recursive) {
19171917 };
19181918
19191919 if (boundGeneric->isArray ())
1920- return ArraySliceType::get (getGenericArg (0 ));
1920+ return Type ( ArraySliceType::get (getGenericArg (0 ) ));
19211921 if (boundGeneric->isDictionary ())
1922- return DictionaryType::get (getGenericArg (0 ), getGenericArg (1 ));
1922+ return Type ( DictionaryType::get (getGenericArg (0 ), getGenericArg (1 ) ));
19231923 if (boundGeneric->isOptional ())
1924- return OptionalType::get (getGenericArg (0 ));
1924+ return Type ( OptionalType::get (getGenericArg (0 ) ));
19251925 }
1926- return Ty ;
1926+ return std:: nullopt ;
19271927 };
19281928 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 ;
19321935}
19331936
19341937TypeBase *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))
19371940 return syntaxSugarType->getSinglyDesugaredType ()->getWithoutSyntaxSugar ();
1938- return Ty ;
1941+ return std:: nullopt ;
19391942 };
1940- return Type (this ).transform (Func).getPointer ();
1943+ return Type (this ).transformRec (Func).getPointer ();
19411944}
19421945
19431946#define TYPE (Id, Parent )
@@ -4156,23 +4159,6 @@ static bool transformSILParameter(
41564159 return false ;
41574160}
41584161
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-
41764162static PackType *getTransformedPack (Type substType) {
41774163 if (auto pack = substType->getAs <PackType>()) {
41784164 return pack;
0 commit comments