Skip to content

Commit 31fa694

Browse files
committed
Revert "Merge pull request swiftlang#3853 from milseman/noescape_by_default"
This reverts commit 8219d4f, reversing changes made to e37d048.
1 parent 71de3c9 commit 31fa694

File tree

106 files changed

+1486
-1611
lines changed

Some content is hidden

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

106 files changed

+1486
-1611
lines changed

benchmark/single-source/Integrate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Integrate {
2020

2121
let fun: (Double) -> Double
2222

23-
init (f: @escaping (Double) -> Double) {
23+
init (f: (Double) -> Double) {
2424
fun = f
2525
}
2626

benchmark/utils/DriverUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct Test {
5050
let index: Int
5151
let f: (Int) -> ()
5252
var run: Bool
53-
init(name: String, n: Int, f: @escaping (Int) -> ()) {
53+
init(name: String, n: Int, f: (Int) -> ()) {
5454
self.name = name
5555
self.index = n
5656
self.f = f

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,8 +1821,6 @@ ERROR(autoclosure_function_type,none,
18211821
())
18221822
ERROR(autoclosure_function_input_nonunit,none,
18231823
"autoclosure argument type must be '()'", ())
1824-
1825-
// FIXME: drop these when we drop @noescape
18261824
ERROR(noescape_function_type,none,
18271825
"@noescape may only be applied to parameters of function type",
18281826
())
@@ -1831,7 +1829,6 @@ ERROR(noescape_implied_by_autoclosure,none,
18311829
"redundantly specified", ())
18321830
ERROR(noescape_conflicts_escaping_autoclosure,none,
18331831
"@noescape conflicts with @autoclosure(escaping)", ())
1834-
18351832
ERROR(escaping_function_type,none,
18361833
"@escaping may only be applied to parameters of function type", ())
18371834

@@ -2274,20 +2271,17 @@ WARNING(optional_pattern_match_promotion,none,
22742271
ERROR(type_of_metatype,none,
22752272
"'.dynamicType' is not allowed after a type name", ())
22762273
ERROR(invalid_noescape_use,none,
2277-
"non-escaping %select{value|parameter}1 %0 may only be called",
2274+
"@noescape %select{value|parameter}1 %0 may only be called",
22782275
(Identifier, bool))
22792276
NOTE(noescape_autoclosure,none,
2280-
"parameter %0 is implicitly non-escaping because it was declared @autoclosure",
2281-
(Identifier))
2282-
NOTE(noescape_parameter,none,
2283-
"parameter %0 is implicitly non-escaping",
2277+
"parameter %0 is implicitly @noescape because it was declared @autoclosure",
22842278
(Identifier))
22852279

22862280
ERROR(closure_noescape_use,none,
2287-
"closure use of non-escaping parameter %0 may allow it to escape",
2281+
"closure use of @noescape parameter %0 may allow it to escape",
22882282
(Identifier))
22892283
ERROR(decl_closure_noescape_use,none,
2290-
"declaration closing over non-escaping parameter %0 may allow it to escape",
2284+
"declaration closing over @noescape parameter %0 may allow it to escape",
22912285
(Identifier))
22922286

22932287
ERROR(capture_across_type_decl,none,

include/swift/AST/PrintOptions.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,6 @@ struct PrintOptions {
261261
/// Whether we are printing part of SIL body.
262262
bool PrintInSILBody = false;
263263

264-
/// Whether to print the types as if they appear as function parameters. This
265-
/// governs whether we print a function type with an explicit @escaping. This
266-
/// is also set and restored internally when visiting a type in a parameter
267-
/// position.
268-
bool PrintAsInParamType = false;
269-
270264
/// Whether to use an empty line to separate two members in a single decl.
271265
bool EmptyLineBetweenMembers = false;
272266

include/swift/AST/Types.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2132,6 +2132,7 @@ class AnyFunctionType : public TypeBase {
21322132
enum : uint16_t { AutoClosureMask = 0x010 };
21332133
enum : uint16_t { NoEscapeMask = 0x020 };
21342134
enum : uint16_t { ThrowsMask = 0x040 };
2135+
enum : uint16_t { ExplicitlyEscapingMask = 0x080 };
21352136

21362137
uint16_t Bits;
21372138

@@ -2152,15 +2153,17 @@ class AnyFunctionType : public TypeBase {
21522153

21532154
// Constructor with no defaults.
21542155
ExtInfo(Representation Rep,
2155-
bool IsAutoClosure, bool IsNoEscape,
2156+
bool IsAutoClosure, bool IsNoEscape, bool IsExplicitlyEscaping,
21562157
bool Throws)
21572158
: ExtInfo(Rep, Throws) {
21582159
Bits |= (IsAutoClosure ? AutoClosureMask : 0);
21592160
Bits |= (IsNoEscape ? NoEscapeMask : 0);
2161+
Bits |= (IsExplicitlyEscaping ? ExplicitlyEscapingMask : 0);
21602162
}
21612163

21622164
bool isAutoClosure() const { return Bits & AutoClosureMask; }
21632165
bool isNoEscape() const { return Bits & NoEscapeMask; }
2166+
bool isExplicitlyEscaping() const { return Bits & ExplicitlyEscapingMask; }
21642167
bool throws() const { return Bits & ThrowsMask; }
21652168
Representation getRepresentation() const {
21662169
unsigned rawRep = Bits & RepresentationMask;
@@ -2284,6 +2287,12 @@ class AnyFunctionType : public TypeBase {
22842287
return getExtInfo().isNoEscape();
22852288
}
22862289

2290+
/// \brief True if the parameter declaration it is attached to has explicitly
2291+
/// been marked with the @escaping attribute. This is a temporary measure.
2292+
bool isExplicitlyEscaping() const {
2293+
return getExtInfo().isExplicitlyEscaping();
2294+
}
2295+
22872296
bool throws() const {
22882297
return getExtInfo().throws();
22892298
}

include/swift/Serialization/ModuleFormat.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const uint16_t VERSION_MAJOR = 0;
5353
/// in source control, you should also update the comment to briefly
5454
/// describe what change you made. The content of this comment isn't important;
5555
/// it just ensures a conflict if two people change the module format.
56-
const uint16_t VERSION_MINOR = 259; // Last change: drop explicitlyEscaping
56+
const uint16_t VERSION_MINOR = 258; // Last change: precedencegroup
5757

5858
using DeclID = PointerEmbeddedInt<unsigned, 31>;
5959
using DeclIDField = BCFixed<31>;
@@ -590,6 +590,7 @@ namespace decls_block {
590590
FunctionTypeRepresentationField, // representation
591591
BCFixed<1>, // auto-closure?
592592
BCFixed<1>, // noescape?
593+
BCFixed<1>, // explicitlyEscaping?
593594
BCFixed<1> // throws?
594595
>;
595596

lib/AST/ASTDumper.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2916,11 +2916,8 @@ namespace {
29162916
}
29172917

29182918
printFlag(T->isAutoClosure(), "autoclosure");
2919-
2920-
// Dump out either @noescape or @escaping
2921-
printFlag(T->isNoEscape(), "@noescape");
2922-
printFlag(!T->isNoEscape(), "@escaping");
2923-
2919+
printFlag(T->isNoEscape(), "noescape");
2920+
printFlag(T->isExplicitlyEscaping(), "escaping");
29242921
printFlag(T->throws(), "throws");
29252922

29262923
printRec("input", T->getInput());

lib/AST/ASTPrinter.cpp

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,11 +2535,7 @@ void PrintAST::visitVarDecl(VarDecl *decl) {
25352535
}
25362536

25372537
void PrintAST::visitParamDecl(ParamDecl *decl) {
2538-
// Set and restore in-parameter-position printing of types
2539-
auto prior = Options.PrintAsInParamType;
2540-
Options.PrintAsInParamType = true;
2541-
visitVarDecl(decl);
2542-
Options.PrintAsInParamType = prior;
2538+
return visitVarDecl(decl);
25432539
}
25442540

25452541
void PrintAST::printOneParameter(const ParamDecl *param, bool Curried,
@@ -2593,11 +2589,7 @@ void PrintAST::printOneParameter(const ParamDecl *param, bool Curried,
25932589
TheTypeLoc.setType(BGT->getGenericArgs()[0]);
25942590
}
25952591

2596-
// Set and restore in-parameter-position printing of types
2597-
auto prior = Options.PrintAsInParamType;
2598-
Options.PrintAsInParamType = true;
25992592
printTypeLoc(TheTypeLoc);
2600-
Options.PrintAsInParamType = prior;
26012593

26022594
if (param->isVariadic())
26032595
Printer << "...";
@@ -3321,10 +3313,6 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
33213313
const PrintOptions &Options;
33223314
Optional<std::vector<GenericParamList *>> UnwrappedGenericParams;
33233315

3324-
/// Whether we are printing something in a function parameter position, and
3325-
/// thus want to print @escaping if it escapes.
3326-
bool inParameterPrinting;
3327-
33283316
void printDeclContext(DeclContext *DC) {
33293317
switch (DC->getContextKind()) {
33303318
case DeclContextKind::Module: {
@@ -3492,8 +3480,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
34923480

34933481
public:
34943482
TypePrinter(ASTPrinter &Printer, const PrintOptions &PO)
3495-
: Printer(Printer), Options(PO),
3496-
inParameterPrinting(Options.PrintAsInParamType) {}
3483+
: Printer(Printer), Options(PO) {}
34973484

34983485
void visit(Type T) {
34993486
Printer.printTypePre(TypeLoc::withoutLoc(T));
@@ -3758,10 +3745,11 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
37583745
Printer << "@autoclosure ";
37593746
else
37603747
Printer << "@autoclosure(escaping) ";
3761-
} else if (inParameterPrinting) {
3762-
if (!info.isNoEscape()) {
3763-
Printer << "@escaping ";
3764-
}
3748+
} else if (info.isNoEscape()) {
3749+
// autoclosure implies noescape.
3750+
Printer << "@noescape ";
3751+
} else if (info.isExplicitlyEscaping()) {
3752+
Printer << "@escaping ";
37653753
}
37663754

37673755
if (Options.PrintFunctionRepresentationAttrs) {
@@ -3853,17 +3841,8 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
38533841

38543842
if (needsParens)
38553843
Printer << "(";
3856-
3857-
// Set in-parameter-position printing to print our parameters, then unset it
3858-
// for the return type (in case it is also a function), and restore at the
3859-
// end.
3860-
auto prior = inParameterPrinting;
3861-
inParameterPrinting = true;
3844+
38623845
visit(inputType);
3863-
inParameterPrinting = false;
3864-
SWIFT_DEFER {
3865-
inParameterPrinting = prior;
3866-
};
38673846

38683847
if (needsParens)
38693848
Printer << ")";

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5587,6 +5587,7 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
55875587
swift::AnyFunctionType::ExtInfo newEI(fromEI.getRepresentation(),
55885588
toEI.isAutoClosure(),
55895589
toEI.isNoEscape() | fromEI.isNoEscape(),
5590+
toEI.isExplicitlyEscaping() | fromEI.isExplicitlyEscaping(),
55905591
toEI.throws() & fromEI.throws());
55915592
auto newToType = FunctionType::get(fromFunc->getInput(),
55925593
fromFunc->getResult(), newEI);

lib/Sema/MiscDiagnostics.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -464,16 +464,7 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
464464

465465
TC.diagnose(DRE->getStartLoc(), diag::invalid_noescape_use,
466466
DRE->getDecl()->getName(), isa<ParamDecl>(DRE->getDecl()));
467-
468-
// If we're a parameter, emit a helpful fixit to add @escaping
469-
auto paramDecl = dyn_cast<ParamDecl>(DRE->getDecl());
470-
auto isAutoClosure = AFT->isAutoClosure();
471-
if (paramDecl && !isAutoClosure) {
472-
TC.diagnose(paramDecl->getStartLoc(), diag::noescape_parameter,
473-
paramDecl->getName())
474-
.fixItInsert(paramDecl->getTypeLoc().getLoc(), "@escaping ");
475-
} else if (isAutoClosure)
476-
// TODO: add in a fixit for autoclosure
467+
if (AFT->isAutoClosure())
477468
TC.diagnose(DRE->getDecl()->getLoc(), diag::noescape_autoclosure,
478469
DRE->getDecl()->getName());
479470
}

0 commit comments

Comments
 (0)