Commit Graph

2546 Commits

Author SHA1 Message Date
Joe Groff
c7b9805ed2 Clang importer: Rename buildGetter/SetterThunk to buildSubscript.etterDecl.
These aren't thunks anymore; they have no body and just exist to represent the accessors of the subscript.

Swift SVN r28001
2015-04-30 22:13:05 +00:00
Joe Groff
fa8e2aac08 ClangImporter: Associate imported subscript accessors with Clang nodes.
This allows SILGen to recognize them as foreign declarations, fixing a bug when classes with subscripts defined in Objective-C were extended to conform to Swift protocols with subscript requirements. rdar://problem/20371661

Swift SVN r27998
2015-04-30 21:59:40 +00:00
Doug Gregor
592a8c86ab Stop using getProtocols() in the Clang importer.
The Clang importer was relying on stashing the protocol list within a
nominal type or extension and then retrieving it to fill in all of the
members, which will typically happen before the protocol conformances
can be handled. This prevented the conformance lookup table from being
directly usable for these protocol queries.

In time, the conformance lookup table should have separate callbacks
for "list the protocols to which this conforms" and "provide all of
the conformances", which can make these computations lazier. For now,
use a side table to stash these conformances.

Part of rdar://problem/18448811.

Swift SVN r27980
2015-04-30 16:13:46 +00:00
Doug Gregor
cf1bb3a8ce Remove the old "delayed protocol conformances" code.
It's in the way of progress; a better solution is coming.

Swift SVN r27970
2015-04-30 16:13:39 +00:00
Doug Gregor
8a8895de75 Populate the conformance lookup table for a deserialized protocol.
When deserializing a protocol, the conformance lookup table would not
contain entries for the inherited protocols of that protocol. They
were stashed in the "Protocols" array in TypeDecl (which will
eventually go away), but since there are no conformances for a
protocol, the conformance lookup table never got updated.

Nothing important seems to query this now; that will change soon.

Swift SVN r27967
2015-04-30 16:13:35 +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
Slava Pestov
fafd0b83ee Attempt to properly handle static global variables
This is based on Jordan Rose's patch from rdar://problem/17597453.

Swift SVN r27821
2015-04-27 22:16:37 +00:00
Joe Pamer
edee327df3 Per yesterday's specification update, initializers imported as throwing should not also be marked as failable.
Swift SVN r27695
2015-04-24 17:48:31 +00: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
Doug Gregor
e5f8557e52 Map Clang's 'deprecated' attribute to @availability(*, deprecated).
Previously, we were importing Clang's 'deprecated' attribute in as
@availability(*, unavailable), based on the idea things that were
unconditionally deprecated in Objective-C shouldn't even be accessible
in Swift. (We were motivated by 'tmpnam', among others). However, this
plays havoc with mixed Objective-C/Swift projects, because the
Objective-C 'deprecated' attribute was useless as a mechanism for
making internal changes in the project. We have Clang's
__attribute__((availability(swift, unavailable))) to make an API
unavailable in Swift, so the deprecated -> unavailable mapping here no
longer makes sense.

Fixes rdar://problem/18934173.

Swift SVN r27358
2015-04-16 17:09:46 +00:00
Doug Gregor
4e0e32197f Extend 'availability' attribute with an unconditional 'deprecated' option.
Allow an unversioned 'deprecated' attribute to specify unconditional
deprecation of an API, e.g.,

  @availability(*, deprecated, message="sorry")
  func foo() { }

Also support platform-specific deprecation, e.g.,

  @availability(iOS, deprecated, message="don't use this on iOS")
  func bar() { }

Addresses rdar://problem/20562871.

Swift SVN r27355
2015-04-16 06:36:45 +00:00
Doug Gregor
921855ee0d Revert "Extend 'availability' attribute with an unconditional 'deprecated' option."
This reverts r27339; it broke an iOS test.

Swift SVN r27343
2015-04-16 03:36:40 +00:00
Doug Gregor
b4b5dbb5d8 Extend 'availability' attribute with an unconditional 'deprecated' option.
Allow an unversioned 'deprecated' attribute to specify unconditional
deprecation of an API, e.g.,

  @availability(*, deprecated, message="sorry")
  func foo() { }

