Commit Graph

3502 Commits

Author SHA1 Message Date
Argyrios Kyrtzidis
c5e19b4afd [AST] Hide operator '~>' as an internal symbol.
Swift SVN r18628
2014-05-25 20:42:23 +00:00
Argyrios Kyrtzidis
adb17b5aca [AST] If a symbol has a type of a typealias that is not with leading underscore, accept it as public one.
Note that if the typealias type is an internal one it will show up undeclared in the interface.
We currently allow this to avoid unintentionally hiding a public API.

Swift SVN r18627
2014-05-25 20:06:02 +00:00
Argyrios Kyrtzidis
95bd9e1d28 [AST/IDE] Centralize the logic to determine if a symbols is a 'private' stdlib one and hide them more extensively.
-Hide vars that have a private type.
-Hide functions that have a parameter with private type or a parameter name with leading underscore.
-Minor change in StringUTF16.swift to avoid printing "func generate() -> IndexingGenerator<_StringCore>".

rdar://17027294

Swift SVN r18623
2014-05-25 03:49:02 +00:00
Joe Pamer
c81e822ef5 Add some logic to the type checking process to prevent stack overflows while type checking certain kinds of self-referential declarations. This addresses rdar://problem/1641865, rdar://problem/16994520 and host of other radars that have been filed over the past several months.
Post-WWDC, we need to update the type checking process to make these kinds of infinite loops impossible without checking special flags.

Swift SVN r18598
2014-05-23 18:19:29 +00:00
Chris Lattner
0d8c93b186 fix <rdar://problem/16889110> capture lists in lazy member properties cannot use self
When reparenting a closure in an @lazy initializer into the computed getter, make sure
to reparent any var/pbd decls in the capture list into the same context.



Swift SVN r18365
2014-05-18 22:40:56 +00:00
Chris Lattner
cf55f7edd5 fix:
<rdar://problem/16264989> property not mutable in closure inside of its willSet
and:
<rdar://problem/16826319> willSet immutability behavior is incorrect

by changing how we handle immutability of an observing property within its willSet.
Instead of trying to model it as an rvalue, just model it as an lvalue (which it is)
and diagnose the problem with a warning in MiscDiagnostics.



Swift SVN r18184
2014-05-16 06:32:33 +00:00
Argyrios Kyrtzidis
2fe6987c5a [IDE] Annotate 'convenience' in an initializer as keyword.
rdar://16855149

Swift SVN r18065
2014-05-14 05:51:09 +00:00
Argyrios Kyrtzidis
2d1f1b1386 Fix ConstructorDecl::getSourceRange() to return the signature range if there is no body, not the range of its containing type declaration.
Swift SVN r18046
2014-05-14 00:41:12 +00:00
Chris Lattner
46a2939e5d try to unbreak the bot.
Swift SVN r17873
2014-05-11 14:55:42 +00:00
Doug Gregor
b6e915e7e5 Introduce "with" into method names that have keyword arguments as their first argument.
Only do this when neither the first word of the keyword argument nor
the last word of the base method name is a preposition. This is the
last semantic part of <rdar://problem/16795899>.

Swift SVN r17782
2014-05-09 16:26:01 +00:00
Doug Gregor
90726dfdb3 When the first argument of a method name is API, add it to the first selector piece of the @objc selector.
Swift SVN r17780
2014-05-09 16:25:59 +00:00
Jordan Rose
de4c0ee8a8 Simplify a check to see if a particular struct is Swift.String.
ASTContext knows how to find this type now.

No functionality change.

Swift SVN r17572
2014-05-06 22:50:30 +00:00
Joe Groff
05c80a8fe9 AST: Avoid instantiating all members when implicit destructors are inserted into classes.
We were accidentally forcing all members of a class to be instantiated in two places:

- by trying to look up an existing destructor decl in the class, and
- by adding the implicit destructor to the class, because addMember needlessly called loadAllMembers.

Fix the former problem by adding a 'has destructor' bit to ClassDecl so we can track whether the implicit destructor needs to be added without querying its members. Fix the latter by making IterableDeclContext::addMember not call loadAllMembers, and making loadAllMembers not barf when it sees existing members in the context.

Together with Jordan and JoeP's changes, this makes many interpreter tests now compile 3-20x faster.

Swift SVN r17562
2014-05-06 20:30:08 +00:00
Dave Abrahams
5fe453ca3e Silence unused variable warning
Swift SVN r17479
2014-05-05 19:24:15 +00:00
Doug Gregor
3c71c4ee21 Compute useful effective full names for property accessors, too.
willSet/didSet and the synthesized getter they imply had keyword
arguments when they shouldn't have. Fix this.

