Commit Graph

434 Commits

Author SHA1 Message Date
Robert Widmann
ab093db95e Serialize the __shared type attribute 2017-07-23 21:47:25 -07:00
Andrew Trick
1ab24d8c0f Update SIL VERSION_MINOR for new SIL instruction. 2017-07-18 08:58:57 -07:00
Alex Hoppen
f8c2692f79 Introduce special decl names
Special DeclNames represent names that do not have an identifier in the
surface language. This implies serializing the information about whether
a name is special together with its identifier (if it is not special)
in both the module file and the swift lookup table.
2017-07-11 19:04:13 +02:00
Robert Widmann
ab580a3a0a Remove @autoclosure and @noescape as decl attributes
Using these in declaration position has been deprecated and
removed in Swift 3.  These attributes were not being parsed and
contained deadweight diagnostics that should have been moved
when these attributes became type attributes.
2017-07-05 21:27:04 -07:00
Robert Widmann
ac5594dabe Use a meaningful representation of parameter specifiers
In anticipation of future attributes, and perhaps the ability to
declare lvalues with specifiers other than 'let' and 'var', expand
the "isLet" bit into a more general "specifier" field.
2017-06-29 16:03:49 -07:00
Robert Widmann
777e1f9604 Miscellaneous cleanups for Parameters/Tuple Types
* Move IsInOut bit into the type parameter flags and
make sure to serialize it.

* Remove some unused constructors and accessors.
2017-06-21 10:17:43 -07:00
Jordan Rose
f0aca936c7 Allow '@objc(RuntimeName)' on classes with generic ancestry.
This is accomplished by recognizing this specific situation and
replacing the 'objc' attribute with a hidden '_objcRuntimeName'
attribute. This /only/ applies to classes that are themselves
non-generic (including any enclosing generic context) but that have
generic ancestry, and thus cannot be exposed directly to Objective-C.

This commit also eliminates '@NSKeyedArchiverClassName'. It was
decided that the distinction between '@NSKeyedArchiverClassName' and
'@objc' was too subtle to be worth explaining to developers, and that
any case where you'd use '@NSKeyedArchiverClassName' was already a
place where the ObjC name wasn't visible at compile time.

This commit does not update diagnostics to reflect this change; we're
going to change them anyway.

rdar://problem/32414557
2017-06-05 17:32:25 -07:00
Jordan Rose
e8229107ac [Serialization] Drop enums if a case payload can't be deserialized.
Layout for an enum depends very intimately on its cases---both their
existence and what their payload types are. That means there's no way
to "partly" recover from failure to deserialize an individual case's
payload type, the way we can partly recover from failing to
deserialize an initializer in a class. Add deserialization recovery
to enums by validating all of their payload types up front, and
dropping the enum if we can't import all of the cases.