Also support platform-specific deprecation, e.g.,

  @availability(iOS, deprecated, message="don't use this on iOS")
  func bar() { }

Addresses rdar://problem/20562871.

Swift SVN r27339
2015-04-15 23:59:20 +00:00
Ben Langmuir
3982ca5135 Extend the hack that delays enum conformance checking to code-completion
This works around a big performance regression in code completion
performance that was introduced with r25741.  This hack does not work
completely correctly with multiple file builds, but a) this should be a
minor issue for enum code completions, and b) this simply returns to the
pre-25741 behaviour.  This hack should disappear when we fix
rdar://problem/20047340.

For rdar://problem/20445407.

Swift SVN r27320
2015-04-15 16:46:31 +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
Dmitri Hrybenko
6b8037374c ClangImporter: ignore availability(swift, unavailable) declarations when
calculating the common prefix of enumerators

rdar://20507924

Swift SVN r27228
2015-04-11 02:04:14 +00:00
Dmitri Hrybenko
3b8a2290de ClangImporter: ignore swift1_unavailable declarations when calculating
the common prefix of enumerators

rdar://20507924

Swift SVN r27227
2015-04-11 01:40:55 +00:00
John McCall
d62a154e29 Import ObjC method error-handling conventions. WIP.
Swift SVN r27193
2015-04-10 00:32:54 +00:00
Jordan Rose
86203cad7e [ClangImporter] Import enum case aliases using static let properties.
I don't want to call this complete until
a) we handle using alias names in switch statements (right now they're
   straight-up rejected, not just non-complete), and
b) we prefer non-deprecated names over deprecated ones to be the "real"
   enum cases.
but this is a good start, and fixes them showing up poorly in the SDK
analyzer.

rdar://problem/18662118

Swift SVN r27130
2015-04-08 19:23:38 +00:00
Jordan Rose
63e9f0fba5 [ClangImporter] Replace std::set with llvm::DenseSet.
No functionality change.

Swift SVN r27129
2015-04-08 19:23:34 +00:00
Jordan Rose
182ef27f95 [ClangImporter] Handle __attribute__((availability(swift, unavailable))).
This is the new and improved version of
__attribute__((annotate("swift1_unavailable"))), with the "improved" being
specifically that the 'availability' attribute supports a message.

This requires a corresponding Clang commit.

Swift side of rdar://problem/18768673.

Swift SVN r27053
2015-04-07 02:40:22 +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
Jordan Rose
b94f7a249e [Importer] Update CF_ENUM detection for changes in Foundation.
...and bump our "Foundation epoch" guard to 3 to match.

Long-term we should switch to an attribute for "yes, this is really a set
of enumerated constants" (and "this is a set of related bitmask options"),
but this unblocks things for now, and doesn't cause any issue if we end
up doing something else.

rdar://problem/20418505

Swift SVN r26944
2015-04-03 18:43:53 +00:00
Chris Lattner
79ed57f9f2 standardize naming of tuples and tuple patterns on "elements".
Previously some parts of the compiler referred to them as "fields",
and most referred to them as "elements".  Use the more generic 'elements'
nomenclature because that's what we refer to other things in the compiler
(e.g. the elements of a bracestmt).

At the same time, make the API better by providing "getElement" consistently
and using it, instead of getElements()[i].

NFC.



Swift SVN r26894
2015-04-02 20:23:49 +00:00
Doug Gregor
38cc1fe5c6 Remove LazyResolver arguments from API entry points to the conformance lookup table.
Swift SVN r26838
2015-04-02 00:06:01 +00:00
Doug Gregor
ccde6bb87d Allow protocol extensions to add further constraints via a trailing where clause.
Start parsing a "trailing" where clause for extension declarations, which follows the extended type name and (optional) inheritance clause. Such a where clause is only currently permitted for protocol extensions right now.