Swift SVN r17459
2014-05-05 17:36:45 +00:00
Argyrios Kyrtzidis
dfa772de8b [AST] Set the source range of ParamDecl as the argument+parameter range and keep track of its parent pattern.
Swift SVN r17441
2014-05-05 15:14:31 +00:00
John McCall
2b969c41a2 Track whether a class is "foreign" in the AST.
This basically just means "it's a CF class" for now,
but you could imagine applying this to all sorts of
class-like types from peer runtimes that we can't
support all possible language features for.

There are quite a few language features that require
fairly deep object-model integration to implement,
like subclassing and adding polymorphic methods.
Some of those features, like final classes, are useful
to generally support as attributes, but most of
them aren't.  At least in the short term, it makes
sense to have a big hammer we can hit things with.

Swift SVN r17428
2014-05-05 06:45:40 +00:00
Doug Gregor
eb7a9144a8 Bring keyword arguments to subscripts.
Subscript declarations were still encoding the names of index
variables in the subscript type, which unintentionally made them
keyword arguments. Bring subscript declarations into the modern day,
using compound names to encode the subscript argument names, which
provides consistency for the keyword-argument world
<rdar://problem/14462349>. Note that arguments in subscripts default
to not being keyword arguments, which seems like the right default.

We now get keyword arguments for subscripts, so one can overload
subscripts on the names of the indices, and distinguish at the call
site. Under -strict-keyword-arguments, we require strictness here as well.

The IRGen/IDE/SILGen test updates are because the mangling of common
subscripts changed from accidentally having keyword arguments to not
having keyword arguments.

Swift SVN r17393
2014-05-04 19:31:09 +00:00
Doug Gregor
4996efbfba Implement support for making "with" implicit on the first argument of an initializer.
When importing an Objective-C init method or factory method into an
initializer, if the first camelCase word of the first argument name
starts with "with", drop the "with". This means that

  -initWithRed:green:blue:alpha:

will get imported into Swift as

  init(red:green:blue:alpha:)

as will

  +colorWithRed:green:blue:alpha:

This is <rdar://problem/16795899>, hidden behind the
-implicit-objc-with flag.

