Skip to content

Commit 35db50a

Browse files
authored
Merge pull request #22665 from slavapestov/remove-noreturn
Sema: Remove @NoReturn attribute support
2 parents c2f8622 + 112f6e0 commit 35db50a

File tree

7 files changed

+4
-136
lines changed

7 files changed

+4
-136
lines changed

include/swift/AST/Attr.def

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
// Type attributes
5050
TYPE_ATTR(autoclosure)
5151
TYPE_ATTR(convention)
52-
TYPE_ATTR(noreturn)
5352
TYPE_ATTR(noescape)
5453
TYPE_ATTR(escaping)
5554

@@ -136,9 +135,7 @@ CONTEXTUAL_SIMPLE_DECL_ATTR(optional, Optional,
136135
SIMPLE_DECL_ATTR(dynamicCallable, DynamicCallable,
137136
OnNominalType,
138137
6)
139-
SIMPLE_DECL_ATTR(noreturn, NoReturn,
140-
OnFunc | OnAccessor,
141-
7)
138+
// NOTE: 7 is unused
142139
SIMPLE_DECL_ATTR(_exported, Exported,
143140
OnImport |
144141
UserInaccessible,

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,9 +1508,6 @@ WARNING(function_type_usable_from_inline_warn,none,
15081508
"'@usableFromInline' %select{function|method|initializer}0 "
15091509
"should be '@usableFromInline' or public",
15101510
(unsigned, bool))
1511-
ERROR(noreturn_not_supported,none,
1512-
"'@noreturn' has been removed; functions that never return should have a "
1513-
"return type of 'Never' instead", ())
15141511

15151512
// Extensions
15161513
ERROR(non_nominal_extension,none,

lib/Sema/TypeCheckAttr.cpp

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -123,66 +123,6 @@ class AttributeEarlyChecker : public AttributeVisitor<AttributeEarlyChecker> {
123123
IGNORED_ATTR(PrivateImport)
124124
#undef IGNORED_ATTR
125125

126-
// @noreturn has been replaced with a 'Never' return type.
127-
void visitNoReturnAttr(NoReturnAttr *attr) {
128-
if (auto FD = dyn_cast<FuncDecl>(D)) {
129-
auto &SM = TC.Context.SourceMgr;
130-
131-
auto diag = TC.diagnose(attr->getLocation(),
132-
diag::noreturn_not_supported);
133-
auto range = attr->getRangeWithAt();
134-
if (range.isValid())
135-
range.End = range.End.getAdvancedLoc(1);
136-
diag.fixItRemove(range);
137-
138-
auto *last = FD->getParameters();
139-
140-
// If the declaration already has a result type, we're going
141-
// to change it to 'Never'.
142-
bool hadResultType = false;
143-
bool isEndOfLine = false;
144-
SourceLoc resultLoc;
145-
if (FD->getBodyResultTypeLoc().hasLocation()) {
146-
const auto &typeLoc = FD->getBodyResultTypeLoc();
147-
hadResultType = true;
148-
resultLoc = typeLoc.getSourceRange().Start;
149-
150-
// If the function 'throws', insert the result type after the
151-
// 'throws'.
152-
} else {
153-
if (FD->getThrowsLoc().isValid()) {
154-
resultLoc = FD->getThrowsLoc();
155-
156-
// Otherwise, insert the result type after the final parameter
157-
// list.
158-
} else if (last->getRParenLoc().isValid()) {
159-
resultLoc = last->getRParenLoc();
160-
}
161-
162-
if (Lexer::getLocForEndOfToken(SM, resultLoc).getAdvancedLoc(1) ==
163-
Lexer::getLocForEndOfLine(SM, resultLoc))
164-
isEndOfLine = true;
165-
166-
resultLoc = Lexer::getLocForEndOfToken(SM, resultLoc);
167-
}
168-
169-
if (hadResultType) {
170-
diag.fixItReplace(resultLoc, "Never");
171-
} else {
172-
std::string fix = " -> Never";
173-
174-
if (!isEndOfLine)
175-
fix = fix + " ";
176-
177-
diag.fixItInsert(resultLoc, fix);
178-
}
179-
180-
auto neverType = TC.Context.getNeverType();
181-
if (neverType)
182-
FD->getBodyResultTypeLoc() = TypeLoc::withoutLoc(neverType);
183-
}
184-
}
185-
186126
void visitAlignmentAttr(AlignmentAttr *attr) {
187127
// Alignment must be a power of two.
188128
auto value = attr->getValue();
@@ -821,7 +761,6 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
821761
IGNORED_ATTR(Mutating)
822762
IGNORED_ATTR(NonMutating)
823763
IGNORED_ATTR(NonObjC)
824-
IGNORED_ATTR(NoReturn)
825764
IGNORED_ATTR(NSManaged) // checked early.
826765
IGNORED_ATTR(ObjC)
827766
IGNORED_ATTR(ObjCBridged)

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,6 @@ namespace {
12731273
UNINTERESTING_ATTR(NonMutating)
12741274
UNINTERESTING_ATTR(NonObjC)
12751275
UNINTERESTING_ATTR(NonOverride)
1276-
UNINTERESTING_ATTR(NoReturn)
12771276
UNINTERESTING_ATTR(NSApplicationMain)
12781277
UNINTERESTING_ATTR(NSCopying)
12791278
UNINTERESTING_ATTR(NSManaged)

lib/Sema/TypeCheckType.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,7 +2031,7 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
20312031
// Pass down the variable function type attributes to the
20322032
// function-type creator.
20332033
static const TypeAttrKind FunctionAttrs[] = {
2034-
TAK_convention, TAK_noreturn, TAK_pseudogeneric,
2034+
TAK_convention, TAK_pseudogeneric,
20352035
TAK_callee_owned, TAK_callee_guaranteed, TAK_noescape, TAK_autoclosure,
20362036
TAK_escaping, TAK_yield_once, TAK_yield_many
20372037
};
@@ -2165,17 +2165,6 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
21652165
attrs.clearAttribute(TAK_autoclosure);
21662166
}
21672167

2168-
// @noreturn has been replaced with a 'Never' return type.
2169-
if (attrs.has(TAK_noreturn)) {
2170-
auto loc = attrs.getLoc(TAK_noreturn);
2171-
auto attrRange = getTypeAttrRangeWithAt(Context, loc);
2172-
auto resultRange = fnRepr->getResultTypeRepr()->getSourceRange();
2173-
2174-
diagnose(loc, diag::noreturn_not_supported)
2175-
.fixItRemove(attrRange)
2176-
.fixItReplace(resultRange, "Never");
2177-
}
2178-
21792168
// Resolve the function type directly with these attributes.
21802169
FunctionType::ExtInfo extInfo(rep, attrs.has(TAK_noescape),
21812170
fnRepr->throws());

test/IDE/complete_decl_attribute.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@
3434
@#^KEYWORD2^#
3535
func method(){}
3636

37-
// KEYWORD2: Begin completions, 11 items
37+
// KEYWORD2: Begin completions, 10 items
3838
// KEYWORD2-NEXT: Keyword/None: available[#Func Attribute#]; name=available{{$}}
3939
// KEYWORD2-NEXT: Keyword/None: objc[#Func Attribute#]; name=objc{{$}}
40-
// KEYWORD2-NEXT: Keyword/None: noreturn[#Func Attribute#]; name=noreturn{{$}}
4140
// KEYWORD2-NEXT: Keyword/None: IBAction[#Func Attribute#]; name=IBAction{{$}}
4241
// KEYWORD2-NEXT: Keyword/None: NSManaged[#Func Attribute#]; name=NSManaged{{$}}
4342
// KEYWORD2-NEXT: Keyword/None: inline[#Func Attribute#]; name=inline{{$}}
@@ -91,11 +90,10 @@ struct S{}
9190

9291
@#^KEYWORD_LAST^#
9392

94-
// KEYWORD_LAST: Begin completions, 22 items
93+
// KEYWORD_LAST: Begin completions, 21 items
9594
// KEYWORD_LAST-NEXT: Keyword/None: available[#Declaration Attribute#]; name=available{{$}}
9695
// KEYWORD_LAST-NEXT: Keyword/None: objc[#Declaration Attribute#]; name=objc{{$}}
9796
// KEYWORD_LAST-NEXT: Keyword/None: dynamicCallable[#Declaration Attribute#]; name=dynamicCallable
98-
// KEYWORD_LAST-NEXT: Keyword/None: noreturn[#Declaration Attribute#]; name=noreturn{{$}}
9997
// KEYWORD_LAST-NEXT: Keyword/None: dynamicMemberLookup[#Declaration Attribute#]; name=dynamicMemberLookup
10098
// KEYWORD_LAST-NEXT: Keyword/None: NSCopying[#Declaration Attribute#]; name=NSCopying{{$}}
10199
// KEYWORD_LAST-NEXT: Keyword/None: IBAction[#Declaration Attribute#]; name=IBAction{{$}}

test/attr/attr_noreturn.swift

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)