When used on a protocol extension, it allows one to create a more-constrained protocol extension, e.g.,

  extension CollectionType where Self.Generator.Element : Equatable { ... }

which appears to be working, at least in the obvious cases I've tried.

More cleanup, tests, and penance for the previous commit's "--crash" introductions still to come.

Swift SVN r26689
2015-03-29 05:42:37 +00:00
Doug Gregor
3d77855b31 Start allowing extensions of protocol types.
Remove the semantic restrictions that prohibited extensions of
protocol types, and start making some systematic changes so that
protocol extensions start to make sense:
  - Replace a lot of occurrences of isa<ProtocolDecl> and
    dyn_cast<ProtocolDecl> on DeclContexts to use the new
    DeclContext::isProtocolOrProtocolExtensionContext(), where we want
    that behavior to apply equally to protocols and protocol extensions.
  - Eliminate ProtocolDecl::getSelf() in favor of
    DeclContext::getProtocolSelf(), which produces the appropriate
    generic type parameter for the 'Self' of a protocol or protocol
    extension. Update all of the callers of ProtocolDecl::getSelf()
    appropriately.
  - Update extension validation to appropriately form generic
    parameter lists for protocol extensions.
  - Methods in protocol extensions always use the witnesscc calling
  convention.

At this point, we can type check and SILGen very basic definitions of
protocol extensions with methods that can call protocol requirements,
generic free functions, and other methods within the same protocol
extension.

Regresses four compiler crashers but improves three compiler
crashers... we'll call that "progress"; the four regressions all hit
the same assertion in the constraint system that will likely be
addressed as protocol extensions starts working.

Swift SVN r26579
2015-03-26 04:50:51 +00:00
Jordan Rose
83a4841829 [ClangImporter] Clean up subscript thunk generation code.
I'm not sure this code is even still necessary, but while we're still
using it we can at least not pretend we're still using it for properties.

No functionality change.

Swift SVN r26480
2015-03-24 03:36:47 +00:00
Dmitri Hrybenko
ab408d4dc3 Update the compiler and SDK overlay for nullability and generics in Foundation
We have an SPI between the Swift compiler and Foundation based on the
SWIFT_SDK_OVERLAY_FOUNDATION_EPOCH preprocessor macro that allows us to
request the new API.  rdar://20270080 tracks removing it.

Swift SVN r26475
2015-03-24 02:18:06 +00:00
Jordan Rose
f74bc7122c Split getAccessibility() into getFormalAccess() and getEffectiveAccess().
Currently a no-op, but effective access for entities within the current
module will soon need to take testability into account. This declaration:

  internal func foo() {}

has a formal access of 'internal', but an effective access of 'public' if
we're in a testable mode.

Part of rdar://problem/17732115 (testability)

Swift SVN r26472
2015-03-24 02:16:58 +00:00
Doug Gregor
7708c5a65e Start moving away from (Nominal)?TypeDecl::getProtocols().
Instead, use other entry points, particularly those that use the conformance lookup table.

Swift SVN r26412
2015-03-22 12:35:21 +00:00
Doug Gregor
3f6a14ade6 Eliminate NominalTypeDecl::(get|set)Conformances.
We now access the conformances of a nominal type through the
conformance lookup table, so there is no reason to continue storing
conformances directly on the nominal type declaration, which was
error-prone regardless. This mirrors the change to ExtensionDecl from
my previous commit.

Swift SVN r26354
2015-03-20 16:32:25 +00:00
Doug Gregor
9bd774fd57 Eliminate ExtensionDecl::(get|set|)Conformances.
Stop storing a conformances array on ExtensionDecls. Instead, always use the conformance lookup table to retrieve conformances (which is lazy and supports multi-file, among other benefits).

As part of this, space-optimize ExtensionDecl's handling of conformance loaders. When one registers a conformance loader, it goes into a DenseMap on ASTContext and gets erased once we've loaded that data, so we get two words worth of space back in each ExtensionDecl.

