Commit Graph

689 Commits

Author SHA1 Message Date
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
fa0b339a21 Fix typos. 2015-12-26 17:51:59 +01:00
Max Moiseev
200be71583 Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-23 10:28:04 -08:00
Chris Lattner
f7252d2ea1 Fix <rdar://problem/22000564> Crash on Subscript taking a tuple argument list
by changing buildSubscriptIndexReference to work solely in terms of the parameter
pattern of the subscript, instead of trying to walk the index type in parallel to
extract parameter labels.
2015-12-22 22:15:06 -08:00
Max Moiseev
a7339e67ac Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-22 11:36:07 -08:00
practicalswift
36d7072013 Remove immediately adjacent repeated words ("the the", "for for", "an an", etc.). 2015-12-21 22:16:04 +01:00
Max Moiseev
2f7b64e475 Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-21 12:02:13 -08:00
practicalswift
176f487d76 Fix incorrect filenames in headers. 2015-12-20 23:59:05 +01:00
Doug Gregor
f245f18a09 Merge remote-tracking branch 'origin/swift-3-api-guidelines' into swift-3-omit-needless-words 2015-12-17 11:35:58 -08:00
Slava Pestov
59a74b4dfe Sema: Clean up configureImplicitSelf() and related code to not return a generic parameter list, NFC
Instead, get the generic parameter list from the DeclContext,
since now we need it even if there's no 'self' type.
2015-12-15 22:59:38 -08:00
Doug Gregor
06c5e9cd5b Enable "omit needless words" by default.
Most of this is in updating the standard library, SDK overlays, and
piles of test cases to use the new names. No surprises here, although
this shows us some potential heuristic tweaks.

There is one substantive compiler change that needs to be factored out
involving synthesizing calls to copyWithZone()/copy(zone:). Aside from
that, there are four failing tests:

    Swift :: ClangModules/objc_parse.swift
    Swift :: Interpreter/SDK/Foundation_test.swift
    Swift :: Interpreter/SDK/archiving_generic_swift_class.swift
    Swift :: Interpreter/SDK/objc_currying.swift

due to two independent remaining compiler bugs:
  * We're not getting partial ordering between NSCoder's
  encode(AnyObject, forKey: String) and NSKeyedArchiver's version of
  that method, and
  * Dynamic lookup (into AnyObject) doesn't know how to find the new
  names. We need the Swift name lookup tables enabled to address this.
2015-12-11 14:46:50 -08:00
Justas Brazauskas
043c518b27 Fix typos 2015-12-09 17:54:54 +02:00
Slava Pestov
fe4390aac5 Sema: Access stored properties of resilient structs through accessors
Synthesize accessors for stored properties when appropriate, and use them
if the struct is in a different module.

For now, this goes along with a resilience domain being a single module.
2015-11-13 13:20:49 -08:00
Michael Gottesman
7820961891 Revert commits to fix the build.
Revert "Fix complete_decl_attribute test for @fixed_layout"
Revert "Sema: non-@objc private stored properties do not need accessors"
Revert "Sema: Access stored properties of resilient structs through accessors"
Revert "Strawman @fixed_layout attribute and -{enable,disable}-resilience flags"

This reverts commit c91c6a789e.
This reverts commit 693d3d339f.
This reverts commit 085f88f616.
This reverts commit 5d99dc9bb8.
2015-11-12 10:40:54 -08:00
Slava Pestov
085f88f616 Sema: non-@objc private stored properties do not need accessors
Mostly NFC, since SILGen would in practice never emit them.
2015-11-12 02:30:08 -08:00
Slava Pestov
693d3d339f Sema: Access stored properties of resilient structs through accessors
Synthesize accessors for stored properties when appropriate, and use them
if the struct is in a different module.

