1627 Commits

Author SHA1 Message Date
Jordan Rose
144e993bd9 [Serialization] Add assertions to track down a SIL deserialization issue.
The issue: we're apparently not keeping the archetypes in an instruction in sync
with the archetypes used in the SIL function's generic signature. This apparently
isn't the problem, but it's a good assertion to have, if a little ad hoc.

(The actual issue is rdar://problem/23892955.)
2015-12-21 17:42:13 -08:00
Argyrios Kyrtzidis
042efbfb26 [AST] Introduce internal attribute '_migration_id'.
It's intended use is to keep track of stdlib changes for migration purposes.
2015-12-16 21:28:38 -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
practicalswift
8a9d99ea93 Fix typo: assocativity → associativity 2015-12-14 00:11:15 +01:00
Joe Groff
b1667ec705 SIL: Introduce a new @inout_aliasable parameter convention.
Modeling nonescaping captures as @inout parameters is wrong, because captures are allowed to share state, unlike 'inout' parameters, which are allowed to assume to some degree that there are no aliases during the parameter's scope. To model this, introduce a new @inout_aliasable parameter convention to indicate an indirect parameter that can be written to, not only by the current function, but by well-typed, well-synchronized aliasing accesses too. (This is unrelated to our discussions of adding a "type-unsafe-aliasable" annotation to pointer_to_address to allow for safe pointer punning.)
2015-12-08 14:35:47 -08:00
Nadav Rotem
4bc6248319 Fix an unused variable warning in deserialization. 2015-12-07 09:32:24 -08:00
Roger Z
fbbc25aba2 whitespace and capitalization for TODO's 2015-12-03 15:56:26 -05:00
Simone Ferrini
ce4031f240 Removed unnecessary semicolons 2015-12-03 21:24:40 +01:00
Joe Groff
fbd2e4d872 Rename @asmname to @_silgen_name.
This reflects the fact that the attribute's only for compiler-internal use, and isn't really equivalent to C's asm attribute, since it doesn't change the calling convention to be C-compatible.
2015-11-17 14:13:48 -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
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
0b2b0df907 Clean up canonicalization of GenericSignatures. NFC
GenericSignature's factory method determining whether the signature
was canonical based solely on whether the types in the parameters and
requirments were canonical. While that is currently true (for legacy
reasons), it is wrong: canonicalization also needs to canonicalize
requirements, including same-type requirements, as is currently done
in the canonical signature "for mangling". Move the "this is
canonical" dependency to the point where the canonical signature is
actually computed, so we can change the definition of canonical
signatures later.

While we're here, don't eagerly compute the canonical generic
signature in GenericSignature::getASTContext().

Swift SVN r32309
2015-09-29 22:05:47 +00:00
Jordan Rose
babdb9e9f9 Delay loading the witnesses of a protocol conformance.
Apart from being general compile-time goodness, this helps break a
circularity issue involving serialization cross-references and the
Clang importer.

The test is being added to validation-tests because it relies on
several levels of non-laziness in the compiler, all of which we'd
like to fix. It's making sure we don't regress here, but it isn't
actually verifying this change in particular.

rdar://problem/22364953

Swift SVN r31455
2015-08-25 21:47:18 +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
Jordan Rose
3e0cf08daa [Serialization] Support factory initializers.
These never appear in Swift code, but they can appear when serializing the
full output of SILGen ("SIB" format) because that includes code synthesized
for imported Clang declarations.

rdar://problem/22098491

Swift SVN r31364
2015-08-20 19:28:22 +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
83cb1e69bb Serialize the list of inherited types for all nominal types.
This provides better AST fidelity through module files and further
reduces our dependencies on storing a list of protocols on nominal
type declarations.

Swift SVN r31345
2015-08-19 21:10:45 +00:00
Doug Gregor
dd68b9fc59 Start serializing the "inherited" list of extension declarations.
This improves the fidelity of the AST printed from a loaded module, as
well as consistency in the AST. Also teach the Clang importer to add
"inherited" clauses, providing better fidelity for the mapping from
Objective-C to Swift.

With trivial update to SDKAnalyzer test.

Swift SVN r31344
2015-08-19 21:10:42 +00:00
Ted Kremenek
60174804e1 Revert "Start serializing the "inherited" list of extension declarations."
This reverts commit r31337.

Swift SVN r31340
2015-08-19 20:13:13 +00:00
Doug Gregor
1393ee18a4 Start serializing the "inherited" list of extension declarations.
This improves the fidelity of the AST printed from a loaded module, as
well as consistency in the AST. Also teach the Clang importer to add
"inherited" clauses, providing better fidelity for the mapping from
Objective-C to Swift.

Swift SVN r31337
2015-08-19 18:29:11 +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
f0fcd594c0 Stop using TypeDecl::Protocols within abstract type parameters.
More baby steps toward sinking protocol lists down into
NominalTypeDecl. Fixes another 12 crashers along the way.

Swift SVN r31333
2015-08-19 06:42:30 +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
Jordan Rose
cd3d98c10c [Serialization] Don't look at extension members when resolving XREFs.
This is mostly a "don't crash" commit, but since member XREFs don't
specify which module they're looking in, they can actually pick up
members from the module currently being compiled...which may not have
a type yet.

rdar://problem/21071045

Swift SVN r30895
2015-08-01 00:37:45 +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
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
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
John McCall
d190ee0767 Honor the swift_error attribute during import.
Add a new convention to describe what happens with
nonzero_result on a type that isn't imported as Bool.
This isn't really a safe convention to implement, but
calls are fine.

Implements <rdar://21715350>.

Swift SVN r29953
2015-07-08 00:57:27 +00:00
Jordan Rose
7962f71ab7 [Serialization] Add more PrettyStackTraces.
No functionality change.

Swift SVN r29861
2015-07-01 23:34:33 +00:00
Joe Groff
e57c470019 Introduce a "@box T" type for SIL.
Represents a heap allocation containing a value of type T, which we'll be able to use to represent the payloads of indirect enum cases, and also improve codegen of current boxes, which generates non-uniqued box metadata on every allocation, which is dumb. No codegen changes or IRGen support yet; that will come later.

This time, fix a paste-o that caused SILBlockStorageTypes to get replaced with SILBoxTypes during type substitution. Oops.

Swift SVN r29489
2015-06-18 15:21:52 +00:00
Mark Lacey
39087cd36b Revert "Introduce a "@box T" type for SIL."
This reverts commit r29474 because it looks like it is breaking the
build of the SpriteKit overlay.

Swift SVN r29482
2015-06-18 06:28:04 +00:00
Joe Groff
7b0045c790 Introduce a "@box T" type for SIL.
Represents a heap allocation containing a value of type T, which we'll be able to use to represent the payloads of indirect enum cases, and also improve codegen of current boxes, which generates non-uniqued box metadata on every allocation, which is dumb. No codegen changes or IRGen support yet; that will come later.

Swift SVN r29474
2015-06-18 04:07:03 +00:00
Chris Willmore
52d441ba61 Have a bit per PatternBindingEntry saying whether the corresponding
initializer has been type-checked, rather than a bit for the entire
PatternBindingDecl.

<rdar://problem/21057425> Crash while compiling attached test-app.

Swift SVN r29049
2015-05-27 01:31:28 +00:00
Doug Gregor
98314777f2 Allow a protocol extension to define a default implementation for a requirement of its own protocol.
Based on Dave’s hack, this allows one to define a “default implementation” as, e.g.,

  protocol P {
    func foo()
  }

  extension P {
    final func foo() { … }
  }

Swift SVN r28949
2015-05-23 03:40:41 +00:00
Doug Gregor
a8a6924a9d Deserialize the @warn_unused_result attribute.
Fixes rdar://problem/21043330.

Swift SVN r28859
2015-05-20 23:54:30 +00:00
Jordan Rose
72188fc00b [Serialization] Show types when XREF resolution fails.
For debugging purposes only.

Swift SVN r28809
2015-05-20 01:04:51 +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
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
Doug Gregor
f2e66d1cd7 Break recursion when deserializing constrained protocol extensions.
When reading the generic parameters of a constrained protocol
extension, cross-refencing an associated type would perform name
lookup into the protocol extension itself, causing fatal recursion
during deserialization. Fixed by avoiding additional deserialization
when looking for an associated type. Fixes rdar://problem/20812303.

Swift SVN r28228
2015-05-06 23:56:58 +00:00
Joe Groff
ab09922966 Runtime/IRGen: Replace the _SwiftNativeNS*Base +load hack with a compiler hack.
Rather than swizzle the superclass of these bridging classes at +load time, have the compiler set their ObjC runtime base classes, using a "@_swift_native_objc_runtime_base" attribute that tells the compiler to use a different implicit base class from SwiftObject. This lets the runtime shed its last lingering +loads, and should overall be more robust, since it doesn't rely on static initialization order or deprecated ObjC runtime calls.

Swift SVN r28219
2015-05-06 22:00:59 +00:00
Chris Lattner
7927a230ae remove compiler support for let/else. This simplifies PBD back to being
an unconditional binding, yay.


Swift SVN r28101
2015-05-03 22:13:02 +00:00
John McCall
9065880e5a When an error import would conflict with another method,
preserve the original method name.

This heuristic is based on the Objective-C selector and therefore
doesn't really handle factory methods that would conflict with
initializers, but we can hope that those simply don't come up in
the wild.

It's not clear that this is the best thing to do --- it tends to
promote the non-throwing API over what's probably a newer, throwing
API --- but it's significantly easier, and it unblocks code without
creating deployment problems.

Swift SVN r28066
2015-05-02 01:52:37 +00:00
Doug Gregor
d86893482a Decouple conformance deserialization from getProtocols().
Swift SVN r27974
2015-04-30 16:13:42 +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
Doug Gregor
514ef30943 (De-)serialization for foreign error conventions.
Printing a module as Objective-C turns out to be a fantastic way to
verify the (de-)serialization of foreign error conventions, so
collapse the parsing-driving Objective-C printing test of throwing
methods into the general test for methods.

Swift SVN r27880
2015-04-28 20:59:32 +00:00
Doug Gregor
7dafdf873c Revert "(De-)serialization for foreign error conventions."
This reverts r27870. It's causing inexplicable SourceKit failures.

Swift SVN r27875
2015-04-28 17:50:59 +00:00
Doug Gregor
a487a9e345 (De-)serialization for foreign error conventions.
Printing a module as Objective-C turns out to be a fantastic way to
verify the (de-)serialization of foreign error conventions, so
collapse the parsing-driving Objective-C printing test of throwing
methods into the general test for methods.

Swift SVN r27870
2015-04-28 16:00:47 +00:00
Doug Gregor
3daae5b561 Serialize cross-references to constrained extensions with a generic signature.
Extensions cannot be uniquely cross-referenced, so cross-references to
extensions are serialized with the extended nominal type name and the
module in which the extension resides. This is not sufficient when
cross-referencing the generic type parameters of a constrained
protocol extension, because we don't know whether to get the
archetypes of the nominal type or some extension thereof. Serialize
the canonical generic signature so that we can pick an extension with
the same generic signature; it doesn't matter which we pick, so long
as we're consistent.

Fixes rdar://problem/20680169. Triggering this involves some
interesting interactions between the optimizer and standard library;
the standard library updates in the radar will test this.

Swift SVN r27825
2015-04-27 22:55:47 +00:00