-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SE-0155] Implement (Most of) The Proposal #15418
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
Conversation
Alright, it works. Could I get @slavapestov for SIL and @rudkx for Sema? |
@swift-ci please test source compatibility |
@swift-ci please test |
This test case
Triggers this assertion currently. |
@dduan Lowering of applies with tuple shuffle sources needs to go thru the normal apply path instead of the open-coded enum case path which forms ill-typed (to the verifier) payloads. The question is how best to make that distinction in SILGenApply. |
@@ -1078,11 +1079,13 @@ namespace decls_block { | |||
IdentifierIDField, // name | |||
DeclContextIDField,// context decl | |||
TypeIDField, // interface type | |||
BCFixed<1>, // has argument type? |
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.
If you keep this around, you won't need maybeReadParameterList(), you'll know if you're reading a parameter list or not
lib/Sema/TypeCheckPattern.cpp
Outdated
ByVariableNameMismatch, | ||
}; | ||
|
||
auto deriveStrategy = [](const TuplePatternElt &patternElt, const TupleTypeElt &typeElt) { |
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.
What is this for?
lib/Sema/TypeCheckStmt.cpp
Outdated
@@ -207,7 +207,7 @@ static void setAutoClosureDiscriminators(DeclContext *DC, Stmt *S) { | |||
S->walk(ContextualizeClosures(DC)); | |||
} | |||
|
|||
bool TypeChecker::contextualizeInitializer(Initializer *DC, Expr *E) { |
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.
Why is this no longer an Initializer?
lib/Sema/TypeCheckStmt.cpp
Outdated
/*respectVersionedAttr=*/true).isPublic()) | ||
expansion = ResilienceExpansion::Minimal; | ||
|
||
func->setDefaultArgumentResilienceExpansion(expansion); |
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.
You'll need this for enums as well, except I guess we don't need the Swift 3 compatibility part
lib/Sema/TypeChecker.h
Outdated
virtual void resolveAccessControl(ValueDecl *VD) override { | ||
validateAccessControl(VD); | ||
validateAccessibility(VD); |
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.
We don't use the term 'accessibility' since there's potential for confusion with the UI feature
@@ -27,7 +27,7 @@ public struct DispatchData : RandomAccessCollection, _ObjectiveCBridgeable { | |||
case unmap | |||
|
|||
/// A custom deallocator | |||
case custom(DispatchQueue?, @convention(block) () -> Void) | |||
case custom(DispatchQueue?, @convention(block) @escaping () -> Void) |
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.
You'll need to not break source compatibility with this
lib/Parse/ParsePattern.cpp
Outdated
@@ -168,6 +168,21 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc, | |||
SyntaxKind::FunctionParameterList); | |||
} | |||
rightParenLoc = consumeToken(tok::r_paren); | |||
|
|||
// Per SE-0155, enum elements may not have empty parameter lists. | |||
// Diagnose and insert 'Void' where appropriate. |
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.
This needs to be conditional on -swift-version 5, and you need test
lib/Sema/TypeCheckPattern.cpp
Outdated
elt.getLabel(), tupleTy->getElement(i).getName()); | ||
hadError = true; | ||
} | ||
// if (!hadError && !tupleTy->getElement(i).getName().empty() && |
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.
What's this?
lib/Sema/TypeChecker.h
Outdated
@@ -1327,7 +1327,7 @@ class TypeChecker final : public LazyResolver { | |||
void checkDefaultArguments(ArrayRef<ParameterList *> params, ValueDecl *VD); | |||
|
|||
virtual void resolveAccessControl(ValueDecl *VD) override { | |||
validateAccessibility(VD); | |||
validateAccessControl(VD); |
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.
Squash this back to the other patch
@@ -27,7 +27,7 @@ public struct DispatchData : RandomAccessCollection, _ObjectiveCBridgeable { | |||
case unmap | |||
|
|||
/// A custom deallocator | |||
case custom(DispatchQueue?, @convention(block) @escaping () -> Void) |
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.
Stack this patch below the others to avoid test churn
lib/Parse/ParsePattern.cpp
Outdated
@@ -56,9 +56,9 @@ static DefaultArgumentKind getDefaultArgKind(Expr *init) { | |||
llvm_unreachable("Unhandled MagicIdentifierLiteralExpr in switch."); | |||
} | |||
|
|||
void Parser::DefaultArgumentInfo::setFunctionContext(AbstractFunctionDecl *AFD){ | |||
void Parser::DefaultArgumentInfo::setFunctionContext(DeclContext *DC, MutableArrayRef<ParameterList *> paramList){ |
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.
Line too long
lib/Sema/CSApply.cpp
Outdated
@@ -4965,7 +4965,20 @@ getCallerDefaultArg(ConstraintSystem &cs, DeclContext *dc, | |||
unsigned index) { | |||
auto &tc = cs.getTypeChecker(); | |||
|
|||
auto defArg = getDefaultArgumentInfo(cast<ValueDecl>(owner.getDecl()), index); | |||
std::pair<DefaultArgumentKind, Type> defArg; |
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.
This looks like its duplicating code elsewhere (in SIL maybe?)
Nice work @CodaFi!
Which distinction? |
className: exceptionResult["className"]!, | ||
name: exceptionResult["name"]!, | ||
reason: exceptionResult["reason"]!) | ||
exceptionResult["className"]!, |
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.
Why did this change?
lib/Sema/TypeCheckPattern.cpp
Outdated
return true; | ||
} else { | ||
// FIXME: Re-enable this post-discussion on Swift Evolution. |
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.
What's this?
lib/AST/ASTPrinter.cpp
Outdated
@@ -4233,6 +4252,13 @@ void swift::printEnumElementsAsCases( | |||
// If the enum element has no payloads, return. | |||
if (!PL) | |||
return; | |||
|
|||
// Print an empty-but-non-NULL parameter list as '(Void)' |
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.
Why not print it as ()?
@slavapestov Fixed what all I could
The open-coding for
The proposal has a bit of ambiguous wording around how it wants the compiler to handle pattern matching in its post-implementation world. I raised the issue on the mailing list at the time and received some responses, though none from anybody on the Swift team or @rjmccall himself. |
@CodaFi It would be best to refactor the SILGen code so that it could ultimately either emit an apply or an enum_inst (or enum_addr_inst) and handle default arguments in both. Failing that, we should always go through the thunk except in trivial cases like Optional, and try to recover the performance regression. |
6c713a1
to
24e938f
Compare
I'm going to go refresh my memory on the details of the proposal and then take a look at this. |
@rudkx I need your review on the overload resolution bits both in the constraint system and in TypeCheckPattern. |
Cannot wait for this feature to finally see it's light. :) |
43bf0ae
to
e1b31ab
Compare
@DanielAsher Swift 5 is set to early 2019 so I think we're sill good on this feature. However I'm not sure it will make it into Swift 4.2 though. |
@DevAndArtist @CodaFi @rudkx pretty please bring this to Xcode 10 / swift 4.2. |
ab24db2
to
68652e2
Compare
3f047ec
to
74236de
Compare
What is the status of this? @CodaFi @DevAndArtist |
It's being split into smaller chunks. It will not make Swift 5.0. In future, please ask questions like this on the forums. |
😔 |
Best of luck with the implementation for swift 6! |
This has sat un-reviewed for long enough. The last part of the patch is some nits in the original proposal around pattern matching.
In addition, the Sema and SIL plumbing for default arguments in enum cases is there, but does not work in 100% of cases. I have disabled it with a diagnostic in Parse.