Commit Graph

854 Commits

Author SHA1 Message Date
Slava Pestov
82e9015335 AST: Use the new getMemberSubstitutions() in a few places 2016-12-17 16:28:18 -08:00
Slava Pestov
3989aea9ae AST: Clean up getMemberSubstitutions() and friends
Rename the old getMemberSubstitutions() to getContextSubstitutions()
and add a new getMemberSubstitutions() that takes a ValueDecl, rather
than the member's DeclContext.

This new method forwards generic parameters if the member is a generic
function.
2016-12-17 16:28:18 -08:00
practicalswift
38be6125e5 [gardening] C++ gardening: Terminate namespaces, fix argument names, ...
Changes:
* Terminate all namespaces with the correct closing comment.
* Make sure argument names in comments match the corresponding parameter name.
* Remove redundant get() calls on smart pointers.
* Prefer using "override" or "final" instead of "virtual". Remove "virtual" where appropriate.
2016-12-17 00:32:42 +01:00
Slava Pestov
2c6b9f71b6 AST: Change TypeAliasDecls to store an interface type as their underlying type
- TypeAliasDecl::getAliasType() is gone. Now, getDeclaredInterfaceType()
  always returns the NameAliasType.

- NameAliasTypes now always desugar to the underlying type as an
  interface type.

- The NameAliasType of a generic type alias no longer desugars to an
  UnboundGenericType; call TypeAliasDecl::getUnboundGenericType() if you
  want that.

- The "lazy mapTypeOutOfContext()" hack for deserialized TypeAliasDecls
  is gone.

- The process of constructing a synthesized TypeAliasDecl is much simpler
  now; instead of calling computeType(), setInterfaceType() and then
  setting the recursive properties in the right order, just call
  setUnderlyingType(), passing it either an interface type or a
  contextual type.

  In particular, many places weren't setting the recursive properties,
  such as the ClangImporter and deserialization. This meant that queries
  such as hasArchetype() or hasTypeParameter() would return incorrect
  results on NameAliasTypes, which caused various subtle problems.

- Finally, add some more tests for generic typealiases, most of which
  fail because they're still pretty broken.
2016-12-15 22:46:15 -08:00
Slava Pestov
a384b2a677 Don't call VarDecl::getType() on deserialized VarDecls 2016-12-15 22:46:15 -08:00
Hugh Bellamy
d8fbaa01eb Fix errors and warnings building swift/IDE on Windows using MSVC 2016-12-09 10:08:00 +00:00
Doug Gregor
38671e2771 [AST] Hide DeclContext::getAsGenericTypeOrGenericTypeExtensionContext().
This method gets the GenericTypeDecl for a typealias, nominal type, or
extension thereof. While the result is typed as GenericTypeDecl, it's
not always generic, so rename it accordingly.

An audit of the callers illustrated that they should be using
different entrypoints anyway, so fix all of the callers and make this
function private.
2016-12-05 22:42:03 -08:00
Slava Pestov
9caaad442b AST: Don't call hasType()/getType()/setType() on TypeDecls 2016-12-01 13:00:19 -08:00
Slava Pestov
2d83a79c2c AST: Remove TypeDecl::getDeclaredType()
A pointless use of polymorphism -- the result values are not
interchangeable in any practical sense:

- For GenericTypeParamDecls, this returned getDeclaredInterfaceType(),
  which is an interface type.

- For AssociatedTypeDecls, this returned the sugared AssociatedTypeType,
  which desugars to an archetype.

- For TypeAliasDecls, this returned TypeAliasDecl::getAliasType(),
  which desugars to a type containing archetypes.

- For NominalTypeDecls, this returned NominalTypeDecl::getDeclaredType(),
  which is the unbound generic type, a special case used for inferring
  generic arguments when they're not written in source.
