Skip to content

Commit 06a712b

Browse files
authored
Merge pull request #34957 from rjmccall/partial-async-task-is-a-job
Freeze PartialAsyncTask as a Job*
2 parents 4957a5e + ee0bb0a commit 06a712b

26 files changed

+286
-81
lines changed

docs/ABI/Mangling.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,13 +492,14 @@ Types
492492

493493
type ::= 'Bb' // Builtin.BridgeObject
494494
type ::= 'BB' // Builtin.UnsafeValueBuffer
495+
type ::= 'Bc' // Builtin.RawUnsafeContinuation
495496
type ::= 'Bf' NATURAL '_' // Builtin.Float<n>
496497
type ::= 'Bi' NATURAL '_' // Builtin.Int<n>
497498
type ::= 'BI' // Builtin.IntLiteral
499+
type ::= 'Bj' // Builtin.Job
498500
type ::= 'BO' // Builtin.UnknownObject (no longer a distinct type, but still used for AnyObject)
499501
type ::= 'Bo' // Builtin.NativeObject
500502
type ::= 'Bp' // Builtin.RawPointer
501-
type ::= 'Bc' // Builtin.RawUnsafeContinuation
502503
type ::= 'Bt' // Builtin.SILToken
503504
type ::= type 'Bv' NATURAL '_' // Builtin.Vec<n>x<type>
504505
type ::= 'Bw' // Builtin.Word

