-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow return to be omitted from single expression functions. #23251
Allow return to be omitted from single expression functions. #23251
Conversation
@swift-ci please test source compatibility |
1 similar comment
@swift-ci please test source compatibility |
@swift-ci please test source compatibility |
Forgot the summary at the top of "This looks pretty good; I'm glad it doesn't seem to take too many changes; good job listing out test cases." Some other things to check:
|
@swift-ci please test source compatibility |
2 similar comments
@swift-ci please test source compatibility |
@swift-ci please test source compatibility |
@swift-ci please test source compatibility |
@swift-ci please test |
Build failed |
Build failed |
@swift-ci please test |
Build failed |
Build failed |
3d5bb41
to
a42c2c1
Compare
@swift-ci please test |
Build failed |
@swift-ci please test source compatibility |
Match the behavior of typeCheckExpressionImpl which simply calls solve and applySolution but never salvage.
When type-checking a return statement's result, pass a new ContextualTypePurpose when that return statement appears in a function with a single expression. When solving the corresponding constraint system, the conversion constraint will have a new ConstraintKind. When matching types, check whether the constraint kind is this new kind, meaning that the constraint is between a function's single expression and the function's result. If it is, allow a conversion from an uninhabited type (the expression's type) to anything (the function's result type) by adding an uninhabited upcast restriction to the vector of conversions. Finally, at coercion time, upon encountering this restriction, call coerceUninhabited, replacing the original expression with an UninhabitedUpcastExpr. Finally, at SILGen time, treat this UninhabitedUpcastExpr as a ForcedCheckedCastExpr. Eliminates the bare ConstraintSystem usage from typeCheckFunctionBodyUntil, ensuring that the same code path is followed for all function bodies.
Modified so that single-expression implicit return does not throw off tests.
Added objc_interop requirement to tests which require it and moved one test into file stating that requirement.
…l type of single expr function
…f single expr function
Corrected a number of diagnostic regressions.
23ad54a
to
f8ef213
Compare
@swift-ci please test |
Build failed |
Build failed |
@swift-ci Please clean smoke test OS X platform |
@swift-ci please clean smoke test OS X platform |
@swift-ci please clean test OS X platform |
@nate-chandler this broke the Windows test suite! |
// RUN: cp %s %t/main.swift | ||
// RUN: %target-build-swift -Xfrontend -playground -Xfrontend -disable-playground-transform -o %t/main %t/main.swift | ||
// RUN: %target-codesign %t/main | ||
// RUN: ! %target-run %t/main --crash 2>&1 | %FileCheck -check-prefix=CRASH-CHECK %s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use not.py next time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we prefer LLVM's not --crash
.
if (numElements > 0) { | ||
auto element = BS->getElement(numElements - 1); | ||
if (auto expr = element.dyn_cast<Expr *>()) { | ||
if (expr->getType()->getCanonicalType() == ResTy->getCanonicalType()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypeBase::isEqual() is a shortcut for comparing getCanonicalType()s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR with a fix at #24546 .
auto Element = BS->getElement(0); | ||
if (auto *stmt = Element.dyn_cast<Stmt *>()) { | ||
auto kind = AFD->getKind(); | ||
if (kind == DeclKind::Var || kind == DeclKind::Subscript || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFD is an AbstractFunctionDecl so it will never have a kind that is Var or Subscript. In general we prefer to use isa<>
instead of checking the kind directly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR with a fix at #24546 .
Enables return to be omitted from function bodies which consist of only a single expression.