This is the first time where we're trying to do deserialization
recovery for a /type/, and that could have many more ripple effects
than for a var/func/subscript/init. A better answer here might be to
still import the enum but mark it as unavailable, but in that case
we'd have to make sure to propagate that unavailability to anything
that /used/ the enum as well. (In Swift, availability is checked based
on use of the name, so if someone manages to refer to an enum using
inferred types we'd be in trouble.)

There is one case here that's not covered: if an enum case has a
payload that references a type declaration nested within the enum, but
then that nested type /itself/ can't be loaded for some reason, we
have no way to check that up front, because we can't even try to load
the nested type without loading its parent DeclContext (the enum). I
can't think of an easy solution for this right now.

(In the future, we'll be able to support dropping a single case for
resilient enums. But we're not there right now.)

rdar://problem/31920901
2017-05-17 17:05:15 -07:00
Jordan Rose
4cce46d197 [Serialization] Bump the module version for 4a6fe941c. (#9699)
Oops.
2017-05-17 12:57:27 -07:00
Jordan Rose
4a6fe941c7 [Serialization] Do less work checking if a value can be deserialized. (#9666)
Previously we recorded the canonical type of the declaration and made
sure we could deserialize that, but that's a lot of extra work
building up intermediate types that we mostly don't need. Instead,
record smaller types that represent the possible points of failure---
right now, just the nominal types that are referenced by the value
(function, variable/constant, subscript, or initializer). I chose to
use types instead of declarations here because types can potentially
encode more complicated constraints later (such as generic types
checking that their arguments still conform).

This gains us back 20% of type-checking time on a compile-time
microbenchmark: `let _ = [1, 2]`. I expect the effect is less dramatic
the more expressions you have, since we only need to deserialize
things once.
2017-05-17 09:02:45 -07:00
Doug Gregor
7955aa13e6 Rename @NSKeyedArchive* attributes.
@NSKeyedArchiveLegacy -> @NSKeyedArchiverClassName
@NSKeyedArchiveSubclassesOnly -> @NSKeyedArchiverEncodeNonGenericSubclassesOnly

Fixes rdar://problem/32178796.
2017-05-15 11:02:31 -07:00
Jordan Rose
d8eef2ea5e [Serialization] Record whether an initializer was newly 'required'
That is, whether an initializer is 'required', and either does not
override anything or overrides a non-required initializer. We don't
use this for anything now, but it'll show up in the next commit.
2017-05-10 11:55:54 -06:00
Jordan Rose
6c098033de Lift the decision of whether a method needs a vtable slot up to AST.
This lets us serialize that decision, which means we can conceivably
/change/ the decision in later versions of the compiler without
breaking existing code. More immediately, it's groundwork that will
eventually allow us to drop decls from the AST without affecting
vtable layout.

This isn't actually a great answer; what we really want is for SIL
vtables to be serialized consistently and treated as the point of
truth. But that would be more change than we're comfortable taking in
the Swift 4 timeframe.

First part of rdar://problem/31878396.
2017-05-04 17:49:47 -07:00
Joe Groff
70f15b3c5e SIL: Serialization for KeyPathInsts.
rdar://problem/31768491
2017-05-03 20:22:39 -07:00
Doug Gregor
aaf7933a6d Add the @NSKeyedArchiveLegacy attribute.
This attribute allows one to provide the "legacy" name of a class for
the purposes of archival (via NSCoding). At the moment, it is only
useful for suppressing the warnings/errors about classes with unstable
archiving names.
2017-05-02 22:38:32 -07:00
Joe Shajrawi
0d0cac357a retain_value_addr and release_value_addr SIL instructions: take as an input an address, load the value inside it and call retain_value and release_value respectively 2017-04-30 10:23:55 -07:00
Joe Shajrawi
d17258cac7 @in_constant calling convention - part of passing large loadable types by address 2017-04-30 10:13:02 -07:00
Jordan Rose
a9b6181ebd [Serialization] Drop support for serializing LValueType. (#9080)
This type never appears in API boundaries or in SIL instructions,
which means it never gets serialized.
2017-04-28 11:15:15 -07:00
Jordan Rose
1168cacf4f [Serialization] Drop decls whose types can't be deserialized.
Proof-of-concept for the above. This shouldn't be common---renames are
far more likely, and those we can track---but occurs when the
swift_wrapper attribute (the implementation of NS_STRING_ENUM) is
active in Swift 4 but not in Swift 3.

Note that this only checks the canonical interface type of the
declaration, because the non-canonical type may contain references to
the declaration's generic parameters.
2017-04-27 18:30:34 -07:00
Andrew Trick
087a1a956e Fix SIL serialization for access markers. 2017-04-26 17:11:30 -07:00
John McCall
978f0e05fe Add unpaired access marker instructions and use them to implement
dynamic access tracking in materializeForSet.
2017-04-22 22:52:13 -04:00
Jordan Rose
f1902fd719 [Serialization] Drop typealiases whose underlying types have changed. (#8896)
In order to accomplish this, cross-module references to typealiases
are now banned except from within conformances and NameAliasTypes, the
latter of which records the canonical type to determine if the
typealias has changed. For conformances, we don't have a good way to
check if the typealias has changed without trying to map it into
context, but that's all right---the rest of the compiler can already
fall back to the canonical type.
2017-04-21 13:17:12 -07:00
Slava Pestov
53305f1e58 Merge pull request #8847 from slavapestov/subclass-existentials-clang-importer
ClangImporter: Support for subclass existentials
2017-04-19 13:27:02 -07:00
Graydon Hoare
6a94c9fb9e Merge pull request #8735 from graydon/rdar-30959593-operators-defeat-incrementality
Attribute @_implements & deriving enum equality not-named ==
2017-04-19 11:18:55 -07:00
Slava Pestov
57b2c059db Serialization: Fix serialization of layout constraints 2017-04-19 00:52:14 -07:00
Doug Gregor
f6f547469d [Serialization] Filter Objective-C methods by mangled name rather than type ID.
Module files store all of the Objective-C method entrypoints in a
central table indexed by selector, then filter the results based on
the specific class being requested. Rather than storing the class as
a TypeID---which requires a bunch of deserialization---store its
mangled name. This allows us to deserialize less, and causes circular
deserialization in rdar://problem/31615640.
2017-04-18 11:53:17 -07:00
Graydon Hoare
c71295a12a Add @_implements decl attribute. 2017-04-18 11:12:53 -07:00
Slava Pestov
d49f8fb6d9 AST: Introduce primitive AnyObject type
Add a 'hasExplicitAnyObject()' bit to ProtocolCompositionType
to represent canonical composition types containing '& AnyObject'.

Serialize this bit and take it into account when building
ExistentialLayouts.

Rename ProtocolCompositionType::getProtocols() to getMembers()
since it can contain classes now, and update a few usages that
need further attention with FIXMEs or asserts.

For now, nothing actually constructs these types, and they will
trigger arounds asserts. Upcoming patches will introduce support
for this.
2017-04-13 21:17:05 -07:00
Jordan Rose
b93ee5fbec [Serialization] Don't bother with interface types for typealiases. (#8752)
These are fully recreatable from the underlying type, and indeed we
do that already. No intended functionality change.
2017-04-13 15:45:45 -07:00
Arnold Schwaighofer
4d60ec333b AST/SILGen support for constant string literals
rdar://30545013
2017-04-11 11:41:43 -07:00
Arnold Schwaighofer
b167b4475d Add SIL and IRGen support for a ConstantStringLiteral instruction
This supports a utf8 or utf16 encoding.

rdar://30545013
2017-04-11 08:43:47 -07:00
Jordan Rose
7e8d642e8e [Serialization] When crashing, note if mix-and-match may be to blame.
That is, a Swift 3 target imported into a Swift 4 context or vice
versa. This requires serializing the compatibility mode explicitly,
instead of including it in the textual version string that's only
for debugging.
2017-04-10 16:38:58 -07:00
Doug Gregor
5c89eb84f0 [AST] Drop substitutions from type witnesses.
Nobody is using the actual substitutions, but we sure did a lot of
work to cope with them.
2017-04-05 11:21:38 -07:00
Doug Gregor
30ef37cb83 [AST] Eliminate "inherited conformances" from NormalProtocolConformance.
All of this information is recoverable from the more-general,
more-sane signature conformances, so stop
recording/serializing/deserializing all of this extra stuff.
2017-04-04 22:20:50 -07:00
Doug Gregor
71d5988ab3 [Serialization] Serialization for the @objc “Swift 3 inferred” bit 2017-03-31 21:22:15 -07:00
Slava Pestov
8fe8b89b0f SIL: Terminology change: [fragile] => [serialized]
Also, add a third [serializable] state for functions whose bodies we
*can* serialize, but only do so if they're referenced from another
serialized function.

This will be used for bodies synthesized for imported definitions,
such as init(rawValue:), etc, and various thunks, but for now this
change is NFC.
2017-03-29 16:47:28 -07:00
John McCall
57ecaa7fae Add begin_access and end_access instructions.
NFC because we're not actually emitting them.
2017-03-26 04:37:05 -04:00
Joe Groff
39ecc53a25 Add a loadInvariant builtin.
Lowers to an invariant load in LLVM; probably useful for SIL too at some point too, but NFC at that level yet.
2017-03-08 21:02:03 -08:00
Michael Gottesman
cfb5893663 [silgen] Fix destroying destructor to use proper ownership with its @owned return value.
rdar://29791263
2017-03-02 17:17:17 -08:00
John McCall
fe7915d09e Rework a number of SIL and IRGen witness-table abstractions
to correctly handle generalized protocol requirements.

The major missing pieces here are that the conformance search
algorithms in both the AST (type substitution) and IRGen
(witness table reference emission) need to be rewritten to
back-track requirement sources, and the AST needs to actually
represent this stuff in NormalProtocolConformances instead
of just doing ???.

The new generality isn't tested yet; I'm looking into that,
but I wanted to get the abstractions in place first.
2017-03-02 01:34:13 -05:00
Doug Gregor
ce718eeb54 Merge branch 'master' into normal-conformance-requirement-signature 2017-03-01 20:38:20 -08:00
Michael Gottesman
98f77ab18e [serialization] Bump version_minor for end_lifetime.
I forgot to do this in 4bc12aedbd.

Sorry Jordan!
2017-03-01 19:04:33 -08:00
Doug Gregor
348c6b8001 Protocol conformance: store conformances needed for the requirement signature.
The protocol conformance checker verifies that all of the requirements
in the protocol's requirement signature are fulfilled. Save the
conformances from that check into the NormalProtocolConformance,
because this is the record of how that concrete type satisfies the
protocol requirements.

Compute, deserialize, and verify this information, but don't use it
for anything just yet. We'll use this to eliminate the "inherited
protocol map" and possibility some redundant type-witness
information.
2017-03-01 15:32:50 -08:00
Jordan Rose
3639343c53 [Serialization] Distinguish between protocol/extension for types too. (#7794)
Replace an existing flag for cross-references to member types (that
wasn't getting much use) with one consistent with how we lookup
values. This fixes the case where someone actually has a useful type
as a member of a protocol extension, and that type gets referenced in
another module; Dispatch does exactly this.

Because you can currently only define typealiases in protocol
extensions, not new types, there's always a workaround for someone
hitting this issue: just use the underlying type.

https://bugs.swift.org/browse/SR-4076
2017-02-28 10:36:46 -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
cc54361b2a Serialization: Add support for generic subscripts 2017-02-19 21:34:27 -08:00
Arnold Schwaighofer
876cea81ae SIL: Add an allowed access kind to the opened value of an open_existential_addr instruction
Once we move to a copy-on-write implementation of existential value buffers we
can no longer consume or destroy values of an opened existential unless the
buffer is uniquely owned.

Therefore we need to track the allowed operation on opened values.

Add qualifiers "mutable_access" and "immutable_access" to open_existential_addr
instructions to indicate the allowed access to the opened value.

Once we move to a copy-on-write implementation, an "open_existential_addr
mutable_access" instruction will ensure unique ownership of the value buffer.
2017-02-15 14:23:12 -08:00
Argyrios Kyrtzidis
ca906d1e99 Add '-Fsystem' framework search option to indicate path for frameworks that should be treated as 'system'
This has the effect of propagating the search path to the clang importer as '-iframework'.
It doesn't affect whether a swift module is treated as system or not, this can be done as follow-up enhancement.
2017-02-14 16:13:25 -08:00
Arnold Schwaighofer
39fa2f0228 Use the swift calling convention for swift functions
Use the generic type lowering algorithm described in
"docs/CallingConvention.rst#physical-lowering" to map from IRGen's explosion
type to the type expected by the ABI.

Change IRGen to use the swift calling convention (swiftcc) for native swift
functions.

Use the 'swiftself' attribute on self parameters and for closures contexts.

Use the 'swifterror' parameter for swift error parameters.

Change functions in the runtime that are called as native swift functions to use
the swift calling convention.

rdar://19978563
2017-02-14 12:17:57 -08:00
Jordan Rose
c86f8e7089 [Serialization] Improve extensions of nested types with the same name (#7397)
Previously looking up an extension would result in all extensions for
types with the same name (nested or not) being deserialized; this
could even bring in base types that had not been deserialized yet. Add
in a string to distinguish an extension's base type; in the top-level
case this is just a module name, but for nested types it's a full
mangled name.

This is a little heavier than I'd like it to be, since it means we
mangle names and then throw them away, and since it means there's a
whole bunch of extra string data in the module just for uniquely
identifying a declaration. But it's correct, and does less work than
before, and fixes a circularity issue with a nested type A.B.A that
apparently used to work.

https://bugs.swift.org/browse/SR-3915
2017-02-13 12:42:12 -08:00