Commit Graph

767 Commits

Author SHA1 Message Date
Jordan Rose
ba8d1a5656 [ClangImporter] Ban a few deprecated methods of NSDocument.
...so that their modern NSError-based variants won't be imported using an
extra "error: ()" parameter. Apart from looking prettier, this avoids a
crash when overriding the "error: ()" versions, rdar://problem/21144509.

Once NS_REFINED_IN_SWIFT has been implemented we can probably use that instead.
Filed rdar://problem/21192039 to remove the hack at that point.

rdar://problem/21177341

Swift SVN r29212
2015-06-01 23:04:01 +00:00
Dave Abrahams
d65f696344 Kill off [_]RawOptionSetType
Now that we are using OptionSetType for option sets, all the support for
doing things the old way can die.

Note: the fix-it that used to apply to RawOptionSetType, it seemed to me,
should still apply to OptionSetType, so I switched it over instead of
removing it.

Swift SVN r29066
2015-05-27 15:55:54 +00:00
Jordan Rose
cb2ca7d997 [ClangImporter] Remap factory methods according to the swift_name attr.
On a factory method, swift_name can have two effects:

- If the custom name has a base name of "init", import the method as an
  initializer, even if it doesn't follow the usual naming conventions.
- Otherwise, import the method as a method, even if it /would have/ been
  imported as an initializer.

There's a bit of trickiness around NSError**: currently you have to specify
the name of the error parameter on the Clang side even if it's going to be
deleted on the Swift side. We may want to change this later.

The test cases here exposed the issues in the previous two commits,
so this effectively depends on those for passing tests.

More of rdar://problem/19240897.

Swift SVN r28979
2015-05-24 01:48:24 +00:00
Jordan Rose
5db7e8591f [ClangImporter] Don't use 'Self?' for a throwing method.
We have special logic to handle instancetype returns, but that hadn't
been updated for error handling.

Tested in next commit.

Swift SVN r28978
2015-05-24 01:48:21 +00:00
Jordan Rose
b92e0c944d [ClangImporter] Implement NS_SWIFT_NAME for enumerators.
NS_SWIFT_NAME on enum constants has two effects: on top of renaming the
member, it also removes it from the prefix-matching logic.

Part of rdar://problem/19240897

Swift SVN r28927
2015-05-22 20:15:09 +00:00
Joe Groff
d1b6fa32c4 Revert "Revert "[stdlib] Land OptionSetType et. al.""
This recommits r28892, r28894, and r28895; the previous commits should have addressed the previous breakage.

Swift SVN r28905
2015-05-22 05:47:29 +00:00
Dave Abrahams
21b9a97e88 Revert "[stdlib] Land OptionSetType et. al."
This reverts commit r28892, r28894, and r28895.

They broke validation tests; JoeG is going to look at what's needed to
make them work again.

Swift SVN r28897
2015-05-22 00:13:53 +00:00
Dave Abrahams
ad7f7c6779 [stdlib] Land OptionSetType et. al.
This has passed review, or at least satisfied Tony Parker, provided we
do something to hide SetAlgebraDispatchType.  I think I can eliminate it
in an imminent commit.

Swift SVN r28892
2015-05-21 22:55:02 +00:00
Jordan Rose
fa5bd4c6c8 [ClangImporter] Allow apinotes to affect inherited initializers.
Then use that to ban NSError.init(), because it doesn't create a valid
NSError. In the long run Foundation will hopefully add this to their
headers, but they can't yet (rdar://problem/19977891).

rdar://problem/21042412

Swift SVN r28881
2015-05-21 18:11:17 +00:00
Dmitri Hrybenko
ea17483633 Add CMake options and #ifs to hide tvOS
Swift SVN r28752
2015-05-19 05:15:52 +00:00
Devin Coughlin
4b23d4a219 Update clang importer and target platform detection for watchOS.
For the moment, we do not consider APIs deprecated earlier than watchOS 2.0 as
unavailable. rdar://problem/20948019 track changing this once the ultimate
decision on this policy has been made.

This addresses the compile-time components of rdar://problem/20774229

