Skip to content

Commit 60c64bf

Browse files
authored
Merge pull request #27309 from jrose-apple/adjust-adjustTypeForConcreteImport
[ClangImporter] Clean up adjustTypeForConcreteImport
2 parents 46823c0 + 9592fc3 commit 60c64bf

File tree

8 files changed

+279
-307
lines changed

8 files changed

+279
-307
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3647,9 +3647,6 @@ ERROR(sugar_type_not_found,none,
36473647
"broken standard library: cannot find "
36483648
"%select{Array|Optional|ImplicitlyUnwrappedOptional|Dictionary|"
36493649
"Error}0 type", (unsigned))
3650-
ERROR(pointer_type_not_found,none,
3651-
"broken standard library: cannot find "
3652-
"%select{UnsafePointer|UnsafeMutablePointer}0 type", (unsigned))
36533650
ERROR(optional_intrinsics_not_found,none,
36543651
"broken standard library: cannot find intrinsic operations on "
36553652
"Optional<T>", ())

include/swift/AST/Types.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,12 @@ class alignas(1 << TypeAlignInBits) TypeBase {
706706
PointerTypeKind Ignore;
707707
return getAnyPointerElementType(Ignore);
708708
}
709+
710+
/// Returns a type representing a pointer to \c this.
711+
///
712+
/// \p kind must not be a raw pointer kind, since that would discard the
713+
/// current type.
714+
Type wrapInPointer(PointerTypeKind kind);
709715

710716
/// Determine whether the given type is "specialized", meaning that
711717
/// it involves generic types for which generic arguments have been provided.

lib/AST/Type.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,28 @@ Type TypeBase::getAnyPointerElementType(PointerTypeKind &PTK) {
624624
return Type();
625625
}
626626

627+
Type TypeBase::wrapInPointer(PointerTypeKind kind) {
628+
ASTContext &ctx = getASTContext();
629+
NominalTypeDecl *pointerDecl = ([&ctx, kind] {
630+
switch (kind) {
631+
case PTK_UnsafeMutableRawPointer:
632+
case PTK_UnsafeRawPointer:
633+
llvm_unreachable("these pointer types don't take arguments");
634+
case PTK_UnsafePointer:
635+
return ctx.getUnsafePointerDecl();
636+
case PTK_UnsafeMutablePointer:
637+
return ctx.getUnsafeMutablePointerDecl();
638+
case PTK_AutoreleasingUnsafeMutablePointer:
639+
return ctx.getAutoreleasingUnsafeMutablePointerDecl();
640+
}
641+
llvm_unreachable("bad kind");
642+
}());
643+
644+
assert(pointerDecl);
645+
return BoundGenericType::get(pointerDecl, /*parent*/nullptr, Type(this));
646+
}
647+
648+
627649
Type TypeBase::lookThroughAllOptionalTypes() {
628650
Type type(this);
629651
while (auto objType = type->getOptionalObjectType())

0 commit comments

Comments
 (0)