Skip to content

Commit 68806b4

Browse files
authored
Merge branch 'main' into isolated-any-silgen
2 parents 868fc6a + 57e1e39 commit 68806b4

File tree

55 files changed

+979
-496
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+979
-496
lines changed

include/swift/ABI/MetadataValues.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,9 @@ class TargetExtendedFunctionTypeFlags {
11871187

11881188
// Values for the enumerated isolation kinds
11891189
IsolatedAny = 0x00000002U,
1190+
1191+
// Values if we have a transferring result.
1192+
HasTransferringResult = 0x00000010U,
11901193
};
11911194
int_type Data;
11921195

@@ -1211,12 +1214,23 @@ class TargetExtendedFunctionTypeFlags {
12111214
(Data & ~IsolationMask) | IsolatedAny);
12121215
}
12131216

1217+
const TargetExtendedFunctionTypeFlags<int_type>
1218+
withTransferringResult(bool newValue = true) const {
1219+
return TargetExtendedFunctionTypeFlags<int_type>(
1220+
(Data & ~HasTransferringResult) |
1221+
(newValue ? HasTransferringResult : 0));
1222+
}
1223+
12141224
bool isTypedThrows() const { return bool(Data & TypedThrowsMask); }
12151225

12161226
bool isIsolatedAny() const {
12171227
return (Data & IsolationMask) == IsolatedAny;
12181228
}
12191229

1230+
bool hasTransferringResult() const {
1231+
return bool(Data & HasTransferringResult);
1232+
}
1233+
12201234
int_type getIntValue() const {
12211235
return Data;
12221236
}
@@ -1242,6 +1256,7 @@ class TargetParameterTypeFlags {
12421256
AutoClosureMask = 0x100,
12431257
NoDerivativeMask = 0x200,
12441258
IsolatedMask = 0x400,
1259+
TransferringMask = 0x800,
12451260
};
12461261
int_type Data;
12471262

@@ -1280,11 +1295,18 @@ class TargetParameterTypeFlags {
12801295
(Data & ~IsolatedMask) | (isIsolated ? IsolatedMask : 0));
12811296
}
12821297

1298+
constexpr TargetParameterTypeFlags<int_type>
1299+
withTransferring(bool isTransferring) const {
1300+
return TargetParameterTypeFlags<int_type>(
1301+
(Data & ~TransferringMask) | (isTransferring ? TransferringMask : 0));
1302+
}
1303+
12831304
bool isNone() const { return Data == 0; }
12841305
bool isVariadic() const { return Data & VariadicMask; }
12851306
bool isAutoClosure() const { return Data & AutoClosureMask; }
12861307
bool isNoDerivative() const { return Data & NoDerivativeMask; }
12871308
bool isIsolated() const { return Data & IsolatedMask; }
1309+
bool isTransferring() const { return Data & TransferringMask; }
12881310

12891311
ValueOwnership getValueOwnership() const {
12901312
return (ValueOwnership)(Data & ValueOwnershipMask);

include/swift/AST/Types.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,25 +1146,16 @@ class alignas(1 << TypeAlignInBits) TypeBase
11461146
/// function with each archetype-to-substituted-type binding. The callback
11471147
/// may return a new type to substitute into the result type, or return
11481148
/// CanType() to error out of the operation. Each invocation of the callback
1149-
/// receives three arguments:
1149+
/// receives two arguments:
11501150
/// - The `orig` archetype from a position in `this` type.
1151-
/// - The `subst` type in the same structural position of `ty` that is trying to be bound
1152-
/// to `orig`.
1153-
/// - The `upperBound` archetype, which if set, indicates the minimum set of constraints
1154-
/// that any type substituted in this structural position must conform to. May be null,
1155-
/// indicating an unconstrained context.
1156-
/// - If `upperBound` is set, then the `substConformances` array will contain the
1157-
/// protocol conformances for `subst` to each of the protocol requirements
1158-
/// on `upperBound` in `getConformsTo` order.
1151+
/// - The `subst` type in the same structural position of `ty` that is trying
1152+
/// to be bound to `orig`.
11591153
///
11601154
/// Returns the substituted type, or a null CanType() if this type
11611155
/// is not bindable to the substituted type, or the callback returns
11621156
/// CanType().
11631157
CanType substituteBindingsTo(Type ty,
1164-
llvm::function_ref<CanType(ArchetypeType *orig,
1165-
CanType subst,
1166-
ArchetypeType *upperBound,
1167-
ArrayRef<ProtocolConformanceRef> substConformances)> substFn);
1158+
llvm::function_ref<CanType(ArchetypeType *orig, CanType subst)> substFn);
11681159