2016-12-01 13:00:18 -08:00
Slava Pestov
8bdbe774e0 AST: Don't call hasType()/getType()/setType() on SubscriptDecls 2016-12-01 13:00:17 -08:00
Slava Pestov
7b59e75d34 IDE: hasType() => hasInterfaceType() 2016-11-29 03:05:31 -07:00
Slava Pestov
6c63514bb4 IDE: getType() => getInterfaceType() 2016-11-29 03:05:26 -07:00
Slava Pestov
69e7cca64f AST: Remove ConstructorDecl::getResultType() 2016-11-29 03:05:22 -07:00
Graydon Hoare
7c1dc18b64 Revert "Give all declarations an explicit interface type" 2016-11-24 09:55:27 -08:00
Slava Pestov
6db43138fa AST: Remove ConstructorDecl::getResultType() 2016-11-24 02:35:30 -05:00
practicalswift
2fe4254cb7 Merge pull request #5878 from practicalswift/https-swift-org
[gardening] Use the correct base URL (https://swift.org) in references to the Swift website
2016-11-22 09:17:57 +01:00
swift-ci
597b6b4254 Merge pull request #5807 from benlangmuir/cc-invalid-op 2016-11-20 11:36:11 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Slava Pestov
2e901cb4f9 AST: Clean up PrintOptions a bit 2016-11-19 22:53:53 -08:00
David Farler
f450f0ccdf Revert "Preserve whitespace and comments during lexing as Trivia"
This reverts commit d6e2b58382.
2016-11-18 13:23:31 -08:00
David Farler
d6e2b58382 Preserve whitespace and comments during lexing as Trivia
Store leading a trailing "trivia" around a token, such as whitespace,
comments, doc comments, and escaping backticks. These are syntactically
important for preserving formatting when printing ASTs but don't
semantically affect the program.

Tokens take all trailing trivia up to, but not including, the next
newline. This is important to maintain checks that statements without
semicolon separators start on a new line, among other things.

Trivia are now data attached to the ends of tokens, not tokens
themselves.

Create a new Syntax sublibrary for upcoming immutable, persistent,
thread-safe ASTs, which will contain only the syntactic information
about source structure, as well as for generating new source code, and
structural editing. Proactively move swift::Token into there.

Since this patch is getting a bit large, a token fuzzer which checks
for round-trip equivlence with the workflow:

fuzzer => token stream => file1
  => Lexer => token stream => file 2 => diff(file1, file2)

Will arrive in a subsequent commit.

This patch does not change the grammar.
2016-11-15 16:11:57 -08:00
Ben Langmuir
5c801752fd [code-completion] Fix a crash on invalid operator decls
We cache failures in the operator maps, so handle null pointers when
walking them for code-completion.

rdar://problem/29275272
2016-11-15 14:35:21 -08:00
Ben Langmuir
32f131e9ab [code-completion] Handle func-reference syntax for optional expected type
The underlying type-check was correct, but I forgot to consider it in
the outer code, and embarassingly never tested this case.

rdar://problem/28435922
2016-10-28 13:41:45 -07:00
Doug Gregor
6ce4be96f1 Merge pull request #5261 from DougGregor/type-checker-extra-constraints
[Type checker] Eliminate generation of useless constraints NFC.
2016-10-13 13:40:09 -07:00
Doug Gregor
735ef839e2 [Code completion] Suppress vacuous infix operator completions.
With the previous type-checker change, we end up with some vacuous
infix operator completions, where the right-hand side and result type
are *both* type variables. Suppress these; they aren't useful to the
developer.
2016-10-13 10:16:20 -07:00
Bob Wilson
dfa207b7ae Use std::function to fix unsafe use of llvm::function_ref.
This was exposed by building with a recent version of clang. Without this
change, the following tests were failing:

    Swift(macosx-x86_64) :: IDE/complete_assignment.swift
    Swift(macosx-x86_64) :: IDE/complete_enum_elements.swift
    Swift(macosx-x86_64) :: IDE/complete_stmt_controlling_expr.swift
    Swift(macosx-x86_64) :: SourceKit/CodeComplete/complete_structure.swift

I did not narrow it down to which uses of DeclFilter were problematic.
The global variables certainly do not seem like a good place to use a
function_ref. rdar://problem/28699882
2016-10-12 16:44:11 -07:00
Ben Langmuir
114d836737 Merge pull request #5183 from benlangmuir/cc-inst-curry-ref
[code-completion] Fix type-relation check on implicitly curried instance methods
2016-10-07 15:46:32 -07:00
Ben Langmuir
a6934d1e6d [code-completion] Fix type-relation check on implicitly curried instance methods
We strip the first input type on instance methods like,
struct S { func foo(T) -> U } // (S)->(T)->U

but we should not do that when it's actually a curried instance method,
such as S.foo.
2016-10-07 13:55:13 -07:00
Doug Gregor
50341da32b Use "TypeBase::hasError()" rather than "is<ErrorType>()" where needed.
In most places where we were checking "is<ErrorType>()", we now mean
"any error occurred". The few exceptions are in associated type
inference, code completion, and expression diagnostics, where we might
still work with partial errors.
2016-10-07 10:58:23 -07:00
Doug Gregor
66e20116f2 Extend ErrorType with an "original type" and use it to clean up substitution.
Type::subst()'s "IgnoreMissing" option was fairly unprincipled, dropping
unsubstituted types into the resulting AST without any indication
whatsoever that anything went wrong. Replace this notion with a new
form of ErrorType that explicitly tracks which substituted type caused
the problem. It's still an ErrorType, but it prints like the
substituted type (which is important for code completion) and allows
us to step back to the substituted type if needed (which is used by
associated type inference). Then, allow Type::subst(), when the new
UseErrorTypes flag is passed, to form partially-substituted types that
contain errors, which both code completion and associated type
inference relied on.

Over time, I hope we can use error-types-with-original-types more
often to eliminate "<<error type>>" from diagnostics and teach
Type::subst() never to return a "null" type. Clients can check
"hasError()" to deal with failure cases rather than checking null.
2016-10-06 16:40:28 -07:00
Ben Langmuir
d2e2d5fe84 [code-completion] Complete as function reference when the type matches
If we're completing in a context that expects a function type, try to
match methods/functions as function references before trying them as
calls.  This means that

func take(_: (Int)->()) {}
func foo(a: Int) {}
take(#^A^#)  // completes foo(a:)  instead of foo(a: {#value#})

Note: doesn't yet work with generic types.

rdar://problem/28435922
2016-10-05 14:25:38 -07:00
Slava Pestov
cfe9e6a3de IDE: Use GenericSignatures and interface types (mostly)
There was a ton of complicated logic here to work around
two problems:

- Same-type constraints were not represented properly in
  RequirementReprs, requiring us to store them in strong form
  and parse them out when printing type interfaces.

- The TypeBase::getAllGenericArgs() method did not do the
  right thing for members of protocols and protocol extensions,
  and so instead of simple calls to Type::subst(), we had
  an elaborate 'ArchetypeTransformer' abstraction repeated
  in two places.

Rewrite this code to use GenericSignatures and
GenericFunctionType instead of old-school GenericParamLists
and PolymorphicFunctionType.

This changes the code completion and AST printer output
slightly. A few of the changes are actually fixes for cases
where the old code didn't handle substitutions properly.
A few others are subjective, for example a generic parameter
list of the form <T : Proto> now prints as <T where T : Proto>.

We can add heuristics to make the output whatever we want
here; the important thing is that now we're using modern
abstractions.
2016-10-02 23:49:15 -04:00
Slava Pestov
0b8beea69b IDE: Add CodeCompleteInitsInPostfixExpr to completion cache key
This fixes a source of non-determinism. The IDE/complete_constructor
test would sometimes fail depending on the order in which prior tests
ran, since those prior tests might populate the code completion cache.
2016-10-02 23:49:14 -04:00
Slava Pestov
a9c68c0736 AST: Remove archetype from AbstractTypeParamDecl
There's a bit of a hack to deal with generic typealiases, but
overall this makes things more logical.

This is the last big refactoring before we can allow constrained
extensions to make generic parameters concrete. All that remains
is a small set of changes to SIL type lowering, and retooling
some diagnostics in Sema.
2016-09-22 19:48:30 -07:00
practicalswift
ad02d73ee6 Remove unused method isOptionSetDecl(...).
Last usage removed in 31f583f164
2016-09-16 18:37:42 +02:00
Xi Ge
f37f189fcd Refactor a long macro definition to a more readable function. NFC (#4734) 2016-09-12 23:56:09 -07:00
Ben Langmuir
c8cf118b12 [codecompletion] Complete initializers after 'self'
... in other initializers.  We don't restrict it to convenience inits
because you might have forgotten the convenience keyword and the
compiler will give you a fixit.

rdar://problem/20913297
2016-09-12 13:40:47 -07:00
Rintaro Ishizaki
b827298892 [CodeCompletion] Modifier related improvements in CompletionOverrideLookup
* If "required" or "convenience" is specified, emit only initializers
* If "final" or "open" is specified, don't emit initializers or typealias
* If "typealias" is specified, emit only associated type implementation
* Emit "override" or "required" modifier for initializers
* Emit access modifier for initializers
* Emit designated initializers even if "override" is specified
* Don't emit inheritance clause for associated type implentation
2016-08-27 03:48:51 +09:00
Ben Langmuir
4136f919ce Merge pull request #4348 from rintaro/cc-override-access
[CodeCompletion] Never emit 'private' for conformance or override declarations
2016-08-25 08:29:16 -07:00
Ben Langmuir
d8fa0b00ba [codecomplete] Handle null type in AbstractClosureExpr context
rdar://problem/27643235
2016-08-23 14:58:44 -07:00
Ben Langmuir
2855634999 [codecomplete] Check for ErrorType before asking for CD->getResultType()
Fixes a crash where we try to cast ErrorType to a function type to get
the result.

rdar://problem/27763826
2016-08-23 13:14:56 -07:00
Rintaro Ishizaki
526139986a [CodeCompletion] Emit access modifier for override or conformance member only if 'public'
At least, because of SE-0025, we cannnot emit 'private' for them.

Consider:
  protocol P {
    func meth()
  }
  private class C : P {
    #^TOKEN^#
  }
2016-08-20 05:12:01 +09:00
Rintaro Ishizaki
81c1edee5d [CodeCompletion] Suffix ": " instead of "=" when completing attribute argument names
In addtion, renamed DeclAttrParamEqual to DeclAttrParamColon.
2016-08-17 02:33:04 +09:00
Ben Langmuir
89fd31d78f [codecompletion] Add @escaping to override completions
Flush out the ASTPrinter's ability to exclude and include specific
attributes to cover TypeAttrKinds and have code-completion use this to
print @escaping in override completions.  Incidentally fix a case where
we weren't forwarding important options after type transformation, which
prevented printing @escaping in transformed parameter types.

rdar://problem/27772722
2016-08-11 16:43:32 -07:00
Argyrios Kyrtzidis
8b1dde645a [IDE] Fix code-completion fallout after changes for SE-0111.
rdar://27642873
2016-08-09 18:07:58 -07:00
Ted Kremenek
c9e57af9c0 Merge pull request #4174 from nkcsgexi/type-translate
[CodeCompletion] Refactor archetype transform to avoid using recursion.
2016-08-09 17:41:14 -07:00
Xi Ge
2ae236808c [CodeCompletion] Refactor archetype transform to avoid using recursion. rdar://27615558
We have a radar (rdar://27615558) complaining the exiting recursive calls in type transform
of code completion hangs. This patch refactor the existing code to avoid using
recursion. From existing tests' perspective, this is NFC. I am not able to contrive the
test case that leads to the hang, neither is given by the radar.
2016-08-09 16:33:17 -07:00
Slava Pestov
173658a5d8 SIL: Round-trip DynamicSelfType properly
When DynamicSelfType occurs outside of a class body (for example,
inside of a SIL function), it is not enough to simply utter 'Self',
because then we lose the underlying type.

Instead, print it out as '@dynamic_self Foo', where 'Foo' is the
underlying class type or archetype, and add parser support for
the same.

Fixes <rdar://problem/27735857>.
2016-08-09 14:18:03 -07:00
practicalswift
31f583f164 Remove unused method isOptionSet(...).
Last usage removed in 468e6d9c3d
2016-08-06 13:05:14 +02:00
Ben Langmuir
468e6d9c3d [CodeCompletion] Complete unresolved members that are not enums or OptionSets
Replace the enum and OptionSet-specific code with static member lookup
that checks the type against the contextual type.  This lets us complete
static variables, static functions, and initializers.  In particular,
this fixes completion of NS_EXTENSIBLE_STRING_ENUM types from
Objective-C.

rdar://problem/26628652
2016-07-29 14:51:40 -07:00