Commit Graph

103 Commits

Author SHA1 Message Date
Doug Gregor
823c24b355 [SE-0112] Rename ErrorProtocol to Error.
This is bullet (5) of the proposed solution in SE-0112, and the last
major piece to be implemented.
2016-07-12 10:53:52 -07:00
Ben Langmuir
75619c02c4 [CodeCompletion] Improve StmtCondition recovery for code-completion
In the condition expressions of if, while and guard statements we were
throwing away the AST if there was a parse error in the condition, or
the brace statement was missing.  This led to poor code-completion for
unresolved members (enums, options sets) because we couldn't find the
parent expression to type-check.

There are a few minor diagnostic changes because we now do more
type-checking of these conditions, particularly if they end up
containing an unused closure.

SR-2001
2016-07-06 14:08:53 -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
edc29363ed For some reason this crasher was not in crashers_fixed 2016-06-18 17:05:26 -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
bbefeb2fc5 Sema: Better support for nested generic functions
There was a weird corner case with nested generic functions that
would fail in the SIL verifier with some nonsense about archetypes
out of context.

Fix this the "right" way, by re-working Sema function declaration
validation to assign generic signatures in a more principled way.

Previously, nested functions did not get an interface type unless
they themselves had generic parameters.

This was inconsistent with methods nested inside generic types,
which did get an interface type even if they themselves did not
have a generic parameter list.

There's some spill-over in SILGen from this change. Mostly it
makes things more consistent and fixes some corner cases.
2016-06-13 01:22:43 -07:00
Slava Pestov
3127264376 AST: When performing qualified lookup of a member type, filter out non-types earlier
With the previous resolveTypeInContext() patch, a few compiler
crashers regressed with this problem, presumably because we were now
performing lookups in more contexts than before.

This is a class of problems where we would attempt a recursive
validation:

1) Generic signature validation begins for type T
2) Name lookup in type context finds a non-type declaration D nested in T
3) Generic signature validation begins for D
4) The outer generic context of D is T, but T doesn't have a generic
   signature yet

The right way to break such cycles is to implement the iterative
decl checker design. However when the recursion is via name lookup,
we can try to avoid the problem in the first place by not validating
non-type declarations if the client requested a type-only lookup.

Note that there is a small semantic change here, where programs that
were previously rejected as invalid because of name clashes are
now valid. It is arguable if we want to allow stuff like this or not:

class A {
  func A(a: A) {}
}

or

class Case {}
enum Foo {
  case Case(Case)
}

However at the very least, the new behavior is better because it
gives us an opportunity to add a diagnostic in the right place
later. The old diagnostics were not very good, for example the
second example just yields "use of undeclared type 'Case'".
In other examples, the undeclared type diagnostic would come up
multiple times, or we would generate a cryptic "type 'A' used within
its own definition".

As far as I understand, this should not change behavior of any existing
valid code.
2016-06-11 16:27:43 -07:00
Slava Pestov
e8abf54a9a Sema: Fixes for protocol typealiases
This is a big refactoring of resolveTypeInContext() which makes
the function clearer to understand by merging various special
cases and generalizing the logic for walking parent and superclass
contexts to cover more cases.

This improves typealiases in protocols a bit:

1) Previously a typealias in a protocol either had to be concrete,
   or consist of a single path of member types from Self, eg
   Self.A.B. Lift this restriction, so we can now write things like

protocol Fireworks {
  associatedtype Exploding
  typealias Exploder = Exploding -> [Exploding]
}

2) Protocol typealiases can now be accessed via qualified lookup
   on concrete types. Getting this working for unqualified lookup
   requires further refactorings which will be in a subsequent
   patch.
2016-06-11 16:24:14 -07:00
Dmitri Gribenko
14d0be2099 Revert "Sema: Clean up resolveTypeInContext() and generalize typealiases in protocols"
This reverts commit 586288312c.  It broke
tests:

    Swift :: IDE/complete_override_access_control.swift
    Swift :: IDE/complete_value_expr.swift
    Swift :: SourceKit/DocSupport/doc_swift_module.swift
    Swift :: decl/typealias/associated_types.swift
    Swift :: decl/typealias/typealias.swift
