Commit Graph

889 Commits

Author SHA1 Message Date
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
Doug Gregor
e12afa2e1d Start naming functions more uniformly.
For any function that has a name, ensure that the name is a compound
name with argument names for each of the parameters. 


Swift SVN r16398
2014-04-16 06:05:45 +00:00
Joe Groff
69a1f91ded AST: Fix a typo that caused all generic struct property accesses to be computed.
Two little characters cause array complexity to jump from O(n) to O(n^2)! Fixes <rdar://problem/16629598>.

Swift SVN r16392
2014-04-16 03:31:01 +00:00
Doug Gregor
7c961a501f Migrate off a few more ArgParamPatterns
Swift SVN r16391
2014-04-16 03:22:47 +00:00
Chris Lattner
ca7ed40cf0 change Sema to synthesize getters and setters for properties in classes,
even if they are @final.  To get good performance for them, just always
perform direct access to the underlying storage, instead of going through
the accessors.

This allows them to properly fulfill protocol witnesses without overhead,
allows the objc runtime to find them properly, and is just a cleaner way
to go.


Swift SVN r16357
2014-04-15 04:43:36 +00:00
John McCall
f70879c4d9 Fix a weirdly complicated issue with the order of
type-checking and applying attributes.

We should really move to a model where variables are
type-checked in a single pass, including their attributes.
However, given that we don't, attributes which affect the
type must be applied in multiple places and hence multiple
times to the same declaration.

Swift SVN r16339
2014-04-14 22:54:30 +00:00
Doug Gregor
53b84c121e Switch ValueDecl::getObjCSelector() and friends over to ObjCSelector.
Formatting names into strings repeatedly, and using those for semantic
analysis, is generally considered poor form. Additionally, use the
camelCase utilities to perform the string manipulation we need, and
cache results on the ObjCAttr so we don't repeatedly do string
manipulation.

Swift SVN r16334
2014-04-14 22:02:51 +00:00
Doug Gregor
cd4ca76b6a Introduce the ObjCSelector class to store an Objective-C selector.
We have to work with selectors quite often, so provide an efficient
representation for them. Switch ObjCAttr over to this representation,
which has the nice property that it efficiently represents implicit
@objc attributes with names and allows us to overwrite the Objective-C
name without losing all source information. Addresses
<rdar://problem/16478678>, and sets us up for dealing with selectors
better.

Swift SVN r16327
2014-04-14 20:05:35 +00:00
Chris Lattner
6e90d343be At long last, land the implementation of <rdar://problem/16397000> Should be able to override stored properties
This means that we now synthesize getters and setters a lot more than we used to, so the
implementation work on this shook out a ton of bugs with them.

There is still one failure that I don't understand at all (test/stdlib/NewArray.swift.gyb), 
nor do I understand how to diagnose the problem, so I XFAILed it and filed rdar://16604980 to
track fixing it.



Swift SVN r16299
2014-04-14 04:48:54 +00:00
Argyrios Kyrtzidis
31a620f1ee [IDE/ModuleInterface] Fix erroneously printed newline between a regular comment and the declaration it is 'attached' to.
Swift SVN r16293
2014-04-14 03:28:05 +00:00
Doug Gregor
2d28d70bf8 Remove the language/driver/frontend options to enable/disable mangled names for the ObjC runtime.
Burn the bridges!


Swift SVN r16277
2014-04-13 05:36:08 +00:00
Joe Groff
42a942925b Enable block bridging.
Swift SVN r16248
2014-04-12 05:13:45 +00:00
Joe Groff
ef4afbcffa Allow function-type properties to use ObjC dispatch.
Now they can bridge to blocks.

Swift SVN r16246
2014-04-12 05:13:37 +00:00
John McCall
8a85750c4c Plumb a lot of querying for different kinds of existential
type.

Swift SVN r16232
2014-04-11 22:30:14 +00:00