For now, this goes along with a resilience domain being a single module.
2015-11-12 02:30:07 -08:00
Xi Ge
9586337981 [Parser] Allow FuncDecl to record the locations of accessor keywords, e.g. set, get, etc. 2015-11-03 18:13:32 -08:00
Jordan Rose
070ccba166 Verify that a function's DeclName, TuplePattern, and ParamDecls are in sync.
This required a few changes in places where we synthesize functions to
make sure these properties hold. That's good because we don't know where
we might already be depending on them. (On the other hand, we could also
decide not to care about TuplePattern labels, in which case I wonder if
we could eventually discard them altogether in functions.)

Still untested: that the function type is also in sync.
2015-11-02 18:16:19 -08:00
Slava Pestov
a0609ae51a Fix typos
Swift SVN r32158
2015-09-22 21:08:25 +00:00
Slava Pestov
1ca56079f9 Sema: Fix crash if subscript return type cannot be resolved
Fixes <rdar://problem/20280413>.

Swift SVN r30881
2015-07-31 21:22:50 +00:00
Joe Groff
58ccc8e160 Sema: Check mutating-ness of methods irrespective of reference semantics.
Some types are born to mutating methods, and some types have mutating methods thrust upon them. Protocol extensions put classes into the latter category. A 'mutating' protocol extension method requires a mutable 'self' base even when applied to a class. Fix the synthesized getter for lazy properties so that it's only marked 'mutating' on value types, since otherwise it'd now be impossible to access lazy properties on immutable class references.

Fixes part of rdar://problem/21578832, allowing 'mutating' methods from protocol extensions to apply to mutable class references. Properties with mutating setters are still improperly allowed on immutable class reference bases though.

Swift SVN r30557
2015-07-24 00:10:16 +00:00
Doug Gregor
f00e5bc6ab Allow a variadic parameter anywhere in the parameter list.
Requiring a variadic parameter to come at the end of the parameter
list is an old restriction that makes no sense nowadays, and which we
had all thought we had already lifted. It made variadic parameters
unusable with trailing closures or defaulted arguments, and made our
new print() design unimplementable.

Remove this restriction, replacing it with a less onerous and slightly
less silly restriction that we not have more than one variadic
parameter in a given parameter clause. Fixes rdar://problem/20127197.

Swift SVN r30542
2015-07-23 18:45:29 +00:00
Slava Pestov
871d71a555 Sema: Differentiate between 'class is @objc' and 'class has implicitly @objc members'
Generic subclasses of @objc classes are thus no longer @objc, but still
have implicitly @objc members.

Explicit @objc on generic classes or classes that inherit from @objc
classes is now forbidden with a diagnostic. Users need to know that
while they can override Objective-C methods and properties in such
a class, they cannot refer to the class by name from Objective-C code,
since it will not appear in the bridging header.

Fixes <rdar://problem/21342574>.

Swift SVN r30494
2015-07-22 06:34:20 +00:00
Slava Pestov
b03a77f13c Sema: Fix some compiler crashes related to ErrorType handling
- NominalTypeDecl::computeInterfaceType() crash when parent decl
  has error type
- createMaterializeForSetPrototype() crash when parent decl
  has error type
- Crashes in ConformanceChecker when decl has error type

Fixes <rdar://problem/21583601>.

Swift SVN r29912
2015-07-04 01:53:36 +00:00
Slava Pestov
e7d8c3c4bc Sema: Fix synthesis of materializeForSet for subscripts in protocol extensions
Since each override of a subscript protocol requirement provides
its own materializeForSet, there is no need to do dynamic dispatch,
a peer call to the setter suffices. However, since CodeSynthesis
runs at the AST level, it would create a SubscriptExpr which
overload resolution would later bind to the protocol requirement
subscript rather than the static witness in the extension.

This triggered an assertion. Solve the problem by binding the
actual ConcreteDeclRef of the SubscriptExpr at synthesis time,
and modifying CSGen to special-case SubscriptExprs that already
have a ConcreteDeclRef set.

Fixes <rdar://problem/21370629>.

