Commit Graph

345 Commits

Author SHA1 Message Date
swift-ci
391e10e6fe Merge pull request #3561 from practicalswift/sourcekit-071-swift-printoptions-setarchetypetransform 2016-07-17 18:09:18 -07:00
practicalswift
4e4fff4373 [SourceKit] Add test case for crash triggered in swift::PrintOptions::setArchetypeTransform(swift::Type, swift::DeclContext*)
Stack trace:

```
found code completion token A at offset 154
swift-ide-test: /path/to/swift/lib/AST/ASTPrinter.cpp:68: std::unique_ptr<llvm::DenseMap<StringRef, Type> > swift::collectNameTypeMap(swift::Type): Assertion `ParamDecls.size() == Args.size()' failed.
9  swift-ide-test  0x0000000000b7da00 swift::PrintOptions::setArchetypeTransform(swift::Type, swift::DeclContext*) + 144
16 swift-ide-test  0x0000000000bb3694 swift::Decl::walk(swift::ASTWalker&) + 20
17 swift-ide-test  0x0000000000c4b40e swift::SourceFile::walk(swift::ASTWalker&) + 174
18 swift-ide-test  0x0000000000c4a54f swift::ModuleDecl::walk(swift::ASTWalker&) + 79
19 swift-ide-test  0x0000000000c2113b swift::DeclContext::walkContext(swift::ASTWalker&) + 187
20 swift-ide-test  0x00000000008ec438 swift::performDelayedParsing(swift::DeclContext*, swift::PersistentParserState&, swift::CodeCompletionCallbacksFactory*) + 136
21 swift-ide-test  0x00000000007a668d swift::CompilerInstance::performSema() + 3597
22 swift-ide-test  0x0000000000749c80 main + 34176
Stack dump:
0.	Program arguments: swift-ide-test -code-completion -code-completion-token=A -source-filename=<INPUT-FILE>
1.	While walking into decl getter for b at <INPUT-FILE>:3:6
```
2016-07-17 23:26:13 +02:00
practicalswift
581103d766 [SourceKit] Add test case for crash triggered in swift::ArchetypeBuilder::mapTypeIntoContext(swift::ModuleDecl*, swift::GenericParamList*, swift::Type, swift::LazyResolver*)
Stack trace:

```
found code completion token A at offset 151
4  swift-ide-test  0x0000000000b3c793 swift::ArchetypeBuilder::mapTypeIntoContext(swift::ModuleDecl*, swift::GenericParamList*, swift::Type, swift::LazyResolver*) + 163
5  swift-ide-test  0x0000000000a19f1b swift::constraints::ConstraintSystem::openGeneric(swift::DeclContext*, swift::DeclContext*, llvm::ArrayRef<swift::GenericTypeParamType*>, llvm::ArrayRef<swift::Requirement>, bool, swift::constraints::ConstraintLocatorBuilder, llvm::DenseMap<swift::CanType, swift::TypeVariableType*, llvm::DenseMapInfo<swift::CanType>, llvm::detail::DenseMapPair<swift::CanType, swift::TypeVariableType*> >&) + 1051
7  swift-ide-test  0x0000000000c71a83 swift::Type::transform(llvm::function_ref<swift::Type (swift::Type)>) const + 35
8  swift-ide-test  0x0000000000a185fe swift::constraints::ConstraintSystem::openType(swift::Type, swift::constraints::ConstraintLocatorBuilder, llvm::DenseMap<swift::CanType, swift::TypeVariableType*, llvm::DenseMapInfo<swift::CanType>, llvm::detail::DenseMapPair<swift::CanType, swift::TypeVariableType*> >&) + 78
11 swift-ide-test  0x0000000000bb32e5 swift::Expr::walk(swift::ASTWalker&) + 69
12 swift-ide-test  0x0000000000930758 swift::constraints::ConstraintSystem::generateConstraints(swift::Expr*) + 200
13 swift-ide-test  0x000000000096b353 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>) + 371
14 swift-ide-test  0x0000000000971cf2 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*) + 610
17 swift-ide-test  0x00000000009ebae4 swift::TypeChecker::typeCheckClosureBody(swift::ClosureExpr*) + 244
18 swift-ide-test  0x0000000000a229ac swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::Expr*, swift::Type, bool, bool, bool) + 876
19 swift-ide-test  0x0000000000971d91 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*) + 769
22 swift-ide-test  0x00000000009ea75a swift::TypeChecker::typeCheckFunctionBodyUntil(swift::FuncDecl*, swift::SourceLoc) + 346
23 swift-ide-test  0x00000000009ea5be swift::TypeChecker::typeCheckAbstractFunctionBodyUntil(swift::AbstractFunctionDecl*, swift::SourceLoc) + 46
24 swift-ide-test  0x00000000009a89af swift::typeCheckAbstractFunctionBodyUntil(swift::AbstractFunctionDecl*, swift::SourceLoc) + 655
26 swift-ide-test  0x00000000008ec4e1 swift::performDelayedParsing(swift::DeclContext*, swift::PersistentParserState&, swift::CodeCompletionCallbacksFactory*) + 305
27 swift-ide-test  0x00000000007a668d swift::CompilerInstance::performSema() + 3597
28 swift-ide-test  0x0000000000749c80 main + 34176
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>:3:23 - line:4:1] RangeText="{B
"
2.	While type-checking expression at [<INPUT-FILE>:3:24 - line:3:24] RangeText="B"
```
2016-07-17 12:03:10 +02:00
practicalswift
6b8d883948 [SourceKit] Add test case for crash triggered in swift::TypeChecker::typeCheckParameterList(swift::ParameterList*, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver*)
Stack trace:

```
found code completion token A at offset 137
5  swift-ide-test  0x00000000009c30f5 swift::TypeChecker::typeCheckParameterList(swift::ParameterList*, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver*) + 117
8  swift-ide-test  0x0000000000982d96 swift::TypeChecker::typeCheckDecl(swift::Decl*, bool) + 150
9  swift-ide-test  0x00000000009a6142 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int) + 1026
10 swift-ide-test  0x00000000007a64d9 swift::CompilerInstance::performSema() + 3289
11 swift-ide-test  0x0000000000749c4a main + 34106
Stack dump:
0.	Program arguments: swift-ide-test -code-completion -code-completion-token=A -source-filename=<INPUT-FILE>
1.	While type-checking 'b' at <INPUT-FILE>:3:1
```
2016-07-16 21:09:27 +02:00
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
Ted Kremenek
82c0a779e7 XFAIL validation-test/IDE/crashers/011-swift-lookupvisibledecls.swift (SR-1583) 2016-05-21 11:31:47 -07:00
Mark Lacey
eb1c4dc240 Fix two validation tests that require asserts. 2016-04-16 16:10:51 -07:00
Jordan Rose
bc83940301 Make pointer nullability explicit using Optional.
Implements SE-0055: https://github.com/apple/swift-evolution/blob/master/proposals/0055-optional-unsafe-pointers.md

- Add NULL as an extra inhabitant of Builtin.RawPointer (currently
  hardcoded to 0 rather than being target-dependent).
- Import non-object pointers as Optional/IUO when nullable/null_unspecified
  (like everything else).
- Change the type checker's *-to-pointer conversions to handle a layer of
  optional.
- Use 'AutoreleasingUnsafeMutablePointer<NSError?>?' as the type of error
  parameters exported to Objective-C.
- Drop NilLiteralConvertible conformance for all pointer types.
- Update the standard library and then all the tests.

I've decided to leave this commit only updating existing tests; any new
tests will come in the following commits. (That may mean some additional
implementation work to follow.)

The other major piece that's missing here is migration. I'm hoping we get
a lot of that with Swift 1.1's work for optional object references, but
I still need to investigate.
2016-04-11 20:06:38 -07:00
Joe Groff
37dce05803 This validation-test no longer crashes. 2016-03-28 09:50:30 -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
Michael Ilseman
8cb669dd56 Disable crasher test that ASAN somehow fixes.
The disabled crasher test does not crash with ASAN enabled, which is
particularly odd. Disable the test to unblock builders and testers
while diagnosing.
2016-03-18 16:54:00 -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
gregomni
78216b2990 Change all remaining tests that use typealias in a protocol to use associatedtype. 2016-03-09 18:08:52 -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
Michael Gottesman
4691d741a3 Disable some SourceKit/IDE tests that fail with ASAN until after the stable merge. rdar://24540771. 2016-02-06 18:24:51 -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