Commit Graph

1074 Commits

Author SHA1 Message Date
Chris Lattner
d03fc2c536 Prune some redundant #includes, noticed by inspection. 2015-12-27 20:55:01 -08:00
practicalswift
81e7439a9a Fix typos. 2015-12-23 11:16:34 +01:00
ken0nek
fcd8fcee91 Convert [Cc]an not -> [Cc]annot 2015-12-23 00:55:48 +09:00
practicalswift
36d7072013 Remove immediately adjacent repeated words ("the the", "for for", "an an", etc.). 2015-12-21 22:16:04 +01:00
David Zarzycki
6bb0fde66e Fix typo in ClassDecl::setForeign()
Found during source inspection.
2015-12-19 11:26:06 -05:00
Slava Pestov
d6ea5d8717 Sema: Chain all generic parameter lists
Previously, methods on DeclContext for getting generic parameters
and signatures did not walk up from type contexts to function
contexts, or function contexts to function contexts.

Presumably this is because SIL doesn't completely support nested
generics yet, instead only handling these two special cases:

- non-generic local function inside generic function
- generic method inside generic type

For local functions nested inside generic functions, SIL expects
the closure to not have an interface type or generic signature,
even if the contextual type signature contains archetypes.
This should probably be revisited some day.

Recall that these cases are explicitly rejected by Sema diagnostics
because they lack SIL support:

- generic function inside generic function
- generic type inside generic function

After the previous patches in this series, it becomes possible to
construct types that are the same as before for the supported uses of
nested generics, while introducing a more self-consistent conceptual
model for the unsupported cases.

Some new tests show we generate diagnotics in various cases that
used to crash.

The conceptual model might still not be completely right, and of
course SIL, IRGen and runtime support is still missing.
2015-12-16 11:32:56 -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
Slava Pestov
c258f991f6 Sema: Nuke NominalTypeDecl::markInvalidGenericSignature()
This would just set the NominalTypeDecl's declared type to
ErrorType, which caused problems elsewhere.

Instead, generalize the logic used for AbstractFunctionDecl.
This correctly wires up the GenericTypeParamDecl's archetypes even
if the signature didn't validate, fixing crashes if the generic
parameters of the type are referenced.
2015-12-14 13:29:55 -08:00
Slava Pestov
dfbb580de3 AST: Store the GenericSignature in the AbstractFunctionDecl, NFC
For better or worse, the type of a function can end up as ErrorType,
and the generic signature was not stored anywhere else, causing
crashes from orphaned generic type parameters.

This patch is the first in a series to make this more robust by
storing the generic signature before the interface type is computed.
2015-12-14 13:29:52 -08:00
Roman Levenstein
3a4184dad9 Extend a few lookup APIs to use AbstractFunctionDecl instead of FuncDecl. NFC.
This is required for upcoming changes in the devirtualizer.
2015-12-14 10:11:46 -08:00
Dmitri Gribenko
a50b8cd659 Merge pull request #510 from practicalswift/fix-typos-14
Fix typos (14 of 30)
2015-12-14 01:07:49 -08:00
practicalswift
a1e9ebe408 Fix typo: homogenous → homogeneous 2015-12-14 00:11:51 +01:00
practicalswift
473af12679 Fix typo: approproiate → appropriate 2015-12-14 00:11:13 +01:00
Brent Royal-Gordon
072d1e91a2 Fix grammatical error in comment
It looks like someone started to rephrase this but didn't finish.
2015-12-07 18:59:45 -08:00
Brent Royal-Gordon
8c32020608 Fix inaccurate comment on parameter
It was marked as being IsState, but the actual field is called IsStatic.
2015-12-07 18:57:29 -08:00
Robert Widmann
9b68f5f6e3 Bump decl bits 2015-12-05 16:05:15 -05:00
Robert Widmann
11cce3bcdc Diagnose circular type aliases in protocol declarations 2015-12-05 16:05:15 -05:00
Slava Pestov
57dd686742 Strawman @fixed_layout attribute and -{enable,disable}-resilience flags
A fixed layout type is one about which the compiler is allowed to
make certain assumptions across resilience domains. The assumptions
will be documented elsewhere, but for the purposes of this patch
series, they will include:

- the size of the type
- offsets of stored properties
- whether accessed properties are stored or computed

