Commit Graph

731 Commits

Author SHA1 Message Date
Slava Pestov
0c30979f47 Resolve some crashers 2016-09-06 11:52:25 -07:00
swift-ci
05e0cb65fe Merge pull request #4471 from rudkx/remove-assert 2016-08-23 23:35:05 -07:00
Mark Lacey
dc7d433a40 Remove an overzealous assert.
When we are able to type check an expression this assert is fine,
although of little value. In the context of failed type checks, though,
it can be actively harmful.

The issue is that we can attempt to solve smaller parts of the
constraint system and assign contextual types (e.g. for the arguments of
a function) despite not being able to drill into members.

Some of the diagnostics we emit in these cases are not terribly useful,
and I've opened rdar://problem/27982012 with one example.

Resolves:
  rdar://problem/25812474
  rdar://problem/26589865
  rdar://problem/27974638
2016-08-23 21:58:29 -07:00
SpringsUp
f9af1257ef Tighter type-checking of enums with synthesized RawRepresentable
conformance
Fixes SR-2134
2016-08-22 22:49:48 +02:00
Slava Pestov
47898c5962 These tests no longer require asserts to be enabled
Review feedback from @jrose-apple.
2016-08-05 16:26:01 -07:00
Slava Pestov
22aa032285 Sema: Clean up SE-0036 diagnostic a bit
Suggest a fix-it for unqualified references to all static members
from instance context, not just enum elements.

Also, fix a small problem with the fix-it for replacing protocol
names with 'Self' inside extension bodies -- we didn't handle nested
functions properly.
2016-08-05 14:27:16 -07:00
Slava Pestov
75bd88968b SILGen: Allow extensions to define designated initializers of generic types
Previously, if a generic type had a stored property with
a generic type and an initializer expression, we would
emit the expression directly in the body of each designated
initializer.

This is a problem if the designated initializer is defined
within an extension (even in the same source file), because
extensions have a different set of generic parameters and
archetypes.

Also, we've had bugs in the past where emitting an
expression multiple times didn't work properly. While these
might currently all be fixed, this is a tricky case to test
and it would be best to avoid it.

Fix both problems by emitting the initializer expression
inside its own function at the SIL level, and call the
initializer function from each designated initializer.

I'm using the existing 'variable initializer' mangling for this;
it doesn't seem to be used for anything else right now.

Currently, the default memberwise initializer does not use
this, because the machinery for emitting it is somewhat
duplicated and separate from the initializer expressions in
user-defined constructors. I'll clean this up in an upcoming
patch.

Fixes <https://bugs.swift.org/browse/SR-488>.
2016-08-03 01:03:08 -07:00
Chris Lattner
ee52ecccf4 Validation tests shouldn't check for diagnostics. 2016-07-31 16:58:07 -07:00
Joe Groff
c748ba6c12 Merge pull request #3870 from jckarter/no-bridged-default-literal-types
Sema: Don't try bridged classes as default literal types.
2016-07-29 22:16:53 -07:00
Doug Gregor
b9363fe6bd [SE-0111] Enable SE-0111 by default. 2016-07-29 17:28:24 -07:00
Joe Groff
11f03cd8b5 Sema: Don't try bridged classes as default literal types.
One last bit of SE-0072. We shouldn't fall back to bridged classes in the absence of type context for literals anymore. By itself, this kind of hoses the use of literals with NS types, but I think we can get most of the QoI back with overlay changes I plan to propose following this.
2016-07-29 15:18:31 -07:00
Slava Pestov
9a32575cbf Merge pull request #3738 from slavapestov/remove-protocol-typealias-flag
Remove -enable-protocol-typealiases staging flag
2016-07-26 11:41:49 -07:00
David Farler
4a57e647e6 Merge pull request #3762 from bitjammer/se-0081-diagnostic-and-crashes
[SE-0081] Warn on deprecated where clause inside angle brackets
2016-07-26 09:09:30 -07:00
Doug Gregor
5cce5c4d1d [Parser] Refactor parsing of calls and call-like expressions.
Rather than parsing the call arguments (or similar, e.g., subscript)
as a parenthesized expression or tuple, then later reworking that
ParenExpr/TupleExpr if a trailing closure comes along, then digging
through that ParenExpr/TupleExpr to pull out the arguments and
trailing closure... just parse the expression list and trailing
closure together, then directly form the appropriate AST node with
arguments/labels/label locations/trailing closure.

Fixes rdar://problem/19804707, which is an issue where trailing
closures weren't working with unresolved member expressions (e.g.,
".foo {... }"), and is a stepping-stone to SE-0111.
2016-07-26 08:40:11 -07:00
David Farler
7bfaeb57f1 [SE-0081] Warn on deprecated where clause inside angle brackets
and provide a fix-it to move it to the new location as referenced
in SE-0081.

