mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[cxx-interop] Disambiguate template instantiations with array type parameters
When Swift imports C++ template class instantiations, it generates a human-readable Swift name for each instantiation. Having name collisions causes multiple Swift type with the same name, which confuses the compiler. `MyClass<int[]>` and `MyClass<long[]>` were both being imported as `MyClass<_>` into Swift. This patch fixes that: * `MyClass<int[]>` is now imported as `MyClass<[CInt]>` * `MyClass<int[123]>` is now imported as `MyClass<Vector<CInt, 123>>` rdar://138921102
This commit is contained in:
@@ -137,6 +137,17 @@ struct TemplateInstantiationNamePrinter
|
|||||||
Visit(type->getElementType().getTypePtr()) + ">")
|
Visit(type->getElementType().getTypePtr()) + ">")
|
||||||
.str();
|
.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string VisitArrayType(const clang::ArrayType *type) {
|
||||||
|
return (Twine("[") + Visit(type->getElementType().getTypePtr()) + "]")
|
||||||
|
.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string VisitConstantArrayType(const clang::ConstantArrayType *type) {
|
||||||
|
return (Twine("Vector<") + Visit(type->getElementType().getTypePtr()) +
|
||||||
|
", " + std::to_string(type->getSExtSize()) + ">")
|
||||||
|
.str();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string swift::importer::printClassTemplateSpecializationName(
|
std::string swift::importer::printClassTemplateSpecializationName(
|
||||||
|
|||||||
@@ -19,11 +19,19 @@ typedef MagicWrapper<const long> WrappedMagicLongConst;
|
|||||||
typedef MagicWrapper<int*> WrappedMagicIntPtr;
|
typedef MagicWrapper<int*> WrappedMagicIntPtr;
|
||||||
typedef MagicWrapper<const int*> WrappedMagicIntConstPtr;
|
typedef MagicWrapper<const int*> WrappedMagicIntConstPtr;
|
||||||
typedef MagicWrapper<int**> WrappedMagicIntPtrPtr;
|
typedef MagicWrapper<int**> WrappedMagicIntPtrPtr;
|
||||||
|
typedef MagicWrapper<int[]> WrappedMagicIntArr;
|
||||||
|
typedef MagicWrapper<long[]> WrappedMagicLongArr;
|
||||||
|
typedef MagicWrapper<int[123]> WrappedMagicIntFixedSizeArr1;
|
||||||
|
typedef MagicWrapper<int[124]> WrappedMagicIntFixedSizeArr2;
|
||||||
|
|
||||||
typedef DoubleWrapper<MagicWrapper<int>> DoubleWrappedInt;
|
typedef DoubleWrapper<MagicWrapper<int>> DoubleWrappedInt;
|
||||||
typedef DoubleWrapper<MagicWrapper<const int>> DoubleWrappedIntConst;
|
typedef DoubleWrapper<MagicWrapper<const int>> DoubleWrappedIntConst;
|
||||||
typedef DoubleWrapper<MagicWrapper<const long>> DoubleWrappedLongConst;
|
typedef DoubleWrapper<MagicWrapper<const long>> DoubleWrappedLongConst;
|
||||||
typedef DoubleWrapper<MagicWrapper<int*>> DoubleWrappedIntPtr;
|
typedef DoubleWrapper<MagicWrapper<int*>> DoubleWrappedIntPtr;
|
||||||
typedef DoubleWrapper<MagicWrapper<const int*>> DoubleWrappedIntConstPtr;
|
typedef DoubleWrapper<MagicWrapper<const int*>> DoubleWrappedIntConstPtr;
|
||||||
|
typedef DoubleWrapper<MagicWrapper<int[]>> DoubleWrappedMagicIntArr;
|
||||||
|
typedef DoubleWrapper<MagicWrapper<long[]>> DoubleWrappedMagicLongArr;
|
||||||
|
typedef DoubleWrapper<MagicWrapper<int[42]>> DoubleWrappedMagicIntFixedSizeArr1;
|
||||||
|
typedef DoubleWrapper<MagicWrapper<int[43]>> DoubleWrappedMagicIntFixedSizeArr2;
|
||||||
|
|
||||||
#endif // TEST_INTEROP_CXX_TEMPLATES_INPUTS_CLASS_TEMPLATE_WITH_PRIMITIVE_ARGUMENT_H
|
#endif // TEST_INTEROP_CXX_TEMPLATES_INPUTS_CLASS_TEMPLATE_WITH_PRIMITIVE_ARGUMENT_H
|
||||||
|
|||||||
@@ -13,9 +13,17 @@
|
|||||||
// CHECK: typealias WrappedMagicIntPtr = MagicWrapper<UnsafeMutablePointer<CInt>>
|
// CHECK: typealias WrappedMagicIntPtr = MagicWrapper<UnsafeMutablePointer<CInt>>
|
||||||
// CHECK: typealias WrappedMagicIntConstPtr = MagicWrapper<UnsafePointer<CInt>>
|
// CHECK: typealias WrappedMagicIntConstPtr = MagicWrapper<UnsafePointer<CInt>>
|
||||||
// CHECK: typealias WrappedMagicIntPtrPtr = MagicWrapper<UnsafeMutablePointer<UnsafeMutablePointer<CInt>>>
|
// CHECK: typealias WrappedMagicIntPtrPtr = MagicWrapper<UnsafeMutablePointer<UnsafeMutablePointer<CInt>>>
|
||||||
|
// CHECK: typealias WrappedMagicIntArr = MagicWrapper<[CInt]>
|
||||||
|
// CHECK: typealias WrappedMagicLongArr = MagicWrapper<[CLong]>
|
||||||
|
// CHECK: typealias WrappedMagicIntFixedSizeArr1 = MagicWrapper<Vector<CInt, 123>>
|
||||||
|
// CHECK: typealias WrappedMagicIntFixedSizeArr2 = MagicWrapper<Vector<CInt, 124>>
|
||||||
|
|
||||||
// CHECK: typealias DoubleWrappedInt = DoubleWrapper<MagicWrapper<CInt>>
|
// CHECK: typealias DoubleWrappedInt = DoubleWrapper<MagicWrapper<CInt>>
|
||||||
// CHECK: typealias DoubleWrappedIntConst = DoubleWrapper<MagicWrapper<CInt_const>>
|
// CHECK: typealias DoubleWrappedIntConst = DoubleWrapper<MagicWrapper<CInt_const>>
|
||||||
// CHECK: typealias DoubleWrappedLongConst = DoubleWrapper<MagicWrapper<CLong_const>>
|
// CHECK: typealias DoubleWrappedLongConst = DoubleWrapper<MagicWrapper<CLong_const>>
|
||||||
// CHECK: typealias DoubleWrappedIntPtr = DoubleWrapper<MagicWrapper<UnsafeMutablePointer<CInt>>>
|
// CHECK: typealias DoubleWrappedIntPtr = DoubleWrapper<MagicWrapper<UnsafeMutablePointer<CInt>>>
|
||||||
// CHECK: typealias DoubleWrappedIntConstPtr = DoubleWrapper<MagicWrapper<UnsafePointer<CInt>>>
|
// CHECK: typealias DoubleWrappedIntConstPtr = DoubleWrapper<MagicWrapper<UnsafePointer<CInt>>>
|
||||||
|
// CHECK: typealias DoubleWrappedMagicIntArr = DoubleWrapper<MagicWrapper<[CInt]>>
|
||||||
|
// CHECK: typealias DoubleWrappedMagicLongArr = DoubleWrapper<MagicWrapper<[CLong]>>
|
||||||
|
// CHECK: typealias DoubleWrappedMagicIntFixedSizeArr1 = DoubleWrapper<MagicWrapper<Vector<CInt, 42>>>
|
||||||
|
// CHECK: typealias DoubleWrappedMagicIntFixedSizeArr2 = DoubleWrapper<MagicWrapper<Vector<CInt, 43>>>
|
||||||
|
|||||||
Reference in New Issue
Block a user