When -enable-resilience is passed to the frontend, all types become
resilient unless annotated with the @fixed_layout attribute.

So far, the @fixed_layout attribute only comes into play in SIL type
lowering of structs and enums, which now become address-only unless
they are @fixed_layout. For now, @fixed_layout is also allowed on
classes, but has no effect. In the future, support for less resilient
type lowering within a single resilience domain will be added, with
appropriate loads and stores in function prologs and epilogs.

Resilience is not enabled by default, which gives all types fixed
layout and matches the behavior of the compiler today. Since
we do not want the -enable-resilience flag to change the behavior
of existing compiled modules, only the currently-compiling module,
Sema adds the @fixed_layout flag to all declarations when the flag
is off. To reduce the size of .swiftmodule files, this could become
a flag on the module itself in the future.

The reasoning behind this is that the usual case is building
applications and private frameworks, where there is no need to make
anything resilient.

For the standard library, we can start out with resilience disabled,
while perfoming an audit adding @fixed_layout annotations in the
right places. Once the implementation is robust enough we can then
build the standard library with resilience enabled.
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
5d99dc9bb8 Strawman @fixed_layout attribute and -{enable,disable}-resilience flags
A fixed layout type is one about which the compiler is allowed to
make certain assumptions across resilience domains. The assumptions
will be documented elsewhere, but for the purposes of this patch
series, they will include:

- the size of the type
- offsets of stored properties
- whether accessed properties are stored or computed

When -enable-resilience is passed to the frontend, all types become
resilient unless annotated with the @fixed_layout attribute.

So far, the @fixed_layout attribute only comes into play in SIL type
lowering of structs and enums, which now become address-only unless
they are @fixed_layout. For now, @fixed_layout is also allowed on
classes, but has no effect. In the future, support for less resilient
type lowering within a single resilience domain will be added, with
appropriate loads and stores in function prologs and epilogs.

Resilience is not enabled by default, which gives all types fixed
layout and matches the behavior of the compiler today. Since
we do not want the -enable-resilience flag to change the behavior
of existing compiled modules, only the currently-compiling module,
Sema adds the @fixed_layout flag to all declarations when the flag
is off. To reduce the size of .swiftmodule files, this could become
a flag on the module itself in the future.

The reasoning behind this is that the usual case is building
applications and private frameworks, where there is no need to make
anything resilient.

For the standard library, we can start out with resilience disabled,
while perfoming an audit adding @fixed_layout annotations in the
right places. Once the implementation is robust enough we can then
build the standard library with resilience enabled.
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
David Farler
93b6962478 Warn when using 'var' bindings in function parameters
These will no longer be allowed in a future Swift release.

rdar://problem/23172698
2015-11-03 17:24:20 -08:00
Doug Gregor
72a2969224 Iterative type checker: handle the raw type of an enum
Swift SVN r32560
2015-10-09 17:18:38 +00:00
Doug Gregor
2feed84c91 Sketch out the interface to an iterative, lazy type checker.
This is all effectively NFC, but lays out the shape of the iterative
type checker: requests are packaged up in TypeCheckRequest, we can
check whether the request has been satisfied already (isSatisfied),
enumerate its dependencies (enumerateDependenciesOf) in terms of other
TypeCheckRequests, and satisfy a request (satisfy).

Lazily-computed semantic information is captured directly in the
AST, but has been set aside in its own structure to allow us to
experiment with moving it into a lookaside table.

The only request that exists now is to type-check the superclass of
the given class. It currently performs unhealthy recursion into the
existing type checker. As we detangle dependencies, this recursion
between the IterativeTypeChecker and the TypeChecker can go away.

Swift SVN r32558
2015-10-09 17:18:36 +00:00
Doug Gregor
6af6048c0c AST printing: take more care to only escape 'Self' when needed.
Cleans up AST printing somewhat as well as providing slightly better
type-to-declaration mappings for annotated AST printing and indexing.

Swift SVN r32420
2015-10-03 05:13:52 +00:00
Doug Gregor
eea1911fde Split GenericSignature out into its own header. NFC
Swift SVN r32278
2015-09-28 18:13:44 +00:00
Slava Pestov
a0609ae51a Fix typos
Swift SVN r32158
2015-09-22 21:08:25 +00:00
Slava Pestov
33feabb504 SIL: Hack in getLoweredASTFunctionType() for bitfield accessors
Bitfield accessors are generated by Clang, but have a curried function
type Self -> * -> *. This isn't supported for ClangType AbstractionPatterns,
so just special case lowering these since they're so simple.