Fix up a few stray places in the standard library that is still using
the old syntax.

Update any ./test files that aren't expecting the new warning/fix-it
in -verify mode.

While investigating what I thought was a new crash due to this new
diagnostic, I discovered two sources of quite a few compiler crashers
related to unterminated generic parameter lists, where the right
angle bracket source location was getting unconditionally set to
the current token, even though it wasn't actually a '>'.
2016-07-26 01:41:10 -07:00
Slava Pestov
1ae8e37058 Remove -enable-protocol-typealiases staging flag
It looks like migration fixits are done, and this doesn't
expose any new bugs that were not possible before, because
you could already define typealiases inside protocol
extensions.

To prevent some compiler_crasher regressions, add a simple
circularity-breaking hack. I'll need to do a sweep to clean
these up some day soon.
2016-07-25 23:18:49 -07:00
Joe Groff
10a0eb1c13 Merge pull request #3710 from jckarter/turn-on-id-as-any
Turn on id as any
2016-07-25 18:58:27 -07:00
Manav Gabhawala
d06d4e5ad7 [AST][Sema] Fixes the IterativeTypeChecker and better manages circular protocol inheritance
The IterativeTypeChecker now use loops instead of recursion to help keep the stack size low
We diagnose circular dependencies for protocols in a more efficient manner and also prevent the possibility of infinite loops
2016-07-25 13:13:13 -07:00
Joe Groff
21c15d8fe9 Update validation tests for id-as-Any. 2016-07-25 06:40:37 -07:00
Jordan Rose
c98a855dbb Rework access checking in terms of "access scopes", and default to 'internal'
Merge pull request #3506 from jrose-apple/private-and-fileprivate

More progress on SE-0025.
2016-07-22 17:27:52 -07:00
Jordan Rose
758cf64283 Rework access checking in terms of "access scopes".
(in preparation for the private/fileprivate split)

An "access scope" is the outermost DeclContext where a particular
declaration may be referenced: for a 'fileprivate' declaration it's
the enclosing file, and for an 'internal' declaration it's the module.
'public' corresponds to a scope of "everything", represented by a null
DeclContext.

This model extends naturally to the (not-yet-implemented) SE-0025
notion of 'private', where the access scope is a declaration's
immediately enclosing DeclContext.

Complicating this model is the revised rules that allow, e.g., a public
declaration to be declared within an internal type. The access scope
for this declaration is still just the module, not "everything".

This commit reworks formal access control checking in terms of this
model, including tightening up some of the handling for '@testable'.
This implements the rule that you must be able to access a declaration's
type everywhere you can reference the declaration.

This was not intended to change compiler behavior, but in practice it
has made cross-file dependency tracking a bit more conservative
(unnecessarily), caught a mistake in diagnosing access violations,
and fixed a fuzzer-based crasher (see test changes).

Progress on SE-0025 ('private' and 'fileprivate')
2016-07-21 14:54:48 -07:00
Doug Gregor
c56f96d237 [Type checker] Synthesize member operator '==' for Equatable enums.
Rather than synthesizing a global operator '==' for Equatable enums,
synthesize a member operator, which is more idiomatic and much
cleaner.

To make sure that these synthesized operators can actually be found,
start considering operator requirements in protocols
more generally in the type checker, so that, e.g., "myEnum == myEnum"
will type-check against Equatable.== and, on successful type-check,
will call the (newly-synthesized) witness for '=='. This both makes it
easier to make sure we find the operators in, e.g., complex multi-file
and lazy-type checking scenarios, and is a step toward the
type-checking improvements described in SE-0091.
2016-07-21 12:54:27 -07:00
Alex Hoppen
095a68b195 [Sema] Disallow accessing enum elements as instance members
This implements SE-0036.
2016-07-20 19:13:58 +02:00
Doug Gregor
80f0852504 [SE-0091] Allow 'static' operators to be declared within types and extensions thereof.
Allow 'static' (or, in classes, final 'class') operators to be
declared within types and extensions thereof. Within protocols,
require operators to be marked 'static'. Use a warning with a Fix-It
to stage this in, so we don't break the world's code.

Protocol conformance checking already seems to work, so add some tests
for that. Update a pile of tests and the standard library to include
the required 'static' keywords.