2016-06-09 00:06:06 -07:00
Slava Pestov
586288312c Sema: Clean up resolveTypeInContext() and generalize typealiases in protocols
Previously a typealias in a protocol either had to be concrete,
or consist of a single path of member types from Self, eg
Self.A.B. Lift this restriction.

Fix a few other corner cases that came up in the validation
suite, and clean up the function in general.
2016-06-08 20:17:59 -07:00
Slava Pestov
2c21b81910 AST: Clean up archetype mangling
Now that we have ArchetypeBuilder::mapTypeOutOfContext(), we can
delete some tricky hand-crafted logic for getting the depth and
index of archetypes.

Notice that the depth of an archetype is now the same as generic
parameters, where depth 0 is the outermost generic context.
Previously it was backwards.

Mostly NFC, except that a few IDE crashers are now fixed because
of asserts firing in removed code, and also the change to depth
mangling (which I think makes sense, and it matches what's written
in docs/ABI.rst).
2016-06-01 12:54:43 -07:00
John McCall
5c83792a8f Pad my commit count by carefully splitting the actual test change from
the commit that moved the test to the fixed directory.
2016-05-24 11:15:29 -07:00
John McCall
95c9d1fe7e "Fix" this crasher test by marking it resolved. 2016-05-24 11:09:55 -07:00
Slava Pestov
afd383f271 One more time -- utils/resolve_crashers.py doesn't do the right thing for IDE crashers 2016-05-21 14:42:40 -07:00
Slava Pestov
c69df44a83 Generic initializer inheritance changes fixed this IDE crasher that I forgot about 2016-05-21 13:52:45 -07:00
Ben Langmuir
78e2e59351 [IDE] Fix crasher 063-swift-generictypeparamtype-get.swift
This test was crashing (except under asan) because we were using dead
pointers to stack memory where a TypeChecker used to live.
2016-03-21 11:39:43 -07:00
Ben Langmuir
812d1566a7 [CodeCompletion] Don't look through non-type contexts in override
We don't actually want to skip non-type contexts here, since we should
only be showing override completions in the type context itself. This
was pretty obscure to hit in practice, but I noticed it while fixing the
crasher.
2016-03-12 08:39:11 -08:00
Ben Langmuir
5bbc06b35c [CodeCompletion] Fix override completion parser lookback issues
This allows us to get override completions correct when
* There are multiple decls on one line
* The preceding attributes/keywords span multiple lines

Resolving a longstanding FIXME.
2016-03-11 23:00:11 -08:00
Ben Langmuir
47723848bd [CodeCompletion] Fix crash in override completion in a bogus context
Use the right context for getting the formal access. To get the
completions right, we should fix the FIXME about not backtracking the
parser so far.
2016-03-11 17:15:19 -08:00
Xi Ge
615d4cb756 [test] Remove 'not' because code completion prints result. 2016-02-27 22:52:31 -08:00
Xi Ge
380bc11c0e [test] Mark an IDE crash as fixed. 2016-02-27 22:01:20 -08:00
Dmitri Gribenko
a257715fcc Revert "[stdlib] [SE-0031] update stdlib for SE-0031 (inout adjustment)" 2016-02-26 11:17:10 -08:00
Daniel Duan
13b5c8f3bc [SE-0031] update code base for SE-0031 (inout adjustment) 2016-02-26 10:52:10 -08:00
Dmitri Gribenko
084e284c3f Mark a crash test as fixed 2016-02-02 17:03:54 -08:00
Chris Lattner
7c97117d77 Fix IDE crashers 027, 066, and 068.
Expand the "skip" functions in the parser to be more careful about
not skipping passed a #endif or a code completion token, since they
are synchronization points for the parser.