NFC until bitfields land.

Swift SVN r31764
2015-09-08 06:26:37 +00:00
Ben Langmuir
47026609b8 Fix leak of std::function in NominalTypeDecl::DelayedMembers
We were memcopying a std::function into the the AST context memory,
which leaks memory incidentally used by the std::function
implementation.  Fix by using a std::unique_ptr and registering a
destructor cleanup.  Incidentally, I turned the array of functions into
a single function, since we never have more than one anyway.

rdar://problem/22387897

Swift SVN r31600
2015-09-01 16:31:21 +00:00
David Farler
e21e1c40e4 Import fields for named C unions
Create getters and setters for, and initializers taking, fields in
C unions. This doesn't yet fold anonymous unions' fields nested into
a struct, but it does open up APIs that were previously unavailable.

rdar://problem/19660119

Swift SVN r31396
2015-08-21 22:10:17 +00:00
Doug Gregor
00040112cd Eliminate special handling of deserialized inherited protocols.
Now that we have the inheritance lists hanging around, use them: it
makes the conformance lookup table use the same code whether we're
deserializing the conformances or parsing them.

Swift SVN r31383
2015-08-21 17:51:26 +00:00
Doug Gregor
cab320296d Stop recording protocol lists in nominal types.
The conformance lookup table is responsible for answering queries
about the protocols to which a particular nominal type conforms, so
stop storing (redundant and incorrect) protocol lists on the ASTs for
nominal types. Protocol types still store the list of protocols that
they inherit, however.

As a drive-by, stop lying about the number of bits that ProtocolDecl
uses on top of NominalTypeDecl, and move the overflow bits down into
ProtocolDecl itself so we don't bloat Decl unnecessarily.

Swift SVN r31381
2015-08-21 17:51:23 +00:00
Doug Gregor
ee7803a87a Eliminate the list of protocols from ExtensionDecl. NFC
Swift SVN r31349
2015-08-19 21:33:52 +00:00
Doug Gregor
95416eac0e Sink TypeDecl::getProtocols() down into NominalTypeDecl.
We're no longer using this information for generic type parameters or
associated types, so there's no point in leaving this honeypot
around. Note that this information is redundant with what's in the
conformance lookup table already, so it will be going away soon.

Swift SVN r31334
2015-08-19 06:42:32 +00:00
Doug Gregor
f898887894 Eliminate getConformsTo() callback from the archetype builder.
The getConformsTo() callback was responsible for forcing the
collection of the requirements directly placed on an associated type,
which then get added to the archetype builder. This resulted in an
unhealthy dependency on the list of protocols attached to TypeDecl
(which should go away). Instead, retrieve the requirements from the
associated type's archetype (once it's been computed) or directly from
its list of "inherited" types (while we're building the generic
signature for the protocol itself).

Swift SVN r31332
2015-08-19 06:42:27 +00:00
Slava Pestov
af1e0b316e Sema: Your monthly dose of minor @objc fixes
- Disallow @objc on members of non-@objc protocols (the
  real reason for this patch)

- Add a separate diagnostic for @objc appearing on members
  in non-class, non-protocol types.

- Clean up the code that enforces that @objc can only be
  applied to @objc-rooted classes. The diagnostic would
  be incorrectly emitted for @objc subclasses of generic
  classes.

Fixes <rdar://problem/17273524>.

Swift SVN r31303
2015-08-18 18:52:51 +00:00
Doug Gregor
9c82081e3f Reduce type parameters and associated types' dependence on "getProtocols()".
This is a step toward weeding out the "getProtocols()" list on
TypeDecl. Now, use the Archetype's list of protocols for the set of
protocols to which the type parameter or associated type
conforms. Since that list is fully canonicalized, it's more generally
reliable. However, start serializing the list of inherited types for a
generic type parameter, so we can print it appropriately.