11691160
/// Determines whether this type is similar to \p other as defined by
11701161
/// \p matchOptions.

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ LANGUAGE_FEATURE(TypedThrows, 413, "Typed throws")
125125
LANGUAGE_FEATURE(OptionalIsolatedParameters, 420, "Optional isolated parameters")
126126
SUPPRESSIBLE_LANGUAGE_FEATURE(Extern, 0, "@_extern")
127127
LANGUAGE_FEATURE(ExpressionMacroDefaultArguments, 422, "Expression macro as caller-side default argument")
128+
LANGUAGE_FEATURE(BuiltinStoreRaw, 0, "Builtin.storeRaw")
128129

129130
UPCOMING_FEATURE(ConciseMagicFile, 274, 6)
130131
UPCOMING_FEATURE(ForwardTrailingClosures, 286, 6)

include/swift/Demangling/Demangle.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ class Node {
278278
/// Prints the whole node tree in readable form to stderr.
279279
///
280280
/// Useful to be called from the debugger.
281-
void dump();
281+
void dump() LLVM_ATTRIBUTE_USED;
282282
};
283283

284284
/// Returns the length of the swift mangling prefix of the \p SymbolName.
@@ -555,6 +555,7 @@ struct [[nodiscard]] ManglingError {
555555
InvalidImplDifferentiability,
556556
InvalidImplFunctionAttribute,
557557
InvalidImplParameterConvention,
558+
InvalidImplParameterTransferring,
558559
InvalidMetatypeRepresentation,
559560
MultiByteRelatedEntity,
560561
BadValueWitnessKind,

include/swift/Demangling/DemangleNodes.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ NODE(ImplConvention)
133133
NODE(ImplDifferentiabilityKind)
134134
NODE(ImplErasedIsolation)
135135
NODE(ImplParameterResultDifferentiability)
136+
NODE(ImplParameterTransferring)
136137
NODE(ImplFunctionAttribute)
137138
NODE(ImplFunctionConvention)
138139
NODE(ImplFunctionConventionName)
@@ -149,7 +150,9 @@ NODE(InfixOperator)
149150
CONTEXT_NODE(Initializer)
150151
CONTEXT_NODE(InitAccessor)
151152
NODE(Isolated)
153+
NODE(Transferring)
152154
NODE(IsolatedAnyFunctionType)
155+
NODE(TransferringResultFunctionType)
153156
NODE(KeyPathGetterThunkHelper)
154157
NODE(KeyPathSetterThunkHelper)
155158
NODE(KeyPathEqualsThunkHelper)

include/swift/Demangling/Demangler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ class Demangler : public NodeFactory {
566566
NodePointer demangleInitializer();
567567
NodePointer demangleImplParamConvention(Node::Kind ConvKind);
568568
NodePointer demangleImplResultConvention(Node::Kind ConvKind);
569+
NodePointer demangleImplParameterTransferring();
569570
NodePointer demangleImplParameterResultDifferentiability();
570571
NodePointer demangleImplFunctionType();
571572
NodePointer demangleClangType();

include/swift/Demangling/TypeDecoder.h

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class FunctionParam {
7878
}
7979
void setNoDerivative() { Flags = Flags.withNoDerivative(true); }
8080
void setIsolated() { Flags = Flags.withIsolated(true); }
81+
void setTransferring() { Flags = Flags.withTransferring(true); }
8182
void setFlags(ParameterFlags flags) { Flags = flags; };
8283

8384
FunctionParam withLabel(StringRef label) const {
@@ -109,6 +110,7 @@ enum class ImplParameterConvention {
109110

110111
enum class ImplParameterInfoFlags : uint8_t {
111112
NotDifferentiable = 0x1,
113+
Transferring = 0x2,
112114
};
113115

114116
using ImplParameterInfoOptions = OptionSet<ImplParameterInfoFlags>;
@@ -282,72 +284,88 @@ class ImplFunctionTypeFlags {
282284
unsigned Async : 1;
283285
unsigned ErasedIsolation : 1;
284286
unsigned DifferentiabilityKind : 3;
287+
unsigned HasTransferringResult : 1;
285288

286289
public:
287290
ImplFunctionTypeFlags()
288291
: Rep(0), Pseudogeneric(0), Escaping(0), Concurrent(0), Async(0),
289-
ErasedIsolation(0), DifferentiabilityKind(0) {}
292+
ErasedIsolation(0), DifferentiabilityKind(0), HasTransferringResult(0) {
293+
}
290294

291295
ImplFunctionTypeFlags(ImplFunctionRepresentation rep, bool pseudogeneric,
292296
bool noescape, bool concurrent, bool async,
293297
bool erasedIsolation,
294-
ImplFunctionDifferentiabilityKind diffKind)
298+
ImplFunctionDifferentiabilityKind diffKind,
299+
bool hasTransferringResult)
295300
: Rep(unsigned(rep)), Pseudogeneric(pseudogeneric), Escaping(noescape),
296301
Concurrent(concurrent), Async(async), ErasedIsolation(erasedIsolation),
297-
DifferentiabilityKind(unsigned(diffKind)) {}
302+
DifferentiabilityKind(unsigned(diffKind)),
303+
HasTransferringResult(hasTransferringResult) {}
298304

299305
ImplFunctionTypeFlags
300306
withRepresentation(ImplFunctionRepresentation rep) const {
301307
return ImplFunctionTypeFlags(
302308
rep, Pseudogeneric, Escaping, Concurrent, Async, ErasedIsolation,
303-
ImplFunctionDifferentiabilityKind(DifferentiabilityKind));
309+
ImplFunctionDifferentiabilityKind(DifferentiabilityKind),
310+
HasTransferringResult);
304311
}
305312

306313
ImplFunctionTypeFlags
307314
withConcurrent() const {
308315
return ImplFunctionTypeFlags(
309-
ImplFunctionRepresentation(Rep), Pseudogeneric, Escaping, true,
310-
Async, ErasedIsolation,
311-
ImplFunctionDifferentiabilityKind(DifferentiabilityKind));
316+
ImplFunctionRepresentation(Rep), Pseudogeneric, Escaping, true, Async,
317+
ErasedIsolation,
318+
ImplFunctionDifferentiabilityKind(DifferentiabilityKind),
319+
HasTransferringResult);
312320
}
313321

314322
ImplFunctionTypeFlags
315323
withAsync() const {
316324
return ImplFunctionTypeFlags(
317325
ImplFunctionRepresentation(Rep), Pseudogeneric, Escaping, Concurrent,
318326
true, ErasedIsolation,
319-
ImplFunctionDifferentiabilityKind(DifferentiabilityKind));
327+
ImplFunctionDifferentiabilityKind(DifferentiabilityKind),
328+
HasTransferringResult);
320329
}
321330

322331
ImplFunctionTypeFlags
323332
withEscaping() const {
324333
return ImplFunctionTypeFlags(
325334
ImplFunctionRepresentation(Rep), Pseudogeneric, true, Concurrent, Async,
326335
ErasedIsolation,
327-
ImplFunctionDifferentiabilityKind(DifferentiabilityKind));
336+
ImplFunctionDifferentiabilityKind(DifferentiabilityKind),
337+
HasTransferringResult);
328338
}
329339