Swift SVN r26353
2015-03-20 16:32:21 +00:00
Doug Gregor
dc27688eca Generalize the importer-only RawOptionSet attribute to a SynthesizedProtocol attribute.
This lets us tag imported declarations with arbitrary synthesized
protocols. Use it to handle imported raw option sets as well as the
RawRepresentable conformances of enums that come in as structs.

Swift SVN r26298
2015-03-19 06:35:25 +00:00
Jordan Rose
edf3bb460d [ClangImporter] Ignore deprecated enum constants when computing prefixes.
This fixes the import of enums like NSCalendarUnit, which changed from
NSXXXCalendarUnit to NSCalendarUnitXXX, as has been the guideline in
recent years. Now even when the old names are present, we can still
prefix-strip based on the new names. If /all/ options are deprecated,
though, we'll prefix-strip as we did before.

Note that we /don't/ check the current deployment target for this,
because we want to use the "nice" names as soon as we have an SDK where
they're available, not when the deployment target matches such an SDK.

rdar://problem/17686122

Swift SVN r26184
2015-03-16 18:01:45 +00:00
Chris Lattner
8521916b86 change PatternBindingDecl to be created with a static "create" method instead
of using its ctor directly.  NFC, this is in prep for other changes coming.


Swift SVN r26174
2015-03-16 00:44:52 +00:00
Chris Lattner
20f8f09ea8 Land: <rdar://problem/19382905> improve 'if let' to support refutable patterns and untie it from optionals
This changes 'if let' conditions to take general refutable patterns, instead of
taking a irrefutable pattern and implicitly matching against an optional.