Swift SVN r29906
2015-07-03 02:25:26 +00:00
Devin Coughlin
c67ac0d63b [Sema] Add source location for synthesized designated initializer overrides.
When synthesizing designated initializer overrides, set the source location
for the synthesized ConstructorDecl to the location of the opening brace of
the containing ClassDecl. This resolves an assertion failure when constructing
type refinement contexts when whole-program optimization is turned on.

rdar://problem/21233342

Swift SVN r29384
2015-06-15 19:46:09 +00:00
Joe Groff
1479a56ab3 Sema: Move semantic constraints on super/self.init out of the parser.
Instead of forcing full application of '{super,self}.init' in the parser, and installing the RebindSelf semantic expr node early, make these constraints to Sema-time checks, and parse '<expr>.init' as a regular postfix production. This is a better separation of concerns, and also opens the door to supporting 'metatype.init()' in more general expression contexts (though that part still needs some follow-up sema work).

Swift SVN r29343
2015-06-08 04:11:16 +00:00
Jordan Rose
de81a3e15f Prefer using known-identifiers to using getIdentifier.
I didn't add anything to the table, just made use of what was already there.
We have plenty of additional calls to getIdentifier that could probably benefit
from this kind of easy access as well.

This commit also removes FOUNDATION_MODULE_NAME and OBJC_MODULE_NAME from
Strings.h. Neither of these is likely to change in the future, and both
already have KnownIdentifiers equivalents in use.

No intended functionality change.

Swift SVN r29292
2015-06-04 04:01:08 +00:00
Chris Willmore
52d441ba61 Have a bit per PatternBindingEntry saying whether the corresponding
initializer has been type-checked, rather than a bit for the entire
PatternBindingDecl.

<rdar://problem/21057425> Crash while compiling attached test-app.

Swift SVN r29049
2015-05-27 01:31:28 +00:00
John McCall
759df1e74c Wrap a throwing superclass initializer call with 'try' when
synthesizing an override.

rdar://20944100

Swift SVN r28925
2015-05-22 18:43:31 +00:00
Joe Groff
e9ef518f98 Sema: Register accessors for synthesized properties of Clang-imported types as external too.
This is necessary to catch things like the rawValue of NS_OPTIONS types, which doesn't directly correspond to a C decl but still needs to be emitted as an external decl.

Swift SVN r28902
2015-05-22 05:47:22 +00:00
Chris Lattner
d6ba8666ca various parts of the compiler are doggedly trying to figure out
whether a getter is mutating or a setter is nonmutating, centralize
it into methods on AbstractStorageDecl, NFC.