330340
ImplFunctionTypeFlags
331341
withErasedIsolation() const {
332342
return ImplFunctionTypeFlags(
333343
ImplFunctionRepresentation(Rep), Pseudogeneric, Escaping, Concurrent,
334-
Async, true,
335-
ImplFunctionDifferentiabilityKind(DifferentiabilityKind));
344+
Async, true, ImplFunctionDifferentiabilityKind(DifferentiabilityKind),
345+
HasTransferringResult);
336346
}
337347

338348
ImplFunctionTypeFlags
339349
withPseudogeneric() const {
340350
return ImplFunctionTypeFlags(
341351
ImplFunctionRepresentation(Rep), true, Escaping, Concurrent, Async,
342352
ErasedIsolation,
343-
ImplFunctionDifferentiabilityKind(DifferentiabilityKind));
353+
ImplFunctionDifferentiabilityKind(DifferentiabilityKind),
354+
HasTransferringResult);
344355
}
345356

346357
ImplFunctionTypeFlags
347358
withDifferentiabilityKind(ImplFunctionDifferentiabilityKind diffKind) const {
348359
return ImplFunctionTypeFlags(ImplFunctionRepresentation(Rep), Pseudogeneric,
349360
Escaping, Concurrent, Async, ErasedIsolation,
350-
diffKind);
361+
diffKind, HasTransferringResult);
362+
}
363+
364+
ImplFunctionTypeFlags withTransferringResult() const {
365+
return ImplFunctionTypeFlags(
366+
ImplFunctionRepresentation(Rep), Pseudogeneric, Escaping, Concurrent,
367+
Async, ErasedIsolation,
368+
ImplFunctionDifferentiabilityKind(DifferentiabilityKind), true);
351369
}
352370

