Commit Graph

1616 Commits

Author SHA1 Message Date
Doug Gregor
5c2fe3496f Merge pull request #7740 from huonw/parse-assoc-type-where
(Mostly) Type-check where clauses on associated types
2017-02-27 22:06:51 -08:00
Huon Wilson
84e0a109a2 [AST] Explicitly track the validation state of Decls.
Previously some decls (TypeAliasDecl and ExtensionDecl) had bits
explicitly marking whether they've been validated, while other decls
just deduced this from hasInterfaceType. The doing the latter doesn't
work when the interface type can be computed before doing full
validation (such as protocols and associatedtypes, which have trivial
interface types), and so an explicit bit is adopted for all decls.
2017-02-24 19:21:33 -08:00
Jordan Rose
ee0dd49bd7 [ClangImporter] Use the current version to vend enum constant names.
The compiler itself no longer uses this API but the debugger does,
in order to pretty-print option sets.

The normal way to test this would be to add an LLDB-side test that
uses a framework with versioned API notes. Unfortunately I can't
think of a straightforward way to test it Swift-side.
2017-02-24 16:11:33 -08:00
Jordan Rose
c402030877 [ClangImporter] Give compatibility typealiases the correct version.
Unlike values, we can't import multiple copies of types under
different names and get good results. Instead, we make a typealias
that points back to the original type. Make sure this typealias is
flagged with whatever version is appropriate, rather than always using
"Swift 2".
2017-02-24 16:11:33 -08:00
Jordan Rose
79ed26f575 [ClangImporter] Use the correct name for replacement decls.
When a C declaration is marked unavailable with a replacement, we look
for the replacement to see how it would be imported into Swift. Make
sure we do that with respect to the active language version.
2017-02-24 16:11:33 -08:00
Jordan Rose
b9853c209e [ClangImporter] Fix marking of protocols with missing requirements.
This doesn't actually have any effect yet, but if we start importing
both Swift 3 and Swift 4 versions of protocol requirements and the
non-active one is unavailable, we might mistakenly mark the protocol
un-implementable even when the requirements that are needed are all
there. (Hopefully we would never make a protocol /less/ available in a
newer release, of course.) The test case is designed to catch that.
2017-02-24 16:11:33 -08:00
Jordan Rose
c9124d989d [ClangImporter] Import Swift 3 versions of top-level decls in Swift 4.
...and Swift 4 versions in Swift 3, and Swift 2 and "raw" versions in
both. This allows the compiler to produce sensible errors and fix-its
when someone uses the "wrong" name for an API. The diagnostics
certainly have room to improve, but at least the essentials are there.

Note that this commit only addresses /top-level/ decls, i.e. those
found by lookup into a module. We're still limited to producing all
members of a nominal type up front, so that'll require a slightly
different approach.

