Commit Graph

465 Commits

Author SHA1 Message Date
Denis Vnukov
4f92a08987 Adding a location of the var/let/inout to ParamDecl 2016-01-27 13:43:42 -08:00
Denis Vnukov
db6582c72b Fixed several AST nodes wrongly marked with implicit/explicit flag 2016-01-27 13:43:39 -08:00
Doug Gregor
8336419844 Include completion source location information compound DeclNames.
When one spells a compound declaration name in the source (e.g.,
insertSubview(_:aboveSubview:), keep track of the locations of the
base name, parentheses, and argument labels.
2016-01-25 14:13:13 -08:00
Doug Gregor
fd3f03f3be Remove UnresolvedConstructorExpr.
UnresolvedConstructorExpr is not providing any value here; it's
essentially just UnresolvedDotExpr where the name refers to an
initializer, so use that instead. NFC
2016-01-20 17:09:02 -08:00
Doug Gregor
c9c1d1390c [SE-0021] Allow naming of specific initializers via "self.init(foo:bar:)". 2016-01-20 17:09:02 -08:00
Slava Pestov
1d77d810fd Re-apply "Sema: Always synthesize accessors for structs, unless they were imported from Clang"
This reverts commit 24a70e17ea.
2016-01-20 15:04:10 -08:00
Max Moiseev
9a018bd77d Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-20 14:38:22 -08:00
Mark Lacey
24a70e17ea Revert "Sema: Always synthesize accessors for structs, unless they were imported from Clang"
This reverts commit 2b6ab633fc because it
at least breaks:
    Swift :: stdlib/SequenceType.swift.gyb
and possibly also results in some or all of these failures:
    Swift :: compiler_crashers/27944-swift-astvisitor.swift
    Swift :: compiler_crashers/28200-swift-typebase-getdesugaredtype.swift
    Swift :: stdlib/CollectionType.swift.gyb
    Swift :: stdlib/MicroStdlib.swift
2016-01-20 08:32:39 -08:00
Slava Pestov
2b6ab633fc Sema: Always synthesize accessors for structs, unless they were imported from Clang
This fixes the issue that "SILGen: Correctly emit accessors synthesized to
witness protocol requirements" was meant to solve, but in a simpler way.

A better fix would be to first address the issue where @_transparent
function bodies are not serialized in some cases, and then only emit
synthesized accessors as needed, in the original version of this patch.
To fix the duplicate symbol issues, we would emit the synthesized
accessors with shared linkage, which would always work once serialized
bodies were available.

For resilient structs of course, we'll always need to emit accessors
anyway.
2016-01-20 02:11:53 -08:00
Slava Pestov
5273249838 Sema: Fix for setter->isMutating() check before setter was type checked
With an upcoming patch we would call setMutating() on materializeForSet
before computing the setter's isMutating() in the case where a setter
was explicitly declared 'nonmutating'.

Fix that by replacing the setter->isMutating() call with a direct
computation of the expected result.

It seems that the materializeForSet of protocol protocol requirements
has to be mutating, even if the protocol is a class protocol or the
property is nonmutating -- I need to investigate why and fix SILGen
to not make this assumption, but in the meantime, opt-out of the
new logic with protocol requirements to avoid more breakage.
2016-01-20 01:50:17 -08:00
Doug Gregor
7d70b704e4 Merge commit '5e11e3f7287427d386636a169c4065c0373931a8' into swift-3-api-guidelines 2016-01-19 23:18:20 -08:00
Doug Gregor
c4a6902589 Abstract the set of known Foundation entities into a .def-driven enum. NFC
Specifically, we don't want to hard-code the Swift names of these
Objective-C entities, because the importer renaming will affect them.
2016-01-17 23:40:14 -08:00
Slava Pestov
9c3ccc9855 Sema: Plumb through resiliently-accessed global variables
My recent changes added "resiliently-sized" global variables, where a
global in one module is defined to be of a type from another module,
and the type's size is not known at compile time.

This patch adds the other half of the equation: when accessing a
global variable defined by another module, we want to use accessors
since we want to resiliently change global variables from stored to
computed and vice versa.

The main complication here is that the synthesized accessors are not
part of any IterableDeclContext, and require some special-casing in
SILGen and Serialization. There might be simplifications possible here.

For testing and because of how the resilience code works right now,
I added the @_fixed_layout attribute to global variables. In the
future, we probably will not give users a way to promise that a
stored global variable will always remain stored; or perhaps we will
hang this off of a different attribute, once we finalize the precise
set of attributes exposed for resilience.

There's probably some other stuff with lazy and observers I need to
think about here; leaving that for later.
2016-01-15 21:34:54 -08:00
Slava Pestov
6a85b06129 AST: Add AbstractStorageDecl::hasFixedLayout(), NFC
This is a preliminary cleanup before adding resilient access to
global variables. It might also enable @_fixed_layout properties
on resilient structs one day, if we choose to do that.

Also, change NominalTypeDecl::hasFixedLayout() to not care about
classes imported from Clang. IRGen already has its own fine-grained
queries and abstractions for asking this question, so don't try
to capture in the AST.
2016-01-15 21:34:54 -08:00
Erik Eckstein
b3c6fd49c2 Revert "SILGen: Correctly emit accessors synthesized to witness protocol requirements"
It breaks the swiftpm build.

This reverts commit 10c8ce824f.
2016-01-13 11:08:56 -08:00
Slava Pestov
10c8ce824f SILGen: Correctly emit accessors synthesized to witness protocol requirements
We weren't adding them as external decls unless they were for
storage on an imported type, which meant SILGen wasn't emitting
them if the conforming type was from a different Swift source
file, or in whole-module mode, a different module. This led
to linker errors.

Instead, always add accessors to the external decl list, but
skip them in SILGen if they are contained in the DeclContext
we are currently emitting (which is a source file or module).

Note that they are still emitted with the wrong linkage, from a
resilience perspective. Clients must only ever see public
exports for getters, setters and materializeForSet emitted
because they are required by resilience or the access pattern;
'accidental' accessors synthesized for protocol conformance
should not be public.
2016-01-11 21:40:25 -08:00
Slava Pestov
249242b08d SILGen: Always open-code materializeForSet
This improves MaterializeForSetEmitter to support emission
of static materializeForSet thunks, as well as witnesses.

This is now done by passing in a nullptr as the conformance
and requirement parameters, and adding some conditional code.

Along the way, I fixed a few limitations of the old code,
namely weak/unowned and static stored properties weren't
completely plumbed through. There was also a memory leak in
addressed materializeForSet, the valueBuffer was never freed.

Finally, remove the materializeForSet synthesis in Sema since
it is no longer needed, which fixes at least one known crash
case.
2016-01-11 19:53:16 -08:00
Max Moiseev
08e1e4a043 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-11 16:51:11 -08:00
Slava Pestov
a467674847 Sema: Always emit materializeForSelf for resilient structs
This gives us consistent behavior between stored and computed
properties.
2016-01-10 17:06:19 -08:00
Slava Pestov
c3dd77a50c Rename ASTContext::addedExternalDecl() to addExternalDecl() and improve some comments, NFC 2016-01-10 17:06:19 -08:00
Max Moiseev
f51e708a8f Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-04 12:25:25 -08:00
Chris Lattner
95f07f02b9 rename AST/Parameter.h to AST/ParameterList.h now that Parameter is gone. 2016-01-03 14:47:44 -08:00
Chris Lattner
6afe77d597 Eliminate the Parameter type completely - now ParameterList is just
an overblown array of ParamDecl*'s that also keeps track of parenlocs
and has helper methods.
2016-01-03 14:45:38 -08:00
Chris Lattner
ad82cbd5a9 Clone arguments with the implicit bit set when generating implicit accessors,
fixing a recently xfailed test.
2016-01-02 19:42:27 -08:00
Chris Lattner
4479b46ef0 move the TypeLoc for a parameter out of Parameter and onto ParamDecl. NFC. 2016-01-01 14:13:13 -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
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