Skip to content
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 generic signature superclass constraints to contain type parameters #1263

Closed

Conversation

slavapestov
Copy link
Contributor

@DougGregor, @jckarter Can you take a quick look?

This is NOT for Swift 2.2.

@slavapestov
Copy link
Contributor Author

@swift-ci Please test

1 similar comment
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@@ -5,6 +5,12 @@ Swift 3
* Curried function syntax has been removed, and now produces a compile-time
error.

* Generic signatures can now contain superclass requirements with dependent types,
Copy link
Contributor

Choose a reason for hiding this comment

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

"Dependent types" might give people the wrong impression. 'Superclass requirements involving generic parameters' should be clearer.

@slavapestov
Copy link
Contributor Author

@DougGregor You're right, I believe some compiler_crashers regressed because I was overwriting Superclass. I didn't realize it was an instance variable (can we have mandatory 'this' in C++? Just kidding :-) )

@jckarter
Copy link
Contributor

Just give your class a dependent template base class to get mandatory this->.

@slavapestov
Copy link
Contributor Author

@swift-ci Please test

1 similar comment
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

diag::recursive_superclass_constraint,
Superclass);

superclass = Type();
Copy link
Member

Choose a reason for hiding this comment

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

Not actually necessary.

…ontain type parameters

There was a diagnostic to catch these, but it wasn't triggered
reliably, and it sounds like users were already relying on this
feature working in the few cases where it did.

So instead, just map an archetype's superclass into context
when building the archetype.

Recursion is still not allowed and is diagnosed, for example
<T, U where T : C<U>, U : C<T>>.

Note that compiler_crashers_fixed/00022-no-stacktrace.swift no
longer produces a diagnostic in Sema, despite the fact that the
code is invalid. It does diagnose in IRGen when we map the
type into context. Diagnosing in Sema requires fixing the
declaration checker to correctly handle recursion through a
generic signature. Right now, if recursion is detected, we bail
out, but do not always diagnose. Alternatively, we could
prohibit unbound generic types from appearing in generic
signatures.

This is a more principled fix for rdar://problem/24590570.
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov slavapestov deleted the superclass-requirement-fix branch February 15, 2016 08:39
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.

3 participants