There is an amusing name-mangling change here. Global operators were
getting marked as 'static' (for silly reasons), so their mangled names
had the 'Z' modifier for static methods, even though this doesn't make
sense. Now, operators within types and extensions need to be 'static'
as written.
2016-07-18 23:18:57 -07:00
Dmitri Gribenko
3fbd61291d tests: adapt to removal of Boolean protocol 2016-07-18 02:41:21 -07:00
Chris Lattner
0917c01922 update validation tests for Boolean removal. 2016-07-17 22:49:20 -07:00
practicalswift
4f89520c93 Case #08008 belongs to "compiler_crashers" (and not "compiler_crashers_2") :-) 2016-07-12 02:04:53 +02:00
gregomni
5bb61795b6 Mark decls that are illegal due to generic inside non-generic decl or non-generic inside generic decl with setInvalid(), and avoid assertions
trying to set the superclass on classes in such situations by setting the superclass of an invalid decl to the error type.

This fixes a bunch of compiler crashes, and also changes some errors in other tests where the main error is the invalid declaration and now the
downstream errors can be a bit different because the decl has been invalidated.
2016-07-06 22:06:50 -07:00
Slava Pestov
5a902935e8 Sema: Explicitly set interface type on all AbstractFunctionDecls
Previously getInterfaceType() would punt to getType() if no
interface type was set. This patch changes getInterfaceType()
to assert if no interface type is set, and updates various
places to set the interface type explicitly.

This brings us a step closer to removing PolymorphicFunctionType.
2016-07-05 00:24:28 -07:00
gregomni
8d02354b76 Return ErrorType for type on invalid extension
This is a better fix for crash 28328 than commit
a870bdbd23. Also fixes additional
crashers.
2016-07-03 14:05:02 -07:00
Chris Lattner
87db7b4cf2 update validation tests to modern syntax. 2016-07-02 17:10:49 -07:00
gregomni
a870bdbd23 Fix for crash 28328. A decl's computeNominalType() can return null, but a bunch of places expect getDeclaredTypeInContext() to never be null so use ErrorType instead. 2016-07-01 23:35:03 -07:00
gregomni
27b7420fff Fix for crash 28290 in findGenericSubstitutions
Early out needs to check that the types don’t contain UnresolvedType,
not just that they aren’t UnresolvedType at the top level.
2016-07-01 10:48:50 -07:00
rjmccall
aa0b05c1a0 Merge pull request #3271 from rjmccall/fix-lookupVisibleDecls-in-AutoClosureExpr
Fix lookupVisibleDecls from inside an AutoClosureExpr.
2016-06-30 01:28:06 -07:00
Doug Gregor
423c1f09da [Type checker] Use call argument matching even with type variables on the left-hand side.
Rather than using a specialized matching rule in the type checker that
depends on having default arguments in types, use call argument
matching consistently.

Note #1: This (correctly) breaks some existing code that depends on
inferring a parameter type of () for a single-argument parameter from
a no-argument function type().

Note #2: This pessimizes a code completion test, where the code
completion engine seems to depend on some quirks of argument
matching. The "type relationship" matching needs non-trivial work.
2016-06-29 20:43:42 -07:00
John McCall
f59c16faac Fix lookupVisibleDecls from inside an AutoClosureExpr. 2016-06-29 19:06:36 -07:00
John McCall
1e1afc569c Check for lazy signature resolution failure when deciding overloadability. 2016-06-29 13:22:34 -07:00
Slava Pestov
004f145ba4 Sema: Fix some problems with generic typealiases
The underlying type can now refer to generic parameters from an
outer context, and we allow qualified and unqualified access to
such typealiases.

One problem remains, with specializations of generic typealiases
in expression parsing context, marked with FIXME in the test.
2016-06-23 23:14:38 -07:00
John McCall
ddf49af810 Handle invalid contexts when computing the super type. 2016-06-22 08:48:12 -07:00
Slava Pestov
b46b433336 Just-added compiler_crasher is already fixed :) 2016-06-18 17:15:25 -07:00
Slava Pestov
5b4ee41772 Parser: Diagnose if free-standing 'where' clause is attached to a non-generic declaration
Previously we would produce an empty GenericParamList, crashing Sema.
2016-06-18 17:15:25 -07:00
Slava Pestov
7814c47b71 AST: Slightly change meaning of NominalTypeDecl::getDeclaredType()
Consider this code:

struct A<T> {
  struct B {}
  struct C<U> {}
}

Previously:

- getDeclaredType() of 'A.B' would give 'A<T>.B'
- getDeclaredTypeInContext() of 'A.B' would give 'A<T>.B'

- getDeclaredType() of 'A.C' would give 'A<T>.C'
- getDeclaredTypeInContext() of 'A.C' would give 'A<T>.C<U>'

This was causing problems for nested generics. Now, with this change,