The fix was to change Parser::delayParseFromBeginningToHere to use
a manual loop instead of skipUntil (which can stop early for non-EOF
tokens).
2016-02-01 16:36:28 -08:00
Chris Lattner
ff34db7950 fix a few compiler crashers
These were due to CSDiags not reverting the semantic expr embedded in CollectionExprs
when retypechecking them.
2016-01-29 21:13:57 -08:00
Dmitri Gribenko
d7b05d647b Really mark the crash test as fixed 2016-01-29 19:38:36 -07:00
Chris Lattner
2715a9e46e Another testcase fixed by recent patches. 2016-01-29 17:04:26 -08:00
Slava Pestov
3550897090 The previous patch accidentally fixed some compiler_crashers 2016-01-27 23:51:20 -08:00
Dmitri Gribenko
220bac09a7 Remove 'asserts' requirements from fixed compiler crash tests 2016-01-20 14:40:36 -08:00
Chris Lattner
a2ea7b1335 Recent fixes fixed this testcase as well. 2016-01-17 13:11:38 -08:00
Chris Lattner
8bac0868c3 My changes fixed this test, and swift-ide-test is returning a successful exit code,
I should have removed the "not" as well as the --crash.
2016-01-12 16:04:40 -08:00
Ben Langmuir
93e3c72883 [swift-ide-test] Don't go past the end of input in removeCodeCompletionTokens
When matching an incomplete code-completion token #^...
2016-01-12 11:28:11 -08:00
Erik Eckstein
206d410cdc disable an IDE test to unblock the bots 2016-01-12 08:13:46 -08:00
Chris Lattner
2f78b70857 recent diagnostics changes fixed 5 crashers and broke 1. 2016-01-11 22:43:27 -08:00
Slava Pestov
cbb95a2910 Merge pull request #926 from jtbandes/innermost-params
[AST] Fix inconsistent handling of generic args & params during BoundGenericType::getSubstitutions
2016-01-09 23:30:06 -08:00
Jacob Bandes-Storch
b97cb48c2b [AST] Fix inconsistent handling of generic args & params during BoundGenericType::getSubstitutions
A decl’s full GenericSignature is set during validateGenericTypeSignature().

Then during ConstraintSystem::openTypes(), in ReplaceDependentTypes, the GenericArgs list is built from the generic signature (via getGenericParamTypes()) and passed into a new BoundGenericType.

In BoundGenericType::getSubstitutions(), the GenericArgs are assumed to match getGenericParamsOfContext()->getParams().

However, in reality, the GenericArgs include all levels of generic args, whereas getGenericParamsOfContext() are the params of the innermost context only, so the params array is accessed past its end.