Swift SVN r28559
2015-05-14 04:20:43 +00:00
Joe Groff
b1a965fd1e Clang Importer: Import struct elementwise constructors as transparent.
We need to ensure they get inlined away if they're referenced from other transparent definitions, as a workaround for SIL deserialization being unable to trigger instantiation of Clang-importer-synthesized modules. Still doesn't solve that problem, but works around it enough for rdar://problem/20902115.

Swift SVN r28526
2015-05-13 20:53:26 +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
340e4d8f8a Simplify parsing and representation of extension declarations.
Now that we don't have generic parameter lists at arbitrary positions
within the extended type of an extension declaration, simplify the
representation of the extended type down to a TypeLoc along with a
(compiler-synthesized) generic parameter list.

On the parsing side, just parse a type for the extended type, rather
than having a special grammar. We still reject anything that is not a
nominal type (of course), but it's simpler just to call it a type.

As a drive-by, fix the crasher when extending a type with module
qualification, rdar://problem/20900870.

Swift SVN r28469
2015-05-12 16:26:13 +00:00
Jordan Rose
46b52576d3 Recognize imported enum case aliases in TypeCheckPattern.cpp.
...so that they can still be used with exhaustive switches.

This is a hack---groveling through the AST to see if it's in the particular
form of an imported enum case alias---but at least it's limited to imported
properties.

More rdar://problem/18662118

Swift SVN r28326
2015-05-08 21:01:52 +00:00
Doug Gregor
edbb75eef8 Eliminate the 'Module' variant from UnqualifiedLookupResult.
Make unqualified lookup always provide a declaration for the things it
finds, rather than providing either a module or a declaration. Unify
various code paths in our type checker now that module declarations
come in with the other declarations.

Swift SVN r28286
2015-05-07 21:10:55 +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
Joe Groff
73dfea0ba0 ClangImporter: Import option sets as conforming to OptionSetType.
This is pretty much a simplification of the existing RawOptionSetType logic; now, instead of generating a bunch of implicit decls, we provide the minimum set of declarations from which the stdlib will be able to generate default implementations of everything else. The new imported declaration looks like this:

struct MyOptions: OptionSetType {
  let rawValue: UInt // or whatever raw type
  init(rawValue: UInt)

  static var A: MyOptions { return MyOptions(rawValue: 1) }
  static var B: MyOptions { return MyOptions(rawValue: 2) }
  /* etc. */
}

Still hidden behind a staging flag, until the stdlib implementation can land.

Swift SVN r28213
2015-05-06 19:45:52 +00:00
Doug Gregor
de635a8cd9 Implement the 'warn_unused_result' attribute.
@warn_unused_result can be attached to function declarations to
produce a warning if the function is called but its result is not
used. It has two optional parameters that can be placed in
parentheses:

  message="some message": a message to include with the warning.

  mutable_variant="somedecl": the name of the mutable variant of the
  method that should be suggested when the subject method is called on
  a mutable value.

The specific use we're implementing this for now is for the mutating
and in-place operations. For example:

  @warn_unused_result(mutable_variant="sortInPlace") func sort() -> [Generator.Element] { ... }
  mutating func sortInPlace() { ... }

Translate Clang's __attribute__((warn_unused_result)) into
@warn_unused_result.

Implements rdar://problem/18165189.

Swift SVN r28019
2015-05-01 04:10:40 +00:00
Devin Coughlin
4f366b1ff6 Do not treat iOS as active on tvOS.
Change the active-platform availability logic to not consider iOS as active on
tvOS. We want all of the messiness of the fact that tvOS was branched
from iOS to be handled in clang, which "transcribes" iOS availability attributes
to their corresponding tvOS counterparts as long as there is not an
existing explicit tvOS availability attribute on the declaration.

This change exposed several places where I needed to add explicit handling of
of tvOS and where we will need to handle watchOS as well.
rdar://problem/20774229 tracks adding logic and tests to handle watchOS in these
places.

It is also unfortunately the case that llvm::triple returns true when isiOS()
is called on tvOS. This means that to test whether an llvm:triple target is
really iOS, we need to check for iOS then check explicitly that it is not
tvOS. We will eventually change llvm's behavior here so that the double
check is not needed.

Swift SVN r28013
2015-05-01 01:54:24 +00:00
John McCall
26b3f386e0 Fix a bug with importing inherited factory methods with
foreign-error conventions.

Swift SVN r28003
2015-04-30 22:34:41 +00:00
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