353371
ImplFunctionRepresentation getRepresentation() const {
@@ -364,6 +382,8 @@ class ImplFunctionTypeFlags {
364382

365383
bool hasErasedIsolation() const { return ErasedIsolation; }
366384

385+
bool hasTransferringResult() const { return HasTransferringResult; }
386+
367387
bool isDifferentiable() const {
368388
return getDifferentiabilityKind() !=
369389
ImplFunctionDifferentiabilityKind::NonDifferentiable;
@@ -868,6 +888,12 @@ class TypeDecoder {
868888
extFlags = extFlags.withIsolatedAny();
869889
++firstChildIdx;
870890
}
891+
892+
if (Node->getChild(firstChildIdx)->getKind() ==
893+
NodeKind::TransferringResultFunctionType) {
894+
extFlags = extFlags.withTransferringResult();
895+
++firstChildIdx;
896+
}
871897

872898
FunctionMetadataDifferentiabilityKind diffKind;
873899
if (Node->getChild(firstChildIdx)->getKind() ==
@@ -1707,6 +1733,12 @@ class TypeDecoder {
17071733
hasParamFlags = true;
17081734
break;
17091735

1736+
case NodeKind::Transferring:
1737+
param.setTransferring();
1738+
node = node->getFirstChild();
1739+
hasParamFlags = true;
1740+
break;
1741+
17101742
case NodeKind::AutoClosureType:
17111743
case NodeKind::EscapingAutoClosureType:
17121744
param.setAutoClosure();

include/swift/RemoteInspection/TypeRefBuilder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,8 @@ class TypeRefBuilder {
11631163
funcFlags = funcFlags.withConcurrent(flags.isSendable());
11641164
funcFlags = funcFlags.withAsync(flags.isAsync());
11651165
funcFlags = funcFlags.withDifferentiable(flags.isDifferentiable());
1166+
extFuncFlags =
1167+
extFuncFlags.withTransferringResult(flags.hasTransferringResult());
11661168

11671169
FunctionMetadataDifferentiabilityKind diffKind;
11681170
switch (flags.getDifferentiabilityKind()) {

lib/AST/ASTDemangler.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,8 @@ Type ASTBuilder::createFunctionType(
414414
.withVariadic(flags.isVariadic())
415415
.withAutoClosure(flags.isAutoClosure())
416416
.withNoDerivative(flags.isNoDerivative())
417-
.withIsolated(flags.isIsolated());
417+
.withIsolated(flags.isIsolated())
418+
.withTransferring(flags.isTransferring());
418419

419420
hasIsolatedParameter |= flags.isIsolated();
420421
funcParams.push_back(AnyFunctionType::Param(type, label, parameterFlags));
@@ -472,7 +473,7 @@ Type ASTBuilder::createFunctionType(
472473
auto einfo = FunctionType::ExtInfoBuilder(
473474
representation, noescape, flags.isThrowing(), thrownError,
474475
resultDiffKind, clangFunctionType, isolation,
475-
LifetimeDependenceInfo(), false /*is transferring*/)
476+
LifetimeDependenceInfo(), extFlags.hasTransferringResult())
476477
.withAsync(flags.isAsync())
477478
.withConcurrent(flags.isSendable())
478479
.build();
@@ -517,6 +518,11 @@ getParameterOptions(ImplParameterInfoOptions implOptions) {
517518
result |= SILParameterInfo::NotDifferentiable;
518519
}
519520

521+
if (implOptions.contains(ImplParameterInfoFlags::Transferring)) {
522+
implOptions -= ImplParameterInfoFlags::Transferring;
523+
result |= SILParameterInfo::Transferring;
524+
}
525+
520526
// If we did not handle all flags in implOptions, this code was not updated
521527
// appropriately. Return None to signal error.
522528
if (bool(implOptions))
@@ -659,7 +665,7 @@ Type ASTBuilder::createImplFunctionType(
659665
representation, flags.isPseudogeneric(), !flags.isEscaping(),
660666
flags.isSendable(), flags.isAsync(), unimplementable,
661667
isolation, diffKind, clangFnType, LifetimeDependenceInfo(),
662-
false /*has transferring result*/)
668+
flags.hasTransferringResult())
663669
.build();
664670

665671
return SILFunctionType::get(genericSig, einfo, funcCoroutineKind,

lib/AST/ASTMangler.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1989,6 +1989,9 @@ void ASTMangler::appendImplFunctionType(SILFunctionType *fn,
19891989
if (!fn->isNoEscape())
19901990
OpArgs.push_back('e');
19911991

1992+
if (fn->hasTransferringResult())
1993+
OpArgs.push_back('T');
1994+
19921995
switch (fn->getIsolation()) {
19931996
case SILFunctionTypeIsolation::Unknown:
19941997
break;
@@ -2089,6 +2092,8 @@ void ASTMangler::appendImplFunctionType(SILFunctionType *fn,
20892092
// Mangle the parameters.
20902093
for (auto param : fn->getParameters()) {
20912094
OpArgs.push_back(getParamConvention(param.getConvention()));
2095+
if (param.hasOption(SILParameterInfo::Transferring))
2096+
OpArgs.push_back('T');
20922097
if (auto diffKind = getParamDifferentiability(param.getOptions()))
20932098
OpArgs.push_back(*diffKind);
20942099
appendType(param.getInterfaceType(), sig, forDecl);
@@ -2858,6 +2863,10 @@ void ASTMangler::appendFunctionSignature(AnyFunctionType *fn,
28582863
break;
28592864
}
28602865

2866+
if (fn->hasTransferringResult()) {
2867+
appendOperator("YT");
2868+
}
2869+
28612870
if (auto *afd = dyn_cast_or_null<AbstractFunctionDecl>(forDecl)) {
28622871
if (afd->hasImplicitSelfDecl()) {
28632872
auto lifetimeDependenceKind =
@@ -3034,7 +3043,8 @@ void ASTMangler::appendParameterTypeListElement(
30343043
}
30353044
if (flags.isIsolated())
30363045
appendOperator("Yi");
3037-
3046+
if (flags.isTransferring())
3047+
appendOperator("Yu");
30383048
if (flags.isCompileTimeConst())
30393049
appendOperator("Yt");
30403050

0 commit comments

Comments
 (0)