This commit changes NominalTypeDecl::getGenericParamTypes() to return the innermost params, in order to match the output of BoundGenericType::getGenericArgs(). For clarity and to hopefully prevent future confusion, we also rename getGenericParamTypes() to getInnermostGenericParamTypes().
2016-01-09 02:19:28 -08:00
John McCall
e21b71a4e7 This test has been fixed. 2016-01-08 22:49:03 -08:00
practicalswift
0f256b7fe8 Fix IDE test suite: Update with expected exit code (0). 2016-01-08 22:44:10 +01:00
practicalswift
db9fa33be6 Move to IDE/crashers_fixed/
Fixed thanks to @nkcsgexi:s commit f5f796b648 :-)
2016-01-08 22:30:26 +01:00
Xi Ge
40c1622a6d [test] Update test after fixing a crash. 2016-01-05 21:05:08 -08:00
Chris Lattner
5d6c20b0b6 fix 058-swift-constraints-constraintsystem-diagnosefailureforexpr.swift
CSDiag's wasn't considering the case when an operator was invalid and had ErrorType.
2015-12-23 17:28:08 -08:00
Chris Lattner
1a090b0c04 This test got fixed along the way. 2015-12-22 20:21:12 -08:00
Dmitri Gribenko
430a324edd Revert "Add crash case (see #587) for fixed bug to crashers_fixed/" 2015-12-20 03:44:22 -08:00
Dmitri Gribenko
9eef2fb018 Merge pull request #607 from practicalswift/add-ide-crash-024-as-fixed
Add crash case (see #587) for fixed bug to crashers_fixed/
2015-12-20 00:44:17 -08:00
Jacob Bandes-Storch
ac95c1318f More error checking for member type lookup 2015-12-17 01:50:53 -08:00
Mark Lacey
931966ad42 Move a no-longer-crashing swift-ide-test over. 2015-12-16 16:49:44 -08:00
practicalswift
1875e57551 Add crash case (see #587) for fixed bug to crashers_fixed/ 2015-12-16 22:30:58 +01:00
practicalswift
83181f5c02 [SourceKit] Add test case for crash triggered in swift::TypeBase::getMemberSubstitutions(swift::DeclContext*)
Stack trace:

```
found code completion token A at offset 143
swift-ide-test: /path/to/swift/lib/AST/Type.cpp:2492: TypeSubstitutionMap swift::TypeBase::getMemberSubstitutions(swift::DeclContext *): Assertion `baseTy && "Couldn't find appropriate context"' failed.
8  swift-ide-test  0x0000000000b957c0 swift::TypeBase::getMemberSubstitutions(swift::DeclContext*) + 432
9  swift-ide-test  0x0000000000b95abd swift::TypeBase::getTypeOfMember(swift::ModuleDecl*, swift::Type, swift::DeclContext*) + 61
10 swift-ide-test  0x000000000098363b swift::TypeChecker::resolveTypeInContext(swift::TypeDecl*, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, bool, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) + 1435
14 swift-ide-test  0x0000000000983f0e swift::TypeChecker::resolveIdentifierType(swift::DeclContext*, swift::IdentTypeRepr*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, bool, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) + 158
16 swift-ide-test  0x0000000000984e54 swift::TypeChecker::resolveType(swift::TypeRepr*, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) + 164
19 swift-ide-test  0x0000000000ae41e5 swift::Expr::walk(swift::ASTWalker&) + 69
20 swift-ide-test  0x00000000008ccec8 swift::constraints::ConstraintSystem::generateConstraints(swift::Expr*) + 200
21 swift-ide-test  0x0000000000916120 swift::TypeChecker::solveForExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::FreeTypeVariableBinding, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem&, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 256
22 swift-ide-test  0x000000000091c6c9 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*) + 569
23 swift-ide-test  0x000000000091d7e0 swift::TypeChecker::typeCheckBinding(swift::Pattern*&, swift::Expr*&, swift::DeclContext*) + 112
24 swift-ide-test  0x000000000091d989 swift::TypeChecker::typeCheckPatternBinding(swift::PatternBindingDecl*, unsigned int) + 265
31 swift-ide-test  0x0000000000936237 swift::TypeChecker::typeCheckDecl(swift::Decl*, bool) + 151
34 swift-ide-test  0x000000000097f68a swift::TypeChecker::typeCheckClosureBody(swift::ClosureExpr*) + 218
35 swift-ide-test  0x00000000009b77ec swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::Expr*, swift::Type, bool, bool, bool) + 812
36 swift-ide-test  0x000000000091c73b swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*) + 683
38 swift-ide-test  0x000000000097f7d6 swift::TypeChecker::typeCheckTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 134
39 swift-ide-test  0x00000000009039cd swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int) + 1405
40 swift-ide-test  0x0000000000773be2 swift::CompilerInstance::performSema() + 2946
41 swift-ide-test  0x000000000071c7c3 main + 35027
Stack dump:
0.	Program arguments: swift-ide-test -code-completion -code-completion-token=A -source-filename=<INPUT-FILE>
1.	While type-checking expression at [<INPUT-FILE>:2:1 - line:2:39] RangeText="{class d<T where g:e{class B{var b=B p"
2.	While type-checking 'd' at <INPUT-FILE>:2:2
3.	While type-checking expression at [<INPUT-FILE>:2:36 - line:2:36] RangeText="B"
4.	While resolving type B at [<INPUT-FILE>:2:36 - line:2:36] RangeText="B"
```

Mark as fixed.

Move to fixed directory.
2015-12-16 18:22:16 +01:00
Ben Langmuir
50cc79c7f2 Fix crash code-completing after 1 + [0]
A literal in a sub-expression of the right-most expression in a sequence
could accidentally still have an error-type when going through CSApply.

rdar://problem/23488528
2015-11-16 11:35:13 -08:00