Swift SVN r31297
2015-08-18 17:57:37 +00:00
Slava Pestov
ccf21ff90a Revert "Sema: Fix infinite recursion when associated type default references itself"
This reverts revision r30688. The patch needs more work, because it flags a
valid case as circular, see r15054, "Relax restriction on indirectly-self-
recursive protocol conformances.  (rdar://problem/16306715)".

Swift SVN r30690
2015-07-27 06:41:10 +00:00
Slava Pestov
29d3f8f400 Sema: Fix infinite recursion when associated type default references itself
Fixes <rdar://problem/20985232>.

Swift SVN r30688
2015-07-27 05:05:05 +00:00
Slava Pestov
3bead78373 ArchetypeBuilder: Fix infinite recursion with recursive requirements
We have to check for cycles of length > 1 here. Also, add a bit to the
AssociatedTypeDecl to ensure the recursive requirement diagnostic is
only emitted once.

Fixes <rdar://problem/17986597>.

Swift SVN r30678
2015-07-27 00:40:47 +00:00
Joe Groff
0b1283b1c9 Have 'defer' statements cons up func decls instead of closure literals.
The defer body func is only ever fully applied, so SILGen can avoid allocating a closure for it if it's declared as a 'func', making it slightly more efficient at -Onone.

Swift SVN r30638
2015-07-25 21:28:06 +00:00
Jordan Rose
e77e0587c7 Enforce maximum allowed access for extensions with 'where' clauses.
Otherwise, we end up with declarations with public access that do not
have public 'self' types. These declarations can then be used by other
modules, which may end up trying to access non-external symbols.

This closes a loophole currently in use by the standard library, so
the '_prext_ReverseIndexType' and '_ReverseCollectionType' protocols
become public for now. In order to keep the API impact minimized,
extensions involving these protocols now extend them directly, so that
all of the "private" stuff shows up in one place in the generated
interface. This is not a long-term solution, but it's no worse than
the rest of the underscore rules in the standard library.

rdar://problem/21380336 tracks relaxing access restrictions for protocol
conformances when the witnesses come from a different type, like a
protocol extension. This requires some SILGen work to do correctly.

Finishes rdar://problem/21559986

Swift SVN r30612
2015-07-25 01:06:50 +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
6b7647c0a7 Sema: Don't set type of AssociatedTypeDecl until we have an archetype
Otherwise the verifier can crash because hasType() returns true but
getType() gives us a MetatypeType that hits a null pointer in
desugaring.

The computeType() calls appear in a few too many places for my liking;
would be nice to clean this up further or replace everything with
interface types one day.

Fixes <rdar://problem/19606899>.

Swift SVN r30388
2015-07-19 20:57:18 +00:00
Slava Pestov
78bbcce84a Factor out some code duplication with setting EnumElementDecl types, NFC
Swift SVN r30387
2015-07-19 20:57:15 +00:00
Slava Pestov
e748908990 Sema: Don't set type of TypeAliasDecl until we resolve the alias type
This changes the behavior to match NominalTypeDecls, which don't have a type
until everything is set up either. In a few places we construct TypeAliasDecls
from known types directly, and we have to call computeType().

Fixes <rdar://problem/19534837>.

Swift SVN r30386
2015-07-19 20:55:53 +00:00
Doug Gregor
31787b66ee Generalize the "is being type checked" check to consider the type context.
Fixes 22 crashers.

Swift SVN r29948
2015-07-07 23:38:16 +00:00
Slava Pestov
ee07ddc2bf Sema: Fix crash calling protocol extension methods returning Self on existential
In r26737, Sema was changed to not wrap Self occurring in a protocol
extension in a DynamicSelf. The commit message was rather terse but
I believe this is because the metadata for Self is bound to the static
base type, not the runtime base type.

However, we still need to substitute Self in the return type for the
static base type in the case where the base is an existential,
otherwise we get an open existential type leaking out.

Also remove the default argument for replaceCovariantResultType(),
every call site passed in a value and it seems bad to omit it on
accident.

Fixes <rdar://problem/21433694>.

Swift SVN r29802
2015-06-30 05:36:00 +00:00
Joe Groff
66ba6827bf Parse the 'indirect' attribute on enums and cases.
Swift SVN r29777
2015-06-28 21:52:59 +00:00
Dmitri Hrybenko
37a4335b88 Replace swift::Range with llvm::iterator_range
Due to inreased use of llvm::make_range in LLVM headers and ADL for
types defined in the swift namespace, some of the LLVM headers started
to trigger ambiguity errors between llvm::make_range and
swift::make_range.

Swift SVN r29700
2015-06-25 22:01:39 +00:00