Swift SVN r17271
2014-05-02 21:13:04 +00:00
Doug Gregor
8324dc92e1 Introduce and use camel_case::appendSentenceCase().
Swift SVN r17260
2014-05-02 17:43:00 +00:00
Ted Kremenek
4e70269c53 More renaming 'unchecked optional' to 'implicitly unwrapped optional'.
Swift SVN r17236
2014-05-02 06:22:01 +00:00
Ted Kremenek
050fd53af7 Rename UncheckedOptional to ImplicitlyUnwrappedOptional.
Swift SVN r17232
2014-05-02 06:13:57 +00:00
Doug Gregor
72e32c93af Make argument names default to keyword arguments in the cases where Objective-C has names.
Introduce a model where an argument name is a keyword argument if: 

  - It is an argument to an initializer, or
  - It is an argument to a method after the first argument, or
  - It is preceded by a back-tick (`), or
  - Both a keyword argument name and an internal parameter name are
    specified. 

Provide diagnostics Fix-Its to clean up cases where the user is
probably confused, i.e.,

  - "_ x: Int" -> "x: Int" where "x" would not have been a keyword
  argument anyway
  - "x x: Int" -> "`x: Int"

This covers the compiler side of <rdar://problem/16741975> and
<rdar://problem/16742001>.

Update the AST printer to print in this form, never printing just 
a type for a parameter name because we're also going to adopt
<rdar://problem/16737312> and it was easier to move the tests once
rather than twice.

Standard library and test updates coming separately.




Swift SVN r17056
2014-04-30 00:04:04 +00:00
Doug Gregor
85df2fa0a1 Restrict overloading of properties with nullary functions.
Ties down the semantics a little bit more for sanity's sake; thanks, Chris.


Swift SVN r17012
2014-04-29 04:38:41 +00:00
Doug Gregor
153b8ac1a6 Allow a property to overload a function.
It's fairly common in Cocoa applications to do something like:

  var tableView: NSTableView
  func tableView(sender: NSTableView, shouldDoSomething: Int) { }

where the base name of a method is the same as the name of a
property. We lost this ability when I turned on redeclaration
checking, so bring it back <rdar://problem/16746894>.

Swift SVN r16996
2014-04-28 21:36:56 +00:00
Dmitri Hrybenko
14364aa261 Make TypeDecl::getProtocols() actually force delayed members when requested
Fixes
<rdar://problem/16438738> Ensure that RawOptionSet conformance is printed for
imported NS_OPTIONS

and probably other latent bugs.


Swift SVN r16971
2014-04-28 10:19:46 +00:00
Chris Lattner
0c390777ba Implement <rdar://problem/16204675> Need #elseif
This restructures IfConfigDecl/Stmt to be a list of clauses controlled
by a condition.  This makes it straight-forward to drop in #elseif support.

While I'm in here, this patch moves checking for extraneous stuff at the
end of the #if line from the lexer to the parser.  This means that you can
now put a comment on the same line as a #if/#else/#elseif/#endif.



Swift SVN r16912
2014-04-27 04:51:36 +00:00
Chris Lattner
371a9316f4 - Introduce a new 'nonmutating' context sensitive keyword, and use it instead of @!mutating.
- Change the parser to unconditionally reject @mutating and @!mutating with a fixit and 
  specific diagnostic to rewrite them into the [non]mutating keyword.
- Update tests.

This resolves <rdar://problem/16735619> introduce nonmutating CS keyword and remove the attribute form of mutating all together



Swift SVN r16892
2014-04-26 21:00:06 +00:00
Jordan Rose
29566347dc [ClangImporter] Deal with redeclarations of properties as readwrite.
(and a similar issue for subscripts)

In Cocoa, a property can be declared readonly in the public interface of a
class and readwrite in a class extension. Similarly, a protocol can require
a readable property, but a category then declares the property as readwrite.
Swift doesn't like having two of the same declaration, and which one ended
up being used was order-dependent.

This change doesn't really fix the problem, but it does paper over it.
Now, when the importer sees a redeclaration of a readonly property as
readwrite, it forcibly updates the existing property with the new setter.
This isn't entirely correct; the redeclaration doesn't show up in its category,
and this doesn't respect visibility (i.e. the change to readwrite occurs in
a separate module that isn't visible in all source files). (But extensions
don't respect visibility in any other way, either, even in pure Swift code.)

At its heart, this is just a mismatch between Objective-C allowing
redeclarations that add capabilities and Swift not having redeclarations
at all. At some point, it may make more sense to model this as an overload,
or to mark the original declaration invalid, but for now this seems to be
the most contained change we can get that fixes the problem.

<rdar://problem/16692921>

Swift SVN r16832
2014-04-25 19:38:50 +00:00
Doug Gregor
37950d5f7f Don't allow overloading on @unchecked vs. strict optional return type.
Swift SVN r16706
2014-04-23 16:23:45 +00:00
Doug Gregor
fb8c3ce3d7 Signature computation: deal with @noreturn, optionals.
Swift SVN r16704
2014-04-23 15:10:25 +00:00
Doug Gregor
95f3d204d0 Strip default arguments from the signature of a function.
Fixes  <rdar://problem/13338746>.


Swift SVN r16701
2014-04-23 13:38:44 +00:00
Doug Gregor
9ccaf63998 Implement sane redeclaration checking.
Perform redeclaration checking of global and type-member declarations
at the time of declaration, using a notion of the signature of a
declaration to determine when one declaration is a redeclaration of
another. See ValueDecl::getOverloadSignature() and 
conflicting(OverloadSignature, OverloadSignature) for the specific
rules we implement. In a nutshell:

  - For functions, the signature includes:
    + The full name (which includes argument names)
    + The interface type
    + Whether the function is a class/static or instance method
    + For an operator, whether it is prefix or postfix
  - For a subscript, the signature is the interface type
  - For everything else, the signature is just the name

This tightens the rules in a number of ways, which is reflected in the
test case churn:

  - We now properly perform redeclaration checking for generics
  - We now propertly handle API argument names for functions
  - We now ban overloading between two variables of the same name but
    different type 
  - We now ban overloading between a variable/property and a function
  - We now ban overloading for initializers

The two test cases of actual interest are:

  test/decl/overload.swift: A bunch of new test cases for our checking

  test/Constraints/members.swift: I commented out a useful test for
  now, because it relies on overloading between a property and a
  function. We can reconsistute this test with a couple of modules.

This commit fixes at least a half dozen radars under the umbrella
<rdar://problem/11212777>. I still need to check them individually to
close them out.



Swift SVN r16691
2014-04-23 07:03:38 +00:00
Chris Lattner
bbb768f3ac adjust to use LLVM style instead of lldb style.
Swift SVN r16686
2014-04-23 03:55:55 +00:00
Argyrios Kyrtzidis
2db90e9105 [IDE] For the syntax node of functions, set the name range to the range of the function signature.
Swift SVN r16680
2014-04-23 00:24:11 +00:00
Argyrios Kyrtzidis
6f357713b6 [Parser] Fix assertion hits when trying to print an invalid function.
Swift SVN r16674
2014-04-22 23:21:12 +00:00
Jim Ingham
239df8cd5c Relax the requirement on setting the containing Decl context when being used by the debugger.
<rdar://problem/16680866>


Swift SVN r16673
2014-04-22 22:52:39 +00:00
Argyrios Kyrtzidis
3a4d5a54cd [AST] Add some static_asserts to make sure adding a ClangNode to the AST object doesn't violate its alignment.
Suggested by Jordan.

Swift SVN r16650
2014-04-22 06:50:00 +00:00
Argyrios Kyrtzidis
b3f470ad16 [ClangImporter] Make getting the ClangNode from a swift Decl more efficient by
allocating extra memory and storing it directly before the swift AST object.

Reduces code-completion time for Cocoa by -25%.

Swift SVN r16615
2014-04-21 07:18:50 +00:00
Doug Gregor
1f4b73b93f Tricky selector-style parameter parsing into creating ParamDecls.
The selector-style parameter parsing code is going away "soon", but we
still need to prop it up a bit longer. Hence, I don't feel too bad
about the Parser-level state I'm using in this hack to make it happen.

With that change, we can now establish two important invariants in the
AST:
  - Only parameters (ParamDecl or GenericTypeParamDecl) can have their
  DeclContexts changed. Everything else comes into being in the
  correct context.
  - All of the parameters in a function/constructor/closure/etc. are
  described by ParamDecls, not just VarDecls.



Swift SVN r16593
2014-04-20 18:25:23 +00:00
Doug Gregor
09797f7f99 Introduce a new declaration node, ParamDecl, for function parameters.
Use this node to capture the argument name and its source location in
the AST. We're only building these in one place at the moment; the
rest will be updated soon.


Swift SVN r16581
2014-04-20 05:23:35 +00:00
Doug Gregor
6b3ef547ec Replace "Members" arrays with an intrusive linked list.
The use of ASTContext-allocated arrays to store the members of nominal
type declarations and the extensions thereof is an
abomination. Instead, introduce the notion of an "iterable"
declaration context, which keeps track of the declarations within that
context (stored as a singly-linked list) and allows iteration over
them. When a member is added, it will also make sure that the member
goes into the lookup table for its context immediately.

This eliminates a ton of wasted memory when we have to reallocate the
members arrays for types and extensions, and moves us toward a much
more sane model. The only functionality change here is that the Clang
importer no longer puts subscript declarations into the wrong class,
nor does it nested a C struct within another C struct.



Swift SVN r16572
2014-04-19 23:37:06 +00:00
Doug Gregor
8bc2ea4ea1 Use designated/convenience initializer terminology throughout. NFC
Introduce CtorInitializerKind to describe the kind of an enum, rather
than a bool, to make way for more initializer kinds in the future.

Swift SVN r16525
2014-04-18 15:10:13 +00:00
Argyrios Kyrtzidis
2c88bb3f59 [AST] Modify mangleObjCRuntimeName to allow getting the ObjC runtime name of a class or protocol
without needing a fully typechecked AST.

Part of rdar://16521245

Swift SVN r16503
2014-04-18 07:07:11 +00:00
Argyrios Kyrtzidis
26114ca4a1 [AST] Add some const goodness, NFC.
Swift SVN r16492
2014-04-18 04:14:41 +00:00
Doug Gregor
8e597cc695 Eliminate argument parameter patterns.
Swift SVN r16444
2014-04-17 05:20:14 +00:00
Joe Pamer
7107aee3ca If a semantic error occurs while resolving an associated type during archetype construction, we should propagate the error rather than crash. (rdar://problem/16427613)
Swift SVN r16427
2014-04-17 00:24:05 +00:00
Doug Gregor
6493231b77 Switch Objective-C selector computation for initializers over to the method name.
Swift SVN r16405
2014-04-16 07:50:44 +00:00
Doug Gregor
2d70fbad63 Give initializers compound names.
Swift SVN r16404
2014-04-16 07:44:31 +00:00
Doug Gregor
cb252d76d7 Switch Objective-C selector creation for methods from argument patterns to arguments in the name.
Swift SVN r16399
2014-04-16 06:20:49 +00:00