include/swift/AST/ASTContext.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -748,14 +748,10 @@ class ASTContext final {
748748
const CanType TheUnresolvedType; /// This is the UnresolvedType singleton.
749749
const CanType TheEmptyTupleType; /// This is '()', aka Void
750750
const CanType TheAnyType; /// This is 'Any', the empty protocol composition
751-
const CanType TheNativeObjectType; /// Builtin.NativeObject
752-
const CanType TheBridgeObjectType; /// Builtin.BridgeObject
753-
const CanType TheRawPointerType; /// Builtin.RawPointer
754-
const CanType TheRawUnsafeContinuationType; /// Builtin.RawUnsafeContinuation
755-
const CanType TheUnsafeValueBufferType; /// Builtin.UnsafeValueBuffer
756-
const CanType TheSILTokenType; /// Builtin.SILToken
757-
const CanType TheIntegerLiteralType; /// Builtin.IntegerLiteralType
758-
751+
#define SINGLETON_TYPE(SHORT_ID, ID) \
752+
const CanType The##SHORT_ID##Type;
753+
#include "swift/AST/TypeNodes.def"
754+
759755
const CanType TheIEEE32Type; /// 32-bit IEEE floating point
760756
const CanType TheIEEE64Type; /// 64-bit IEEE floating point
761757

include/swift/AST/TypeDifferenceVisitor.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,11 @@ class CanTypeDifferenceVisitor : public CanTypePairVisitor<Impl, bool> {
107107
// non-identical types.
108108

109109
// These types are singleton and can't actually differ.
110-
#define SINGLETON_TYPE(TYPE) \
111-
bool visit##TYPE(Can##TYPE type1, Can##TYPE type2) { \
110+
#define SINGLETON_TYPE(SHORT_ID, ID) \
111+
bool visit##ID##Type(Can##ID##Type type1, Can##ID##Type type2) {\
112112
llvm_unreachable("singleton type that wasn't identical"); \
113113
}
114-
SINGLETON_TYPE(BuiltinIntegerLiteralType)
115-
SINGLETON_TYPE(BuiltinRawPointerType)
116-
SINGLETON_TYPE(BuiltinRawUnsafeContinuationType)
117-
SINGLETON_TYPE(BuiltinNativeObjectType)
118-
SINGLETON_TYPE(BuiltinBridgeObjectType)
119-
SINGLETON_TYPE(BuiltinUnsafeValueBufferType)
120-
SINGLETON_TYPE(SILTokenType)
121-
#undef SINGLETON_TYPE
114+
#include "swift/AST/TypeNodes.def"
122115

123116
bool visitBuiltinIntegerType(CanBuiltinIntegerType type1,
124117
CanBuiltinIntegerType type2) {

include/swift/AST/TypeMatcher.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,10 @@ class TypeMatcher {
102102

103103
TRIVIAL_CASE(ErrorType)
104104
TRIVIAL_CASE(BuiltinIntegerType)
105-
TRIVIAL_CASE(BuiltinIntegerLiteralType)
106105
TRIVIAL_CASE(BuiltinFloatType)
107-
TRIVIAL_CASE(BuiltinRawPointerType)
108-
TRIVIAL_CASE(BuiltinRawUnsafeContinuationType)
109-
TRIVIAL_CASE(BuiltinNativeObjectType)
110-
TRIVIAL_CASE(BuiltinBridgeObjectType)
111-
TRIVIAL_CASE(BuiltinUnsafeValueBufferType)
112106
TRIVIAL_CASE(BuiltinVectorType)
113-
TRIVIAL_CASE(SILTokenType)
107+
#define SINGLETON_TYPE(SHORT_ID, ID) TRIVIAL_CASE(ID##Type)
108+
#include "swift/AST/TypeNodes.def"
114109

115110
bool visitUnresolvedType(CanUnresolvedType firstType, Type secondType,
116111
Type sugaredFirstType) {

include/swift/AST/TypeNodes.def

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@
4747
/// programs and it cannot be the type of an expression.
4848
/// The default behavior is TYPE(id, parent).
4949

50+
/// SINGLETON_TYPE(SHORT_ID, id)
51+
/// This type is a singleton, i.e. there is exactly one instance of
52+
/// it, which can be found as ASTContext.The#SHORT_ID#Type.
53+
/// This is only expanded if SINGLETON_TYPE is defined, and in this
54+
/// case no other macros are expanded.
55+
5056
#ifndef ALWAYS_CANONICAL_TYPE
5157
#define ALWAYS_CANONICAL_TYPE(id, parent) TYPE(id, parent)
5258
#endif
@@ -87,6 +93,8 @@
8793
#define LAST_TYPE(Id)
8894
#endif
8995

96+
#if !defined(SINGLETON_TYPE)
97+
9098
TYPE(Error, Type)
9199
UNCHECKED_TYPE(Unresolved, Type)
92100
UNCHECKED_TYPE(Hole, Type)
@@ -96,6 +104,7 @@ ABSTRACT_TYPE(Builtin, Type)
96104
BUILTIN_TYPE(BuiltinIntegerLiteral, AnyBuiltinIntegerType)
97105
TYPE_RANGE(AnyBuiltinInteger, BuiltinInteger, BuiltinIntegerLiteral)
98106
BUILTIN_TYPE(BuiltinFloat, BuiltinType)
107+
BUILTIN_TYPE(BuiltinJob, BuiltinType)
99108
BUILTIN_TYPE(BuiltinRawPointer, BuiltinType)
100109
BUILTIN_TYPE(BuiltinRawUnsafeContinuation, BuiltinType)
101110
BUILTIN_TYPE(BuiltinNativeObject, BuiltinType)
@@ -166,6 +175,20 @@ ABSTRACT_SUGARED_TYPE(Sugar, Type)
166175
TYPE_RANGE(Sugar, Paren, Dictionary)
167176
LAST_TYPE(Dictionary) // Sugared types are last to make isa<SugarType>() fast.
168177

178+
#endif
179+
180+
#ifdef SINGLETON_TYPE
181+
SINGLETON_TYPE(IntegerLiteral, BuiltinIntegerLiteral)
182+
SINGLETON_TYPE(Job, BuiltinJob)
183+
SINGLETON_TYPE(RawPointer, BuiltinRawPointer)
184+
SINGLETON_TYPE(RawUnsafeContinuation, BuiltinRawUnsafeContinuation)
185+
SINGLETON_TYPE(NativeObject, BuiltinNativeObject)
186+
SINGLETON_TYPE(BridgeObject, BuiltinBridgeObject)
187+
SINGLETON_TYPE(UnsafeValueBuffer, BuiltinUnsafeValueBuffer)
188+
SINGLETON_TYPE(SILToken, SILToken)
189+
#undef SINGLETON_TYPE
190+
#endif
191+
169192
#undef TYPE_RANGE
170193
#undef ABSTRACT_SUGARED_TYPE
171194
#undef ABSTRACT_TYPE

include/swift/AST/Types.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,8 +1392,9 @@ class BuiltinRawPointerType : public BuiltinType {
13921392
DEFINE_EMPTY_CAN_TYPE_WRAPPER(BuiltinRawPointerType, BuiltinType);
13931393

13941394
/// BuiltinRawContinuationType - The builtin raw unsafe continuation type.
1395-
/// This pointer is completely unmanaged, but is lowered with the same
1396-
/// spare bits as an opaque object-pointer type.
1395+
/// In C, this is a non-null AsyncTask*. This pointer is completely
1396+
/// unmanaged (the unresumed task is self-owning), but has more spare bits
1397+
/// than Builtin.RawPointer.
13971398
class BuiltinRawUnsafeContinuationType : public BuiltinType {
13981399
friend class ASTContext;
13991400
BuiltinRawUnsafeContinuationType(const ASTContext &C)
@@ -1405,6 +1406,20 @@ class BuiltinRawUnsafeContinuationType : public BuiltinType {
14051406
};
14061407
DEFINE_EMPTY_CAN_TYPE_WRAPPER(BuiltinRawUnsafeContinuationType, BuiltinType);
14071408

1409+
/// BuiltinJobType - The builtin job type. In C, this is a
1410+
/// non-null Job*. This pointer is completely unmanaged (the unscheduled
1411+
/// job is self-owning), but has more spare bits than Builtin.RawPointer.
1412+
class BuiltinJobType : public BuiltinType {
1413+
friend class ASTContext;
1414+
BuiltinJobType(const ASTContext &C)
1415+
: BuiltinType(TypeKind::BuiltinJob, C) {}
1416+
public:
1417+
static bool classof(const TypeBase *T) {
1418+
return T->getKind() == TypeKind::BuiltinJob;
1419+
}
1420+
};
1421+
DEFINE_EMPTY_CAN_TYPE_WRAPPER(BuiltinJobType, BuiltinType);
1422+
14081423
/// BuiltinNativeObjectType - The builtin opaque object-pointer type.
14091424
/// Useful for keeping an object alive when it is otherwise being
14101425
/// manipulated via an unsafe pointer type.

include/swift/Strings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_RAWUNSAFECONTINUATIO
116116
/// The name of the Builtin type for UnsafeValueBuffer
117117
constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_UNSAFEVALUEBUFFER =
118118
{"Builtin.UnsafeValueBuffer"};
119+
/// The name of the Builtin type for Job
120+
constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_JOB = {
121+
"Builtin.Job"};
119122
/// The name of the Builtin type for UnknownObject
120123
///
121124
/// This no longer exists as an AST-accessible type, but it's still used for

lib/AST/ASTContext.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -595,20 +595,10 @@ ASTContext::ASTContext(LangOptions &langOpts, TypeCheckerOptions &typeckOpts,
595595
TheEmptyTupleType(TupleType::get(ArrayRef<TupleTypeElt>(), *this)),
596596
TheAnyType(ProtocolCompositionType::get(*this, ArrayRef<Type>(),
597597
/*HasExplicitAnyObject=*/false)),
598-
TheNativeObjectType(new (*this, AllocationArena::Permanent)
599-
BuiltinNativeObjectType(*this)),
600-
TheBridgeObjectType(new (*this, AllocationArena::Permanent)
601-
BuiltinBridgeObjectType(*this)),
602-
TheRawPointerType(new (*this, AllocationArena::Permanent)
603-
BuiltinRawPointerType(*this)),
604-
TheRawUnsafeContinuationType(new (*this, AllocationArena::Permanent)
605-
BuiltinRawUnsafeContinuationType(*this)),
606-
TheUnsafeValueBufferType(new (*this, AllocationArena::Permanent)
607-
BuiltinUnsafeValueBufferType(*this)),
608-
TheSILTokenType(new (*this, AllocationArena::Permanent)
609-
SILTokenType(*this)),
610-
TheIntegerLiteralType(new (*this, AllocationArena::Permanent)
611-
BuiltinIntegerLiteralType(*this)),
598+
#define SINGLETON_TYPE(SHORT_ID, ID) \
599+
The##SHORT_ID##Type(new (*this, AllocationArena::Permanent) \
600+
ID##Type(*this)),
601+
#include "swift/AST/TypeNodes.def"
612602
TheIEEE32Type(new (*this, AllocationArena::Permanent)
613603
BuiltinFloatType(BuiltinFloatType::IEEE32,*this)),
614604
TheIEEE64Type(new (*this, AllocationArena::Permanent)

lib/AST/ASTDumper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3560,6 +3560,7 @@ namespace {
35603560
}
35613561

35623562
TRIVIAL_TYPE_PRINTER(BuiltinIntegerLiteral, builtin_integer_literal)
3563+
TRIVIAL_TYPE_PRINTER(BuiltinJob, builtin_job)
35633564
TRIVIAL_TYPE_PRINTER(BuiltinRawPointer, builtin_raw_pointer)
35643565
TRIVIAL_TYPE_PRINTER(BuiltinRawUnsafeContinuation, builtin_raw_unsafe_continuation)
35653566
TRIVIAL_TYPE_PRINTER(BuiltinNativeObject, builtin_native_object)

lib/AST/ASTMangler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,8 @@ void ASTMangler::appendType(Type type, const ValueDecl *forDecl) {
973973
}
974974
case TypeKind::BuiltinIntegerLiteral:
975975
return appendOperator("BI");
976+
case TypeKind::BuiltinJob:
977+
return appendOperator("Bj");
976978
case TypeKind::BuiltinRawPointer:
977979
return appendOperator("Bp");
978980
case TypeKind::BuiltinRawUnsafeContinuation:

lib/AST/ASTPrinter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3854,6 +3854,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
38543854
}
38553855
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinRawPointerType)
38563856
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinRawUnsafeContinuationType)
3857+
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinJobType)
38573858
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinNativeObjectType)
38583859
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinBridgeObjectType)
38593860
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinUnsafeValueBufferType)

lib/AST/Builtins.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ Type swift::getBuiltinType(ASTContext &Context, StringRef Name) {
8080
return Context.TheRawPointerType;
8181
if (Name == "RawUnsafeContinuation")
8282
return Context.TheRawUnsafeContinuationType;
83+
if (Name == "Job")
84+
return Context.TheJobType;
8385
if (Name == "NativeObject")
8486
return Context.TheNativeObjectType;
8587
if (Name == "BridgeObject")
@@ -2684,6 +2686,9 @@ StringRef BuiltinType::getTypeName(SmallVectorImpl<char> &result,
26842686
case BuiltinTypeKind::BuiltinRawUnsafeContinuation:
26852687
printer << MAYBE_GET_NAMESPACED_BUILTIN(BUILTIN_TYPE_NAME_RAWUNSAFECONTINUATION);
26862688
break;
2689+
case BuiltinTypeKind::BuiltinJob:
2690+
printer << MAYBE_GET_NAMESPACED_BUILTIN(BUILTIN_TYPE_NAME_JOB);
2691+
break;
26872692
case BuiltinTypeKind::BuiltinNativeObject:
26882693
printer << MAYBE_GET_NAMESPACED_BUILTIN(BUILTIN_TYPE_NAME_NATIVEOBJECT);
26892694
break;

lib/AST/Type.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ bool CanType::isReferenceTypeImpl(CanType type, const GenericSignatureImpl *sig,
209209
case TypeKind::BuiltinFloat:
210210
case TypeKind::BuiltinRawPointer:
211211
case TypeKind::BuiltinRawUnsafeContinuation:
212+
case TypeKind::BuiltinJob:
212213
case TypeKind::BuiltinUnsafeValueBuffer:
213214
case TypeKind::BuiltinVector:
214215
case TypeKind::Tuple:
@@ -5005,6 +5006,7 @@ ReferenceCounting TypeBase::getReferenceCounting() {
50055006
case TypeKind::BuiltinFloat:
50065007
case TypeKind::BuiltinRawPointer:
50075008
case TypeKind::BuiltinRawUnsafeContinuation:
5009+
case TypeKind::BuiltinJob:
50085010
case TypeKind::BuiltinUnsafeValueBuffer:
50095011
case TypeKind::BuiltinVector:
50105012
case TypeKind::Tuple:

lib/Demangling/Demangler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,10 @@ NodePointer Demangler::demangleBuiltinType() {
11791179
Ty = createNode(Node::Kind::BuiltinTypeName,
11801180
BUILTIN_TYPE_NAME_RAWPOINTER);
11811181
break;
1182+
case 'j':
1183+
Ty = createNode(Node::Kind::BuiltinTypeName,
1184+
BUILTIN_TYPE_NAME_JOB);
1185+
break;
11821186
case 'c':
11831187
Ty = createNode(Node::Kind::BuiltinTypeName,
11841188
BUILTIN_TYPE_NAME_RAWUNSAFECONTINUATION);

lib/Demangling/Remangler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,8 @@ void Remangler::mangleBuiltinTypeName(Node *node) {
745745
Buffer << 'p';
746746
} else if (text == BUILTIN_TYPE_NAME_RAWUNSAFECONTINUATION) {
747747
Buffer << 'c';
748+
} else if (text == BUILTIN_TYPE_NAME_JOB) {
749+
Buffer << 'j';
748750
} else if (text == BUILTIN_TYPE_NAME_SILTOKEN) {
749751
Buffer << 't';
750752
} else if (text == BUILTIN_TYPE_NAME_INTLITERAL) {

lib/IRGen/ExtraInhabitants.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ unsigned irgen::getFunctionPointerExtraInhabitantCount(IRGenModule &IGM) {
6161
return getPointerExtraInhabitantCount(IGM, 0);
6262
}
6363

64+
unsigned irgen::getAlignedPointerExtraInhabitantCount(IRGenModule &IGM,
65+
Alignment align) {
66+
// For all of the operations on current platforms, we totally ignore
67+
// alignment because we assume we can get what we consider to be an
68+
// adequate number of extra inhabitants from LeastValidPointerValue.
69+
// If we have to revisit that for a future ABI, we can take advantage
70+
// of alignment bits.
71+
return getPointerExtraInhabitantCount(IGM, 0);
72+
}
73+
6474
/*****************************************************************************/
6575

6676
static APInt
@@ -99,6 +109,14 @@ APInt irgen::getFunctionPointerFixedExtraInhabitantValue(IRGenModule &IGM,
99109
return getPointerFixedExtraInhabitantValue(IGM, bits, index, offset, 0);
100110
}
101111

112+
APInt irgen::getAlignedPointerExtraInhabitantValue(IRGenModule &IGM,
113+
Alignment align,
114+
unsigned bits,
115+
unsigned index,
116+
unsigned offset) {
117+
return getPointerFixedExtraInhabitantValue(IGM, bits, index, offset, 0);
118+
}
119+
102120
/*****************************************************************************/
103121

104122
static llvm::Value *getPointerExtraInhabitantIndex(IRGenFunction &IGF,
@@ -180,6 +198,12 @@ llvm::Value *irgen::getFunctionPointerExtraInhabitantIndex(IRGenFunction &IGF,
180198
return getPointerExtraInhabitantIndex(IGF, src, 0);
181199
}
182200

201+
llvm::Value *irgen::getAlignedPointerExtraInhabitantIndex(IRGenFunction &IGF,
202+
Alignment align,
203+
Address src) {
204+
return getPointerExtraInhabitantIndex(IGF, src, 0);
205+
}
206+
183207
/*****************************************************************************/
184208

185209
static void storePointerExtraInhabitant(IRGenFunction &IGF,
@@ -214,3 +238,10 @@ void irgen::storeFunctionPointerExtraInhabitant(IRGenFunction &IGF,
214238
Address dest) {
215239
storePointerExtraInhabitant(IGF, index, dest, 0);
216240
}
241+
242+
void irgen::storeAlignedPointerExtraInhabitant(IRGenFunction &IGF,
243+
Alignment align,
244+
llvm::Value *index,
245+
Address dest) {
246+
storePointerExtraInhabitant(IGF, index, dest, 0);
247+
}

lib/IRGen/ExtraInhabitants.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace swift {
2727
namespace irgen {
2828

2929
class Address;
30+
class Alignment;
3031
class IRGenFunction;
3132
class IRGenModule;
3233

@@ -62,6 +63,39 @@ void storeHeapObjectExtraInhabitant(IRGenFunction &IGF,
6263

6364
/*****************************************************************************/
6465

66+
/// \group Extra inhabitants of aligned object pointers.
67+
68+
/// Return the number of extra inhabitant representations for aligned
69+
/// object pointers.
70+
unsigned getAlignedPointerExtraInhabitantCount(IRGenModule &IGM,
71+
Alignment pointeeAlign);
72+
73+
/// Return an indexed extra inhabitant constant for an aligned pointer.
74+
///
75+
/// If the pointer appears within a larger aggregate, the 'bits' and 'offset'
76+
/// arguments can be used to position the inhabitant within the larger integer
77+
/// constant.
78+
llvm::APInt getAlignedPointerExtraInhabitantValue(IRGenModule &IGM,
79+
Alignment pointeeAlign,
80+
unsigned bits,
81+
unsigned index,
82+
unsigned offset);
83+
84+
/// Calculate the index of an aligned pointer extra inhabitant
85+
/// representation stored in memory.
86+
llvm::Value *getAlignedPointerExtraInhabitantIndex(IRGenFunction &IGF,
87+
Alignment pointeeAlign,
88+
Address src);
89+
90+
/// Calculate an extra inhabitant representation from an index and store it to
91+
/// memory.
92+
void storeAlignedPointerExtraInhabitant(IRGenFunction &IGF,
93+
Alignment pointeeAlign,
94+
llvm::Value *index,
95+
Address dest);
96+
97+
/*****************************************************************************/
98+
6599
/// \group Extra inhabitants of function pointers.
66100

67101
/// Return the number of extra inhabitant representations for function pointers,

0 commit comments

Comments
 (0)