Commit Graph

124 Commits

Author SHA1 Message Date
Xi Ge
055da1fbfb [SourceKit] Teach name translation request to translate Swift names to ObjC ones (by using PrintAsObjC). (#7449) 2017-02-14 14:25:52 -08:00
Jordan Rose
c011aa04fd Pull PointerLikeTypeTraits<DeclName> up to Identifier.h
No functionality change.
2017-01-10 16:43:40 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Alex Hoppen
64aaacb309 [AST] Bugfix in ordering of DeclNames 2016-12-15 08:43:01 +01: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
Doug Gregor
8802d6d52a Improve diagnostics for selector collisions with @objc optional requirements.
When an optional requirement of an @objc protocol has a selector that
collides with an entity that has a different *Swift* name but produces
an Objective-C method with the same selector, we have an existing
diagnostic complaining about the conflict. In such cases, make a few
suggestions (with Fix-Its) to improve the experience:

* Change Swift name to match the requirement, adding or modifying the
  @objc as appropriate.
* Add "@nonobjc" to silence the diagnostic, explicitly opting out of
  matching an @objc requirement.

This is intended to help with migration of Swift 2 code into Swift
3. The Swift 2 code will produce selectors that match Objective-C
methods in the protocol from Swift names that don't match; this helps
fix up those Swift names so that we now match.

Fixes the rest of rdar://problem/25159872. In some sense, it's a
stop-gap for more detailed checking of near-misses for optional
requirements, but it's not clear how wide-reaching such changes would
be.
2016-04-19 10:22:23 -07:00
Greg Parker
125a146365 Revert "[Sema] Improve diagnostics for witness mismatches against @objc protocols." and "Improve diagnostics for selector collisions with @objc optional requirements."
This reverts commits 46269299cd
and 27279866ad
and c826a408dd.

The changes broke test bots, including
https://ci.swift.org/job/oss-swift-package-osx/1348/
2016-04-19 05:52:33 -07:00
Doug Gregor
27279866ad Improve diagnostics for selector collisions with @objc optional requirements.
When an optional requirement of an @objc protocol has a selector that
collides with an entity that has a different *Swift* name but produces
an Objective-C method with the same selector, we have an existing
diagnostic complaining about the conflict. In such cases, make a few
suggestions (with Fix-Its) to improve the experience:

* Change Swift name to match the requirement, adding or modifying the
  @objc as appropriate.
* Add "@nonobjc" to silence the diagnostic, explicitly opting out of
  matching an @objc requirement.

This is intended to help with migration of Swift 2 code into Swift
3. The Swift 2 code will produce selectors that match Objective-C
methods in the protocol from Swift names that don't match; this helps
fix up those Swift names so that we now match.

Fixes the rest of rdar://problem/25159872. In some sense, it's a
stop-gap for more detailed checking of near-misses for optional
requirements, but it's not clear how wide-reaching such changes would
be.
2016-04-18 17:08:06 -07:00
Dmitri Gribenko
023eaa6aa8 Merge pull request #1926 from danra/patch-1
Add missing period in end of comment (NFC)
2016-03-29 17:19:19 -07:00
danra
03862bc3ed Finish comment (NFC) 2016-03-30 00:35:19 +03:00
Dan Raviv
201873b729 Prettier operator!= DRY 2016-03-29 23:40:16 +03:00
Chris Lattner
de436b148d Merge pull request #1885 from danra/identifier_opaque_ptr
Fix getAsOpaquePointer method const-correctness
2016-03-26 19:40:41 -07:00
Ted Kremenek
338d8ead31 Merge pull request #1880 from danra/patch-1
Assert on calling getLength() on empty Identifier
2016-03-26 11:01:25 -07:00
Ted Kremenek
dc1106b999 Merge pull request #1884 from danra/identifier_notequals_dry
operator!= DRY
2016-03-26 11:01:02 -07:00
Dan Raviv
5124ff1bb6 Fix getAsOpaquePointer method const-correctness
In order for the method to be const, it should cast its Pointer member to a const void* and return it as such, not as a void*. This wasn't caught before due to using a C-style cast which stripped away the member's constness implicitly.
2016-03-26 20:04:14 +03:00
Dan Raviv
e7b9844b23 operator!= DRY 2016-03-26 19:50:15 +03:00
danra
0dce9f1352 Use nullptr instead of 0 for null pointer value 2016-03-26 18:19:46 +02:00
danra
e2851a9626 Assert on calling getLength() on empty Identifier
Calling ::strlen on nullptr is not allowed, but getLength() does not such check. We should either check for nullptr and return 0, or just assert assuming that calling getLength() on an empty Identifier is not intended and indicates a bug. Here the second approach was selected.
2016-03-26 18:17:37 +02:00
Dmitri Gribenko
8b86dac8c1 Revert "[gardening] Fix typo: "nul-terminated" → "null-terminated"" 2016-02-13 15:27:53 -08:00
Peter Friese
888d0f3fa6 [gardening] Fix typo: "nul-terminated" → "null-terminated" 2016-02-11 11:03:38 +00:00
Jordan Rose
d9d49f72a3 Adopt llvm::TrailingObjects as much as possible in AST.
This class formalizes the common case of the "trailing allocation" idiom we use
frequently. I didn't spot any true bugs while making this change, but I did see
places where we were using the wrong pointer type or casting through void* for
no good reason. This will keep us honest.

I'll get to the other libraries soon.
2016-02-08 19:40:47 -08:00
Doug Gregor
ecfde0e71c Start parsing names with argument labels.
Basic implementatation of SE-0021, naming functions with argument
labels. Handle parsing of compound function names in various
unqualified-identifier productions, updating the AST representation of
various expressions from Identifiers to DeclNames. The result doesn't
capture all of the source locations we want; more on that later.

As part of this, remove the parsing code for the "selector-style"
method names, since we now have a replacement. The feature was never
publicized and doesn't make sense in Swift, so zap it outright.
2016-01-20 17:09:01 -08:00
Doug Gregor
67c81154af Add a swift3_migration attribute to describe how an API gets migrated.
Introduce a new attribute, swift3_migration, that lets us describe the
transformation required to map a Swift 2.x API into its Swift 3
equivalent. The only transformation understood now is "renamed" (to
some other declaration name), but there's a message field where we can
record information about other changes. The attribute can grow
somewhat (e.g., to represent parameter reordering) as we need it.

Right now, we do nothing but store and validate this attribute.
2016-01-13 16:53:01 -08:00
Chris Lattner
a30ae2bf55 Merge pull request #836 from zachpanz88/new-year
Update copyright date
2015-12-31 19:36:14 -08:00
Chris Lattner
7daaa22d93 Completely reimplement/redesign the AST representation of parameters.
Parameters (to methods, initializers, accessors, subscripts, etc) have always been represented
as Pattern's (of a particular sort), stemming from an early design direction that was abandoned.
Being built on top of patterns leads to patterns being overly complicated (e.g. tuple patterns
have to have varargs and default parameters) and make working on parameter lists complicated
and error prone.  This might have been ok in 2015, but there is no way we can live like this in
2016.

Instead of using Patterns, carve out a new ParameterList and Parameter type to represent all the
parameter specific stuff.  This simplifies many things and allows a lot of simplifications.
Unfortunately, I wasn't able to do this very incrementally, so this is a huge patch.  The good
news is that it erases a ton of code, and the technical debt that went with it.  Ignoring test
suite changes, we have:
   77 files changed, 2359 insertions(+), 3221 deletions(-)

This patch also makes a bunch of wierd things dead, but I'll sweep those out in follow-on
patches.

Fixes <rdar://problem/22846558> No code completions in Foo( when Foo has error type
Fixes <rdar://problem/24026538> Slight regression in generated header, which I filed to go with 3a23d75.

Fixes an overloading bug involving default arguments and curried functions (see the diff to
Constraints/diagnostics.swift, which we now correctly accept).

Fixes cases where problems with parameters would get emitted multiple times, e.g. in the
test/Parse/subscripting.swift testcase.

The source range for ParamDecl now includes its type, which permutes some of the IDE / SourceModel tests
(for the better, I think).

Eliminates the bogus "type annotation missing in pattern" error message when a type isn't
specified for a parameter (see test/decl/func/functions.swift).

This now consistently parenthesizes argument lists in function types, which leads to many diffs in the
SILGen tests among others.

This does break the "sibling indentation" test in SourceKit/CodeFormat/indent-sibling.swift, and
I haven't been able to figure it out.  Given that this is experimental functionality anyway,
I'm just XFAILing the test for now.  i'll look at it separately from this mongo diff.
2015-12-31 19:24:46 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
practicalswift
64f6c59bf4 Prune some redundant #includes 2015-12-28 22:18:46 +01:00
Chris Lattner
d03fc2c536 Prune some redundant #includes, noticed by inspection. 2015-12-27 20:55:01 -08:00
practicalswift
22e10737e2 Fix typos 2015-12-26 01:19:40 +01:00
Chris Lattner
0bfacde242 Fix: <rdar://problem/16230507> Cannot use a negative constant as the second operator of ... operator
This is a case that the operator splitting code didn't handle because of
the bizarre lexer code for handling operators with periods in them.  We had
accreted some weird special case logic for what is valid in an operator
(but which even had a special case hack for ..<).  The policy is now very
simple: if an operator name starts with a dot, it is allowed to include other
dots in its name.  If it doesn't, it doesn't.  This allows us to get lexer
level operator splitting in cases like x=.Foo, allowing our existing operator
set that have dots in them without hacks, and provides a superior QoI
experience due to operator splitting.

This is technically a language change, but the TSPL operator grammar was
incorrect for it anyway.  I will file an internal radar to get TSPL updated
with the actual behavior (now that it is defensible).
2015-12-16 22:16:19 -08:00
Doug Gregor
2d7044c024 Clang importer: move name translation for throwing methods into importFullName.
The translation from the Objective-C NSError** convention into Swift
throwing methods alters the names of methods. Move that computation
into importFullName. This should be NFC refactoring for everything
except the Swift name lookup tables, which will now correctly reflect
this name translation.
2015-12-03 11:50:42 -08:00
John McCall
4fc21092dc Check for a couple of special-cased selectors more
efficiently than re-uniquing them constantly.

Swift SVN r27540
2015-04-22 00:04:14 +00:00
Chris Willmore
690daa539a Back out changes for in-place methods/operators from Xcode 7.
This reverts commits r26508, r26545, and r26576.

Swift SVN r26900
2015-04-02 21:14:28 +00:00
Chris Willmore
1ee6f7e67c Implement syntax changes for in-place methods.
Rename 'assignment' attribute of infix operators to 'mutating'. Add
'has_assignment' attribute, which results in an implicit declaration of
the assignment version of the same operator. Parse "func =foo"
declaration and "foo.=bar" expression. Validate some basic properties of
in-place methods.

Not yet implemented: automatic generation of wrapper for =foo() if foo()
is implemented, or vice versa; likewise for operators.

Swift SVN r26508
2015-03-25 00:22:41 +00:00
Argyrios Kyrtzidis
a935e7c13e [Lexer] Recognize editor placeholders as identifiers and provide a specific error when encountered.
Swift SVN r26212
2015-03-17 01:52:59 +00:00
Doug Gregor
b27e88b70b Record Objective-C method lookup tables in Swift modules.
Include a mapping from Objective-C selectors to the @objc methods that
produce Objective-c methods with those selectors. Use this to lazily
populate the Objective-C method lookup tables in each class. This makes
@objc override checking work across Swift modules, which is part of
rdar://problem/18391046.

Note that we use a single, unified selector table, both because it is
simpler and because it makes global queries ("is there any method with
the given selector?") easier.

Swift SVN r23214
2014-11-11 00:19:03 +00:00
Doug Gregor
89e5e5b6fa Diagnose redeclarations of Objective-C methods.
@objc methods, initializers, deinitializers, properties, and
subscripts all produce Objective-C methods. Diagnose cases where two
such entities (which may be of different kinds) produce the same
Objective-C method in the same class.

As a special exception, one can have an Objective-C method in an
extension that conflicts with an Objective-C method in the original
class definition, so long as the original class definition is from a
different model. This reflects the reality in Objective-C that the
category definition wins over the original definition, and is used in
at least one overlay (SpriteKit).

This is the first part of rdar://problem/18391046; the second part
involves checking that overrides are sane.

Swift SVN r23147
2014-11-07 01:15:14 +00:00
Chris Lattner
d7bcbc3817 make ? a general operator character, allowing user defined operators like ??=. We already
reserve ? itself as a special token that cannot be defined (protecting ternary, postfix ?, 
etc) but add some defensive code to prevent people from defining those operators.

<rdar://problem/17923322> allow ? as a general operator character



Swift SVN r21051
2014-08-05 23:06:29 +00:00
Joe Groff
e733f1e816 Lexer: Accept variation selectors as continuations of operators.
Fixes mysterious "invalid character" errors when an operator character is followed by a variation selector.

Swift SVN r17807
2014-05-09 22:03:24 +00:00
Doug Gregor
3d4df3427a Pretty-print DeclNames with no keyword arguments by dropping the parenthsized bit.
Instead of printing "f(_:_:)", just print "f". 


Swift SVN r17078
2014-04-30 06:28:36 +00:00
Argyrios Kyrtzidis
9638623493 [AST] Make dump functions const, NFC.
Swift SVN r16917
2014-04-27 05:33:38 +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
Doug Gregor
86ecc725c9 Start building compound names for functions parsed with the new signature style.
Swift SVN r16394
2014-04-16 03:55:05 +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
Doug Gregor
18bf604360 Distinguish betweeen simple names ("foo") and zero-argument compound names ("foo()").
This isn't actually used yet, but it's an important distinction.

Swift SVN r16326
2014-04-14 20:05:34 +00:00
Doug Gregor
9189145cc5 Change DeclName over to basename(arg1:arg2:...argN:).
Swift will use the basename + argument names formulation for
names. Update the DeclName interfaces, printing, and __FUNCTION__ to
use the method syntax.

We'll still need to rework the "x.foo:bar:wibble:" syntax; that will
come (significantly) later.

Swift SVN r15763
2014-04-02 00:00:03 +00:00
Joe Groff
1585b625f9 Sema: Wire up compound name lookup to UnresolvedSelectorExpr.
Resolve selector references using compound name lookup, pushing DeclNames a bit deeper through the type-checker and diagnostics as necessary.

Swift SVN r14791
2014-03-07 20:52:30 +00:00
Joe Groff
96c09d7179 Renovate name lookup to prepare for compound name lookup.
Make the name lookup interfaces all take DeclNames instead of identifiers, and update the lookup caches of the various file units to index their members by both compound name and simple name. Serialized modules are keyed by identifiers, so as a transitional hack, do simple name lookup then filter the results by compound name.

Swift SVN r14768
2014-03-07 03:21:29 +00:00
Joe Groff
c2339cd091 AST: Unique compound names in the ASTContext.
Add a folding set for CompoundDeclNames so that identical names can be compared by pointer equality.

Swift SVN r14753
2014-03-06 21:10:28 +00:00
Chris Lattner
96947b2606 Change silgen to lower string literal lengths to an explicit value, instead of using
the result of the string_literal instruction.

This fixes:
<rdar://problem/15883849> Diagnostic CCP should be able to fold operations on string_literal lengths

I will follow up with cleanups this enables.




Swift SVN r13361
2014-02-03 18:26:46 +00:00