- getDeclaredType() of 'A.B' gives 'A.B' (*)
- getDeclaredTypeInContext() of 'A.B' gives 'A<T>.B'
- getDeclaredType() of 'A.C' gives 'A.C' (*)
- getDeclaredTypeInContext() of 'A.C' gives 'A<T>.C<U>'

(Differences marked with (*)).

Also, this change makes these accessors fully lazy. Previously,
only getDeclaredTypeInContext() and getDeclaredIterfaceType()
were lazy, whereas getDeclaredType() was built from validateDecl().

Fix a few spots where the return value wasn't being checked
properly.

These functions return ErrorType if a circularity was detected via
the generic parameter list, or if the extension did not resolve.
They return Type() if the extension cannot be resolved *yet*.

This is pretty subtle, and I'll need to do another pass over
callers of these functions at some point. Many of them should be
moved over to use getSelfInContext(), getSelfOfContext() and
getSelfInterfaceType() instead.

Finally, this patch consolidates logic for diagnosting invalid
nesting of types.

The parser had some code for protocols in bad places and bad things
inside protocols, and Sema had several different bail-outs for
bad things in protocols, nested generic types, and stuff nested
inside protocol extensions.

Combine all of these into a single set of checks in Sema. Note
that we no longer give up early if we find invalid nesting.
Leaving decls unvalidated and un-type-checked only leads to
further problems. Now that all the preliminary crap has been
fixed, we can go ahead and start validating these funny nested
decls, actually fixing some crashers in the process.
2016-06-18 17:15:24 -07:00
Slava Pestov
0fc095c775 Sema: Re-arrange deck chairs again
Another pre-emptive compiler_crasher regression fix.

I have an idea for consolidating some of these hacky circularity
checks in a nice way, but not now.
2016-06-18 17:05:28 -07:00
Slava Pestov
7b6736df29 Sema: When validating a nested type, only validate the parent, do not type check it
There's no need to walk the siblings of the nested type. This fixes
a class of infinite recursion issues when inheriting from nested
types.
2016-06-18 17:05:27 -07:00
Slava Pestov
528a4a547c Sema: Clean up some code duplication when validating generic type signatures
Every call to validateGenericTypeSignature() had the same
boilerplate following; move the common logic into that
function.

As one might expect, each callsite had slight variants on
the same underlying logic -- this makes them consistent.

Also, this slightly widens the scope during which
GenericTypeDecl::isValidatingGenericSignature() returns
true.

Interesting, that change introduces a diagnostic in an
existing testcase where previously there was none:

protocol P {
  associatedtype T
}

struct S<A: P where A.T == S<A>> {}

While it looks like this generic signature was built
correctly, in fact I think we weren't computing
conformances for the substitution of 'A' in 'S<A>'.

After trying small variations on the above testcase,
I quickly ran into SILGen crashes, which the diagnostic
now prevents. A few interesting cases still crash.
See test/decl/protocol/req/recursion.swift for the
gory details.
2016-06-18 17:05:27 -07:00
Slava Pestov
4446bc0692 Sema: Use FoldingSetNode for ProtocolType
There was a weirdness with ProtocolType::get() that was causing me grief
while trying to refactor getDeclaredType() and related code in another
patch.

Instead of caching the result like we do elsewhere, this would directly
store the new type into the ProtocolDecl. This is smelly, so let's not
do that.
2016-06-16 22:55:17 -07:00
Slava Pestov
769a5a2048 Sema: Small cleanups
Mostly NFC, but note that DeclContext::getDeclaredInterfaceType()
returns Type() for invalid extensions, whereas the older way
of going through getAsNominalTypeOrNominalTypeExtensionContext()
would crash because we'd call getDeclaredInterfaceType() on a
null decl.
2016-06-16 22:54:27 -07:00
Slava Pestov
bb6521b9b6 Sema: Improve a circularity-breaking hack
The old check was problematic because it would sometimes return
ErrorType from accessing the generic parameters of a type that was
in the process of having its generic signature validated.

Instead fix the root cause of the circularity, which was recursion
through resolveType() when resolving a type's inheritance clause.

To fix it, let's just not walk adopted protocols when looking up
the superclass of a class. Inheriting from an associated type does
not seem very useful, and will probably be hard to get right in
the general case.

I wasn't able to reduce a useful test case, but this patch prevents
compiler_crashers regressions with some other changes I'm working on.
2016-06-16 22:54:07 -07:00
Slava Pestov
e5f0cf93a9 Sema: Pass down NL_OnlyTypes in a couple more places 2016-06-16 22:54:07 -07:00
Slava Pestov
92d5bd2404 Sema: Fix when opening type with minOpeningDepth != 0
This fixes a regression from my previous patch fixing some issues
with nested generic functions:

<bbefeb2fc5>
2016-06-16 22:52:19 -07:00