Swift SVN r28823
2015-05-20 05:00:13 +00:00
Chris Lattner
258f91f60b revert: r28801 - improve the source location information for { and } in a ClosureExpr.
Instead, provide the location of the { in a closure expr to the argument formation as 
part of the datastructure already used to manage implicit closure arguments in the parser.


Swift SVN r28818
2015-05-20 03:19:56 +00:00
Chris Lattner
66916683a2 improve the source location information for { and } in a ClosureExpr, by
actually tracking it. NFC.


Swift SVN r28801
2015-05-20 00:10:04 +00:00
Joe Groff
cbb6d71c96 Sema: Register synthesized accessors for protocol witnesses as external decls.
This ensures SILGen will emit the accessor bodies. Fixes rdar://problem/19509451.

Swift SVN r28685
2015-05-17 19:15:43 +00:00
Ted Kremenek
62feb5c949 Change @availability to @available.
This came out of today's language review meeting.
The intent is to match #available with the attribute
that describes availability.

This is a divergence from Objective-C.

Swift SVN r28484
2015-05-12 20:06:13 +00:00
Doug Gregor
b8995b0aa3 Transform the Module class into ModuleDecl.
Modules occupy a weird space in the AST now: they can be treated like
types (Swift.Int), which is captured by ModuleType. They can be
treated like values for disambiguation (Swift.print), which is
captured by ModuleExpr. And we jump through hoops in various places to
store "either a module or a decl".

Start cleaning this up by transforming Module into ModuleDecl, a
TypeDecl that's implicitly created to describe a module. Subsequent
changes will start folding away the special cases (ModuleExpr ->
DeclRefExpr, name lookup results stop having a separate Module case,
etc.).

Note that the Module -> ModuleDecl typedef is there to limit the
changes needed. Much of this patch is actually dealing with the fact
that Module used to have Ctx and Name public members that now need to
be accessed via getASTContext() and getName(), respectively.

Swift SVN r28284
2015-05-07 21:10:50 +00:00
Jordan Rose
88c9ab591f Make sure we validate the synthesized accessors for NSManaged properties.
(as well as those for lazy properties, which seem to be working already)

This fixes a problem with @NSManaged properties being declared in an
extension in a generated file you're not supposed to modify, which
unfortunately is exactly how Xcode's generating them these days.

rdar://problem/20821582

Swift SVN r28180
2015-05-05 20:02:12 +00:00
Jordan Rose
edf1958f86 Sema: ParamDecls never get accessors.
No functionality change; they wouldn't have ever hit either of the cases
later either.

Swift SVN r28179
2015-05-05 20:02:09 +00:00
Slava Pestov
43c96de2b0 Sema: slightly better diagnostics for @objc
If we inferred @objc, say so instead of telling the user they
"marked" the declaration @objc.

Swift SVN r28128
2015-05-04 19:26:25 +00:00
Slava Pestov
12d835c1d1 Sema: clean up @objc attribute handling a bit
There was a fair amount of code duplication in handling the various
places where @objc could either be explictly specified or be inferred;
centralize these in a new shouldMarkAsObjC() function. NFC

Swift SVN r28125
2015-05-04 19:26:21 +00:00
Chris Willmore
92acb40f6c Don't synthesize function bodies after type checking is over; they won't
get type checked and verification will fail.

<rdar://problem/20645582> Clan Importer assertion failure on swiftz.

Swift SVN r27901
2015-04-29 02:48:33 +00:00
Doug Gregor
a30ca2a60d Replace bool parameter to TypeChecker::conformsToProtocol() with an option set.
NFC; we can extend this option set more readily later.

Swift SVN r27894
2015-04-29 00:08:22 +00:00
Joe Pamer
006c182c13 Begin inferring throwing function types for closures. (There's more work to do here - hence the thin tests - but I need to investigate a couple of sema bugs before moving forward.)
Swift SVN r27438
2015-04-17 19:06:52 +00:00
Doug Gregor
41ae48b22e Start parsing 'throws' on initializers.
Introduce basic validation for throwing @objc initializers, e.g., a
failable @objc initializer cannot also be throwing. However,
Objective-C selector computation is broken.

Swift SVN r27292
2015-04-14 22:52:29 +00:00
Joe Groff
c0a2994564 AST: Start printing function types with @convention instead of old attributes.
And update tests to match.

Swift SVN r27262
2015-04-13 22:51:34 +00:00
Doug Gregor
5406878a7f Don't synthesize materializeForSet for members of protocol extensions.
They aren't dynamically dispatched contexts.

Swift SVN r27067
2015-04-07 06:01:17 +00:00
Devin Coughlin
bbdcf580ee Sema: Add @availability attributes when synthesizing materializeForSet accessors.
Synthesize implicit @availability attributes to make sure that a synthesized
materializeForSet accessor is available enough to access the underlying storage and its
getter and setter.

These synthesized attributes could trigger redundant diagnostics when a subclass gives
overriding getters or setters non-contravariant availability. We detect when this
happens and suppress the redundant diagnostics.

This commit also improves availability diagnostics in synthesized code. We now respect
synthesized @availability annotations on containing DeclContexts when determining the
potential OS versions that could be executed at invalid SourceLocations.

Swift SVN r27002
2015-04-05 03:02:20 +00:00
Joe Pamer
37d65f4202 Start tracking SourceLoc data for function "throws" annotations and eliminate the (now unnecessary) "Throws" bit from AbstractFunctionDecls.
Swift SVN r26955
2015-04-03 21:45:30 +00:00