Where before you might have written:
  if let x = foo() {

you now need to write:
  if let x? = foo() {
    
The upshot of this is that you can write anything in an 'if let' that you can
write in a 'case let' in a switch statement, which is pretty general.

To aid with migration, this special cases certain really common patterns like
the above (and any other irrefutable cases, like "if let (a,b) = foo()", and
tells you where to insert the ?.  It also special cases type annotations like
"if let x : AnyObject = " since they are no longer allowed.

For transitional purposes, I have intentionally downgraded the most common
diagnostic into a warning instead of an error.  This means that you'll get:

t.swift:26:10: warning: condition requires a refutable pattern match; did you mean to match an optional?
if let a = f() {
       ^
        ?

I think this is important to stage in, because this is a pretty significant
source breaking change and not everyone internally may want to deal with it
at the same time.  I filed 20166013 to remember to upgrade this to an error.

In addition to being a nice user feature, this is a nice cleanup of the guts
of the compiler, since it eliminates the "isConditional()" bit from
PatternBindingDecl, along with the special case logic in the compiler to handle
it (which variously added and removed Optional around these things).




Swift SVN r26150
2015-03-15 07:06:22 +00:00
Doug Gregor
3e4632e4d6 Reinstate "Centralize the logic for synthesized conformances.""
This reinstates r26115 along with a small fix to the synthesization of
witnesses (an existing bug exposed by this change).

Swift SVN r26146
2015-03-15 04:15:36 +00:00
Erik Eckstein
fe84d94938 Revert "Centralize the logic for synthesized conformances."
It causes some fails in compiler_crashers:

    Swift :: compiler_crashers/0986-swift-unboundgenerictype-get.swift
    Swift :: compiler_crashers/1103-swift-unboundgenerictype-get.swift
    Swift :: compiler_crashers/1223-swift-lexer-leximpl.swift
    Swift :: compiler_crashers/1276-swift-metatypetype-get.swift
    Swift :: compiler_crashers/1287-swift-printingdiagnosticconsumer-handlediagnostic.swift



Swift SVN r26136
2015-03-14 13:00:13 +00:00
Doug Gregor
78892d78c0 Centralize the logic for synthesized conformances.
This is effectively NFC, but we had two implementations of "figure out
the protocols that this type should implicitly conform to". The one in
the conformance table is what will matter going forward.

Swift SVN r26115
2015-03-13 23:37:21 +00:00
Doug Gregor
746141dc64 Introduce a __raw_option_set attribute that the Clang importer adds for option sets.
Effectively NFC; this is part of teaching the new conformance registry
about all synthesized conformances.

Swift SVN r26113
2015-03-13 23:37:12 +00:00
Joe Groff
b5b65b83e9 Remove the -enable-union-import staging flag.
Swift SVN r25809
2015-03-06 23:08:11 +00:00
Joe Groff
c112d6fa4c Clang importer: Preserve the delayed protocol conformance behavior in playground mode.
The fix for rdar://problem/19924834 introduced a 10% performance hit when importing Foundation. Playgrounds are performance-sensitive, and ought to be able to keep working without the fix, because they're never multi-file and it's not yet possible to dynamically access an Equatable or RawRepresentable conformance using 'is' or 'as'. Preserve the old behavior in playground mode, until we have time to recover the performance hit in a more principled way (covered by rdar://problem/20047340).

Swift SVN r25772
2015-03-05 00:49:24 +00:00
Joe Groff
6bdedc769f Clang importer: Don't delay the protocol conformances of imported enums.
Fixes rdar://problem/19924834, which exposes a case where delayed protocols cause an imported enum's Equatabe protocol conformance to get instantiated too late, if the enum is imported by one file that doesn't use the Equatable conformance, and a subsequent file in the same invocation then uses the conformance. Jordan notes that delaying these conformances is no longer desirable, now that we dynamically detect conformances.

Swift SVN r25741
2015-03-04 04:48:59 +00:00
Jordan Rose
cee28189a2 Add a BodyKind for implicitly-synthesized memberwise initializers.
...rather than just assuming any initializer without a body that makes it
to SILGen is a memberwise initializer.

In the long term we want SILGen to stop handling these initializers, at
which point we can see if it makes sense to remove this body kind.

No intended functionality change.

Swift SVN r25723
2015-03-03 23:22:21 +00:00
Jordan Rose
b1623e5e94 [ClangImporter] Skip setters in protocols if there's a readonly property.
This is a workaround for us saying that the setter generated for a property
conflicts with the setter-method explicitly declared in the Objective-C
protocol. (After all, they do have the same name.) If we really want to
support this, we need something like "var foo { get optional set }", which
our model doesn't really support right now. But we should at least allow
the user's code to build.

rdar://problem/19933285

Swift SVN r25634
2015-02-28 02:49:49 +00:00
Doug Gregor
bce5c20c25 Teach loadAllMembers() implementations to add the members themselves.
The contract for LazyResolver::loadAllMembers() was that the caller
would handle actually adding the members, since it was an iterable
declaration context and could centralize that (simple) logic. However,
this fails in the Clang importer in rare but amusing ways when some of
the deferred actions (e.g., finishing a protocol conformance) depend
on having the members already set. The deferred action occurs after
the member list is complete in ClangImporter's loadAllMembers(), but
before its caller actual set the member list, leaving incomplete
conformances. Fixes rdar://problem/18884272.

Swift SVN r25630
2015-02-28 01:03:41 +00:00
Joe Groff
ff39b971e2 ClangImporter: Import getters for macros as transparent functions.
This ensures we don't leave references to Clang-importer-generated symbols in overlays, working around rdar://problem/19925662, and seems like a good idea regardless.

Swift SVN r25582
2015-02-27 01:17:23 +00:00
Jordan Rose
7a6d8ea940 Revert "[ClangImporter] Add convert-inits for enums defined in terms of other enums."
This reverts r25401. After reviewing the issues this was intended to solve,
and then talking to Dave, I've decided that this doesn't actually solve
enough of the problems we wanted it to, and it creates added complexity,
so I'm taking it back out.

Originally rdar://problem/19667625.

Swift SVN r25489
2015-02-23 22:52:41 +00:00
Jordan Rose
5554cec143 [ClangImporter] Don't inherit initializers as designated...
...even if they were designated in the base class. (Unless they're required,
in which case they're still required.)

This led to Swift subclasses treating convenience initializers as
designated initializers, which (if synthesized) led to properties being
initialized twice.

rdar://problem/19730160

Swift SVN r25410
2015-02-20 02:26:55 +00:00