Part of rdar://problem/29170671
2017-02-24 14:01:10 -08:00
Slava Pestov
7133d92a41 ClangImporter: Subscripts in generic contexts should have a GenericFunctionType 2017-02-21 23:52:13 -08:00
Jordan Rose
e6a85f6602 [ClangImporter] Resolve forward declarations before importing names. (#7555)
This allows a previously-working case of Objective-C forward-declaring
a type in a /different/ Swift module to continue working, as long as
the Swift context being compiled manages to import the other module
properly (including its generated header). This isn't really our
recommended pattern---that would be to @import the module in the
bridging header and forego the forward declaration---but it doesn't
cost much to keep it working. It's also a place where textual and
precompiled bridging headers behaved differently, because precompiled
ones are processed much earlier.

https://bugs.swift.org/browse/SR-3798
2017-02-20 13:24:03 -08:00
Doug Gregor
042e6510c3 [AST] Drop ProtocolDecl's "inherited protocols" list.
The list of directly inherited protocols of a ProtocolDecl is already
encoded in the requirement signature, as conformance constraints where
the subject is Self. Gather the list from there rather than separately
computing/storing the list of "inherited protocols".
2017-02-20 09:41:00 -08:00
Slava Pestov
880803aaba AST: Initial plumbing for generic subscripts 2017-02-19 21:34:26 -08:00
David Farler
3645736ac0 Merge pull request #7393 from bitjammer/syntax-tree
Start the Syntax structured editing library
2017-02-17 15:26:00 -08:00
David Farler
431b7ff2af [Syntax] Add Equal '=' token location to TypeAliasDecl
Needed for full-fidelity structured editing.
2017-02-17 12:57:04 -08:00
Jordan Rose
420f5057af [ClangImporter] "Failing to import" a nested type is okay. (#7544)
Specifically, a forward-declaration of one struct inside another.
This isn't a field, so it doesn't affect whether or not the struct
has addressable storage, nor whether it should get a memberwise
initializer.

This change matches Swift 3.0 behavior. I'm not exactly sure why,
because as far as I can tell Swift 3.0 should have also been leaving
out the memberwise initializer. But it doesn't appear to have been
doing so, and including it is more correct anyway.

rdar://problem/30449400
2017-02-16 17:13:35 -08:00
Slava Pestov
41eba98902 Gardening: Fix some unused variable warnings in no-assert builds 2017-02-15 12:57:35 -08:00
Jordan Rose
385da9dc19 [ClangImporter] Don't crash when an enum case alias has no name. (#7483)
Or rather, when the name importer decides that the name it /would/
have should start with a number, and gives up. We should probably
fix that separately, but meanwhile don't crash.

> Roses are red
> Prefix-stripping can create an invalid remainder
> assert(!member->NextDecl &&
> "Already added to a container")

rdar://problem/30401506
2017-02-15 10:46:57 -08:00
Hugh Bellamy
f001b7562b Use relatively new LLVM_FALLLTHROUGH instead of our own SWIFT_FALLTHROUGH 2017-02-12 10:47:03 +07:00
Doug Gregor
579af863c5 Rename ArchetypeBuilder -> GenericSignatureBuilder 2017-02-10 12:46:34 -08:00
Doug Gregor
2307e15290 [Clang importer] Compute the requirement signature of imported protocols.
We can also avoid walking the members of said protocols in the
archetype builder and when looking for nested types, because of course
there are no associated types in imported Objective-C protocols.
2017-02-09 23:50:16 -08:00
Doug Gregor
def14bfb70 [Archetype builder] Move checking for recursive constraints to finalize().
Rather than waiting until we try to form a contextual type to diagnose
recursion, perform the check while finalizing the archetype builder
itself.
2017-02-06 22:58:44 -08:00
Doug Gregor
4d7d40c14c Switch some clients over to GenericSignature::createGenericEnvironment().
These are the known-to-be-well-formed clients.
2017-02-05 21:23:44 -08:00
Slava Pestov
dca292c652 Serialization: Don't serialize contextual enum argument type
Storing this separately is unnecessary since we already
serialize the enum element's interface type. Also, this
eliminates one of the few remaining cases where we serialize
archetypes during AST serialization.
2017-01-30 00:08:53 -08:00
Jordan Rose
1cf1961fc7 Merge pull request #7007 from jrose-apple/accessor-argument-labels
[Importer] Preserve argument labels even for accessors.
2017-01-27 11:18:44 -08:00
Jordan Rose
6fed3d1edf Merge pull request #6990 from jrose-apple/available-is-better-than-unavailable
[ClangImporter] Prefer available enum elements over unavailable ones.
2017-01-26 11:52:36 -08:00
Jordan Rose
fdbc84f7ec [Importer] Preserve argument labels even for accessors.
The AST verifier is unhappy when an accessor's imported name gets
selector-split but its parameters don't have that recorded. Although
we're not using this for anything today, it seems best to keep the
two in sync.

rdar://problem/29889051
2017-01-25 13:44:25 -08:00
Slava Pestov
c206f629e7 Merge pull request #6678 from karwa/one-plus-two
[ClangImporter] Teach the importer about a couple more kinds macro constants
2017-01-24 19:04:38 -08:00
Jordan Rose
3411fc380e [ClangImporter] Prefer available enum elements over unavailable ones.
...and avoid making aliases from one unavailable declaration to another.
If it's unavailable, we can just import it as a normal case and not
worry about it. This fixes an issue where Sema would try to diagnose
the body of an "alias" for referring to unavailable declarations.

(Background: enum cases in Swift have to have unique values, so we
import any duplicate values as static properties. Pattern matching
logic has a hack to recognize these particular static properties as
being "case-like".)

This commit also sinks enum element uniqueness checking into importing
the enum, instead of keeping a global map we never consult again. This
should save a small bit of memory.

rdar://problem/30025723
2017-01-23 15:34:20 -08:00
SpringsUp
fa834e2f80 [ClangImporter] Teach the importer about more infix operators between
integer constants, and to always look through macro definitions for them.

Also, logical comparisons now return a Boolean.

New operations: +, -, *, /, ^, >>, ==, >, >=, <, <=
2017-01-23 21:02:47 +01:00
Florent Bruneau
b6b63369e1 ClangImporter: use nameless arguments for anonymous struct/unions in constructors.
Following a13c134521, constructors of structures/unions containing
anonymous structures/unions fields include those field in their parameter
list, using the generated field name as parameter name:

 typedef struct foo_t {
     union {
         int a;
         int b;
     };
 } foo_t;

Generates:

 struct foo_t {
     init(__Anonymous_field0: foo_t.__Unnamed_union__Anonymous_field0)
 }

 let foo = foo_t(__Anonymous_field0: .init(a: 1))

One important downside here is that the generated field name get exposed
in the API.

An idealistic approach would be to generate the constructors that expose
the fields indirectly inherited from those structures:

 struct foo_t {
     init(a: Int32)
     init(b: Int32)
 }

However, this approach requires the generation of a constructor per valid
combination of indirect fields, which might start having a huge
cardinality when we have nested anonymous structures in nested anonymous
unions...

 typedef struct bar_t {
     union {
         struct {
             int a;
             int b;
         };
         struct {
             int c;
             int d;
         };
     };
     union {
         int e;
         int f;
     };
 } bar_t;

In this examples, we have 4 constructors to generates, for (a, b, e), (a,
b, f), (c, d, e) and (c, d, f).

The proposed approach is to use a nameless parameter for anonymous
structures/unions, still forcing the user to build that sub-object by
hand, but without exposing the generated field name. This is very similar
to what can be done in C:

 foo_t foo = { { .a = 1 } };
 let foo = foo_t(.init(a: 1))

Or

 bar_t bar = { { { .a = 1, .b = 2 } }, { .e = 1 } };
 let bar = bar_t(.init(.init(a: 1, b: 2)), .init(e: 1))

Signed-off-by: Florent Bruneau <florent.bruneau@intersec.com>
2017-01-23 20:11:47 +01:00
practicalswift
a9d6d8938c [gardening] Fix recently introduced typos 2017-01-22 20:40:45 +01:00
swift-ci
41539284eb Merge pull request #6924 from graydon/rdar-28815071-fixit-to-narrow-availability-check 2017-01-20 01:22:28 -08:00
Slava Pestov
c86b5ae427 AST: Header file gardening - include what you use 2017-01-19 20:07:06 -08:00
Graydon Hoare
d94b76f396 Suggest narrowing an exising availability context, when feasible. 2017-01-19 16:29:16 -08:00
Doug Gregor
6c4e2af22a Merge pull request #6892 from DougGregor/property-as-accessors-independent
[Clang importer] When importing a property as accessors, use accessor types
2017-01-18 11:16:13 -08:00
Doug Gregor
609f9b5a84 [Clang importer] When importing a property as accessors, use accessor types.
When importing a property as accessor methods (rather than as a
property), we were still importing the type of the accessor methods as
if they were Swift getters and setters of a property, which
(necessarily) homogenizes the types. The homogenization is unnecessary
when importing as accessor methods, because the methods are
independent, so just import the accessor method types as if the
property did not exist. This is particularly useful for maintaining
Swift 3 source compatibility for cases where Swift 4 turns a
getter/setter pair into a null_resettable property.

Fixes rdar://problem/30075571.
2017-01-18 10:02:57 -08:00
Bob Wilson
34514513fd Merge remote-tracking branch 'origin/master' into master-next 2017-01-15 17:34:17 -08:00
Florent Bruneau
6ff926511e ClangImporter: fix crash when importing type containing bitfields.
Following PR #6531 there is a position mismatch in the final loop between
the position of the member in the members arrays and the position in the
valueParameters array.

As a consequence, a structure containing indirect fields before a computed
properties (like a bitfield) caused an invalid access in the
valueParameters array resulting in a crash of the compiler.

This patch maintains a separate position for accessing valueParameters. A
non-regression test is also added.

Signed-off-by: Florent Bruneau <florent.bruneau@intersec.com>
2017-01-14 18:39:21 +01:00
Bob Wilson
c765d5e3a5 Merge remote-tracking branch 'origin/master' into master-next 2017-01-12 15:58:19 -08:00
Slava Pestov
d1b7b3769e ClangImporter: Special-case class named OS_os_log for factory initializer treatment
This is horrible hack, see this commit for the backstory:

<c98ce0c770>.

Fixes <rdar://problem/29530506>.
2017-01-11 20:18:35 -08:00
Doug Gregor
2a3817f434 Merge pull request #6722 from DougGregor/archetype-builder-without-module
[Archetype builder] Use a LookupConformanceFn to resolve protocol conformances
2017-01-10 19:44:28 -08:00
Doug Gregor
ac5e74601b [Archetype builder] Use a LookupConformanceFn to resolve protocol conformances.
Instead of creating an archetype builder with a module---which was
only used for protocol conformance lookups of concrete types
anyway---create it with a LookupConformanceFn. This is NFC for now,
but moves us closer to making archetype builders more canonicalizable
and reusable.
2017-01-10 16:40:38 -08:00
Jordan Rose
33ed767933 [ClangImporter] Preserve the names of imported ObjC properties. (#6182)
This is necessary for proper working of #keyPath, as well as improving
the experience of PrintAsObjC.

rdar://problem/28543037
2017-01-10 13:37:12 -08:00
Bob Wilson
cf3a0458f2 Merge remote-tracking branch 'origin/master' into master-next 2017-01-10 09:05:23 -08:00
Doug Gregor
2302f59288 Merge pull request #6531 from Fruneau/indirect-fields
Clang Importer: import all indirect fields.
2017-01-09 15:01:02 -08:00
Brian Gesiak
a9439bb242 [ClangImporter] 'returns_twice' funcs unavailable
Resolves https://bugs.swift.org/browse/SR-2394.

The 'returns_twice' attribute is used to denote a function that may return more
than one time. Examples include `vfork` and `setjmp`. The Swift
compiler, however, cannot ensure definitive initialization when
functions such as these are used.

Mark 'returns_twice' functions as unavailable in Swift.

In turn, this removes the need to explicitly mark `vfork` as unavailable on
Darwin platforms, since it is now unavailable everywhere.

For code that relies upon `vfork`, `setjmp`, or other 'returns_twice'
functions, this is a backwards-incompatible, source-breaking change.
2017-01-08 21:41:08 -05:00
Bob Wilson
37e7d1c627 Merge remote-tracking branch 'origin/master' into master-next 2017-01-08 17:07:46 -08:00
Brian Gesiak
663b92ece9 [AST] Completely replace Module with ModuleDecl
The typedef `swift::Module` was a temporary solution that allowed
`swift::Module` to be renamed to `swift::ModuleDecl` without requiring
every single callsite to be modified.

Modify all the callsites, and get rid of the typedef.
2017-01-08 00:36:08 -05:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Robert Widmann
96f2a04f55 Merge pull request #6490 from modocache/ast
[SR-2757][Sema] Mark VarDecl in capture lists
2017-01-05 21:36:16 -07:00
Bob Wilson
4ca0676a34 Merge remote-tracking branch 'origin/master' into master-next 2017-01-05 17:11:16 -08:00