Skip to content

Commit 2b8ab7f

Browse files
committed
AST: Re-baseline SendingArgsAndResults feature.
1 parent a37ce9a commit 2b8ab7f

File tree

10 files changed

+28
-276
lines changed

10 files changed

+28
-276
lines changed

include/swift/AST/PrintOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,6 @@ struct PrintOptions {
436436
/// Suppress 'isolated' and '#isolation' on isolated parameters with optional type.
437437
bool SuppressOptionalIsolatedParams = false;
438438

439-
/// Suppress 'sending' on arguments and results.
440-
bool SuppressSendingArgsAndResults = false;
441-
442439
/// Suppress printing of '~Proto' for suppressible, non-invertible protocols.
443440
bool SuppressConformanceSuppression = false;
444441

include/swift/Basic/Features.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ BASELINE_LANGUAGE_FEATURE(NoncopyableGenerics2, 427, "Noncopyable generics alias
248248
BASELINE_LANGUAGE_FEATURE(ConformanceSuppression, 426, "Suppressible inferred conformances")
249249
BASELINE_LANGUAGE_FEATURE(BitwiseCopyable2, 426, "BitwiseCopyable feature")
250250
BASELINE_LANGUAGE_FEATURE(BodyMacros, 415, "Function body macros")
251-
SUPPRESSIBLE_LANGUAGE_FEATURE(SendingArgsAndResults, 430, "Sending arg and results")
251+
LANGUAGE_FEATURE(SendingArgsAndResults, 430, "Sending arg and results")
252252
BASELINE_LANGUAGE_FEATURE(BorrowingSwitch, 432, "Noncopyable type pattern matching")
253253
BASELINE_LANGUAGE_FEATURE(IsolatedAny, 431, "@isolated(any) function types")
254254
LANGUAGE_FEATURE(IsolatedAny2, 431, "@isolated(any) function types")

include/swift/Parse/Parser.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,8 +1172,7 @@ class Parser {
11721172
return true;
11731173
if (isCallerIsolatedSpecifier())
11741174
return true;
1175-
if (Context.LangOpts.hasFeature(Feature::SendingArgsAndResults) &&
1176-
Tok.isContextualKeyword("sending"))
1175+
if (Tok.isContextualKeyword("sending"))
11771176
return true;
11781177
return false;
11791178
}

lib/AST/ASTPrinter.cpp

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3220,13 +3220,6 @@ void PrintAST::printExtension(ExtensionDecl *decl) {
32203220
}
32213221
}
32223222

3223-
static void
3224-
suppressingFeatureSendingArgsAndResults(PrintOptions &options,
3225-
llvm::function_ref<void()> action) {
3226-
llvm::SaveAndRestore<bool> scope(options.SuppressSendingArgsAndResults, true);
3227-
action();
3228-
}
3229-
32303223
static void
32313224
suppressingFeatureLifetimes(PrintOptions &options,
32323225
llvm::function_ref<void()> action) {
@@ -3854,17 +3847,7 @@ static void printParameterFlags(ASTPrinter &printer,
38543847
}
38553848

38563849
if (flags.isSending()) {
3857-
if (!options.SuppressSendingArgsAndResults) {
3858-
printer.printKeyword("sending", options, " ");
3859-
} else if (flags.getOwnershipSpecifier() ==
3860-
ParamSpecifier::ImplicitlyCopyableConsuming) {
3861-
// Ok. We are suppressing sending. If our ownership specifier was
3862-
// originally implicitly copyable consuming our argument was being passed
3863-
// at +1. By not printing sending, we would be changing the API
3864-
// potentially to take the parameter at +0 instead of +1. To work around
3865-
// this, print out consuming so that we preserve the +1 parameter.
3866-
printer.printKeyword("__owned", options, " ");
3867-
}
3850+
printer.printKeyword("sending", options, " ");
38683851
}
38693852

38703853
if (flags.isIsolated()) {
@@ -4327,14 +4310,12 @@ void PrintAST::visitFuncDecl(FuncDecl *decl) {
43274310
Printer.printDeclResultTypePre(decl, ResultTyLoc);
43284311
Printer.callPrintStructurePre(PrintStructureKind::FunctionReturnType);
43294312

4330-
if (!Options.SuppressSendingArgsAndResults) {
4331-
if (decl->hasSendingResult()) {
4313+
if (decl->hasSendingResult()) {
4314+
Printer << "sending ";
4315+
} else if (auto *ft = llvm::dyn_cast_if_present<AnyFunctionType>(
4316+
decl->getInterfaceType())) {
4317+
if (ft->hasExtInfo() && ft->hasSendingResult()) {
43324318
Printer << "sending ";
4333-
} else if (auto *ft = llvm::dyn_cast_if_present<AnyFunctionType>(
4334-
decl->getInterfaceType())) {
4335-
if (ft->hasExtInfo() && ft->hasSendingResult()) {
4336-
Printer << "sending ";
4337-
}
43384319
}
43394320
}
43404321

@@ -4507,12 +4488,10 @@ void PrintAST::visitSubscriptDecl(SubscriptDecl *decl) {
45074488
Printer.printDeclResultTypePre(decl, elementTy);
45084489
Printer.callPrintStructurePre(PrintStructureKind::FunctionReturnType);
45094490

4510-
if (!Options.SuppressSendingArgsAndResults) {
45114491
if (decl->getElementTypeRepr()) {
45124492
if (isa<SendingTypeRepr>(decl->getResultTypeRepr()))
45134493
Printer << "sending ";
45144494
}
4515-
}
45164495

45174496
PrintWithOpaqueResultTypeKeywordRAII x(Options);
45184497
auto nrOptions = getNonRecursiveOptions(decl);
@@ -6798,8 +6777,7 @@ class TypePrinter : public TypeVisitor<TypePrinter, void, NonRecursivePrintOptio
67986777

67996778
Printer << " -> ";
68006779

6801-
if (!Options.SuppressSendingArgsAndResults && T->hasExtInfo() &&
6802-
T->hasSendingResult()) {
6780+
if (T->hasExtInfo() && T->hasSendingResult()) {
68036781
Printer.printKeyword("sending ", Options);
68046782
}
68056783

lib/AST/FeatureSet.cpp

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -140,56 +140,7 @@ UNINTERESTING_FEATURE(StaticExclusiveOnly)
140140
UNINTERESTING_FEATURE(ExtractConstantsFromMembers)
141141
UNINTERESTING_FEATURE(GroupActorErrors)
142142
UNINTERESTING_FEATURE(SameElementRequirements)
143-
144-
static bool usesFeatureSendingArgsAndResults(Decl *decl) {
145-
auto isFunctionTypeWithSending = [](Type type) {
146-
auto fnType = type->getAs<AnyFunctionType>();
147-
if (!fnType)
148-
return false;
149-
150-
if (fnType->hasExtInfo() && fnType->hasSendingResult())
151-
return true;
152-
153-
return llvm::any_of(fnType->getParams(),
154-
[](AnyFunctionType::Param param) {
155-
return param.getParameterFlags().isSending();
156-
});
157-
};
158-
auto declUsesFunctionTypesThatUseSending = [&](Decl *decl) {
159-
return usesTypeMatching(decl, isFunctionTypeWithSending);
160-
};
161-
162-
if (auto *pd = dyn_cast<ParamDecl>(decl)) {
163-
if (pd->isSending()) {
164-
return true;
165-
}
166-
167-
if (declUsesFunctionTypesThatUseSending(pd))
168-
return true;
169-
}
170-
171-
if (auto *fDecl = dyn_cast<AbstractFunctionDecl>(decl)) {
172-
// First check for param decl results.
173-
if (llvm::any_of(fDecl->getParameters()->getArray(), [](ParamDecl *pd) {
174-
return usesFeatureSendingArgsAndResults(pd);
175-
}))
176-
return true;
177-
if (declUsesFunctionTypesThatUseSending(decl))
178-
return true;
179-
}
180-
181-
// Check if we have a pattern binding decl for a function that has sending
182-
// parameters and results.
183-
if (auto *pbd = dyn_cast<PatternBindingDecl>(decl)) {
184-
for (auto index : range(pbd->getNumPatternEntries())) {
185-
auto *pattern = pbd->getPattern(index);
186-
if (pattern->hasType() && isFunctionTypeWithSending(pattern->getType()))
187-
return true;
188-
}
189-
}
190-
191-
return false;
192-
}
143+
UNINTERESTING_FEATURE(SendingArgsAndResults)
193144

194145
static bool findUnderscoredLifetimeAttr(Decl *decl) {
195146
auto hasUnderscoredLifetimeAttr = [](Decl *decl) {

lib/AST/TypeRepr.cpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -472,20 +472,7 @@ void FunctionTypeRepr::printImpl(ASTPrinter &Printer,
472472
Printer << " -> ";
473473
Printer.callPrintStructurePre(PrintStructureKind::FunctionReturnType);
474474

475-
// Check if we are supposed to suppress sending results. If so, look through
476-
// the ret ty if it is a Sending TypeRepr.
477-
//
478-
// DISCUSSION: The reason why we do this is that Sending TypeRepr is used for
479-
// arguments and results... and we need the arguments case when we suppress to
480-
// print __owned. So this lets us handle both cases.
481-
auto ActualRetTy = RetTy;
482-
if (Opts.SuppressSendingArgsAndResults) {
483-
if (auto *x = dyn_cast<SendingTypeRepr>(RetTy)) {
484-
ActualRetTy = x->getBase();
485-
}
486-
}
487-
printTypeRepr(ActualRetTy, Printer, Opts);
488-
475+
printTypeRepr(RetTy, Printer, Opts);
489476
Printer.printStructurePost(PrintStructureKind::FunctionReturnType);
490477
Printer.printStructurePost(PrintStructureKind::FunctionType);
491478
}
@@ -926,13 +913,7 @@ void SpecifierTypeRepr::printImpl(ASTPrinter &Printer,
926913
Printer.printKeyword("isolated", Opts, " ");
927914
break;
928915
case TypeReprKind::Sending:
929-
// This handles the argument case. The result case is handled in
930-
// FunctionTypeRepr.
931-
if (!Opts.SuppressSendingArgsAndResults) {
932-
Printer.printKeyword("sending", Opts, " ");
933-
} else {
934-
Printer.printKeyword("__owned", Opts, " ");
935-
}
916+
Printer.printKeyword("sending", Opts, " ");
936917
break;
937918
case TypeReprKind::CompileTimeLiteral:
938919
Printer.printKeyword("_const", Opts, " ");

0 commit comments

Comments
 (0)