Skip to content

[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

Closed
wants to merge 1 commit into from

Conversation

CodaFi
Copy link
Contributor

@CodaFi CodaFi commented Mar 22, 2018

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.

@CodaFi
Copy link
Contributor Author

CodaFi commented Mar 22, 2018

Alright, it works. Could I get @slavapestov for SIL and @rudkx for Sema?

@CodaFi
Copy link
Contributor Author

CodaFi commented Mar 22, 2018

@swift-ci please test source compatibility

@CodaFi
Copy link
Contributor Author

CodaFi commented Mar 22, 2018

@swift-ci please test

@CodaFi
Copy link
Contributor Author

CodaFi commented Mar 22, 2018

@dduan
Copy link
Contributor

dduan commented Mar 23, 2018

This test case

enum a { case b(n: Int) }
a.b(n:)(3)

Triggers this assertion currently.

@CodaFi
Copy link
Contributor Author

CodaFi commented Mar 23, 2018

@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?
Copy link
Contributor

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

ByVariableNameMismatch,
};

auto deriveStrategy = [](const TuplePatternElt &patternElt, const TupleTypeElt &typeElt) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for?

@@ -207,7 +207,7 @@ static void setAutoClosureDiscriminators(DeclContext *DC, Stmt *S) {
S->walk(ContextualizeClosures(DC));
}

bool TypeChecker::contextualizeInitializer(Initializer *DC, Expr *E) {
Copy link
Contributor

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?

/*respectVersionedAttr=*/true).isPublic())
expansion = ResilienceExpansion::Minimal;

func->setDefaultArgumentResilienceExpansion(expansion);
Copy link
Contributor

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

virtual void resolveAccessControl(ValueDecl *VD) override {
validateAccessControl(VD);
validateAccessibility(VD);
Copy link
Contributor

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)
Copy link
Contributor

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

@@ -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.
Copy link
Contributor

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

elt.getLabel(), tupleTy->getElement(i).getName());
hadError = true;
}
// if (!hadError && !tupleTy->getElement(i).getName().empty() &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this?

@@ -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);
Copy link
Contributor

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)
Copy link
Contributor

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

@@ -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){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line too long

@@ -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;
Copy link
Contributor

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?)

@slavapestov
Copy link
Contributor

Nice work @CodaFi!

The question is how best to make that distinction in SILGenApply.

Which distinction?

className: exceptionResult["className"]!,
name: exceptionResult["name"]!,
reason: exceptionResult["reason"]!)
exceptionResult["className"]!,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this change?

return true;
} else {
// FIXME: Re-enable this post-discussion on Swift Evolution.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this?

@@ -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)'
Copy link
Contributor

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 ()?

@CodaFi
Copy link
Contributor Author

CodaFi commented Mar 26, 2018

@slavapestov Fixed what all I could

Which distinction?

The open-coding for EnumInst in SILGenApply is explicitly set up not to handle tuple shuffles with default arguments. All the SILGen work in this patch plumbs the emission of case-building thunks so they can be emitted as normal applies for that. In the previous PR I tried wiring this up unconditionally and it introduced some odd performance regressions in just a few cases where the optimizer should have seen through it... Regardless, I need some condition I can check so I can properly discern when to emit a normal apply and when to emit the open-coded EnumInst.

FIXME: Re-enable this post-discussion on Swift Evolution.

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.

@slavapestov
Copy link
Contributor

@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.

@rudkx
Copy link
Contributor

rudkx commented Apr 4, 2018

I'm going to go refresh my memory on the details of the proposal and then take a look at this.

@CodaFi
Copy link
Contributor Author

CodaFi commented Apr 4, 2018

@rudkx I need your review on the overload resolution bits both in the constraint system and in TypeCheckPattern.

@DevAndArtist
Copy link
Contributor

Cannot wait for this feature to finally see it's light. :)

@DanielAsher
Copy link

@CodaFi @rudkx Very much looking forward to this implementation for swift 5. Is time running out?

@DevAndArtist
Copy link
Contributor

@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.

@DanielAsher
Copy link

@DevAndArtist @CodaFi @rudkx pretty please bring this to Xcode 10 / swift 4.2.
There are so many use-cases for unified function/enum signatures.

@CodaFi CodaFi force-pushed the case-closed branch 3 times, most recently from ab24db2 to 68652e2 Compare August 24, 2018 19:35
@CodaFi CodaFi force-pushed the case-closed branch 4 times, most recently from 3f047ec to 74236de Compare October 9, 2018 23:06
@rudkx rudkx removed their request for review October 12, 2018 17:33
@IOOI-SqAR
Copy link

What is the status of this? @CodaFi @DevAndArtist

@CodaFi
Copy link
Contributor Author

CodaFi commented Dec 21, 2018

It's being split into smaller chunks. It will not make Swift 5.0. In future, please ask questions like this on the forums.

@CodaFi CodaFi closed this Dec 21, 2018
@CodaFi CodaFi deleted the case-closed branch December 21, 2018 02:37
@DanielAsher
Copy link

😔

@DanielAsher
Copy link

Best of luck with the implementation for swift 6!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants