Commit Graph

782 Commits

Author SHA1 Message Date
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
Xi Ge
46d3fe18e9 [Serialization] Simplify some code, tentatively fixing rdar://31812518. (#9017) 2017-04-25 17:48:40 -07: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
a3f725ac2f Serialization: Don't crash when serializing conformances with interface types in them 2017-04-17 18:19:40 -06:00
Slava Pestov
38a22d160f Serialization: Fix serialization of layout constraints 2017-04-13 21:17:06 -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
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
swift-ci
c39ffda2b8 Merge pull request #8477 from graydon/rdar-30961871-metrics-mark-2 2017-04-03 20:39:16 -07:00
Graydon Hoare
7c4eea6542 [Timers] Avoid YAML-special characters in timer names. 2017-03-31 22:58:04 -07:00
Doug Gregor
71d5988ab3 [Serialization] Serialization for the @objc “Swift 3 inferred” bit 2017-03-31 21:22:15 -07:00
adrian-prantl
79bf6e4b0b Merge pull request #8248 from adrian-prantl/30934351
Filter unextended module overlay VFS from serialized debugging options
2017-03-21 17:20:45 -07:00
Adrian Prantl
728c56c0ad Filter unextended module overlay VFS from serialized debugging options
Filter out any -ivfsoverlay options that include an
unextended-module-overlay.yaml overlay. By convention the Xcode
buildsystem uses these while *building* mixed Objective-C and Swift
frameworks; but they should never be used to *import* the module
defined in the framework.

rdar://problem/30934351
2017-03-21 16:15:38 -07:00
Erik Eckstein
d70bfc5de2 rename namespace NewMangling -> Mangle 2017-03-20 10:09:30 -07:00
Erik Eckstein
1625345b90 Remove the old mangler.
NFC
2017-03-17 16:10:36 -07:00
Slava Pestov
18fbfd46c5 Serialization: Fix latent bug with extensions of nested generic types
ExtensionDecls for nested generic types have multiple generic parameter
lists, one for each level of nested generic context.

We only serialized the outermost list, though. This didn't cause any
problems as far as I can see because most of the time we seem to use
the GenericSignature instead, which has the correct generic parameters.

However since we still have usages of getGenericParamsOfContext() on
deserialized DeclContexts, better safe than sorry.

I added a test; the test used to pass on master, but with the new
assertion I added, it would fail without the other changes in this
patch.
2017-03-13 19:33:30 -07:00
Slava Pestov
0881877eaa Serialization: Remove code that became dead when PolymorphicFunctionType was removed 2017-03-13 19:33:16 -07:00
Slava Pestov
162b2d252e AST: Include gardening to minimize dependencies on Expr.h
A lot of files transitively include Expr.h, because it was
included from SILInstruction.h, SILLocation.h and SILDeclRef.h.

However in reality most of these files don't do anything
with Exprs, especially not anything in IRGen or the SILOptimizer.

Now we're down to 171 files in the frontend which depend on
Expr.h, which is still a lot but much better than before.
2017-03-12 22:26:56 -07:00
Slava Pestov
0f4a7d246f AST: Remove GenericSignature::getAllDependentTypes()
This was a remnant of the old generics implementation, where
all nested types were expanded into an AllArchetypes list.

For quite some time, this method no longer returned *all*
dependent types, only those with generic requirements on
them, and all if its remaining uses were a bit convoluted.

- In the generic specialization code, we used this to mangle
  substitutions for generic parameters that are not subject
  to a concrete same-type constraint.

  A new GenericSignature::getSubstitutableParams()
  function handles this use-case instead. It is similar
  to getGenericParams(), but only returns generic parameters
  which require substitution.

  In the future, SubstitutionLists will only store replacement
  types for these generic parameters, instead of the list of
  types that we used to produce from getAllDependentTypes().

- In specialization mangling and speculative devirtualization,
  we relied on SubstitutionLists having the same size and
  order as getAllDependentTypes(). It's better to turn the
  SubstitutionList into a SubstitutionMap instead, and do lookups
  into the map.

- In the SIL parser, we were making a pass over the generic
  requirements before looking at getAllDependentTypes();
  enumeratePairedRequirements() gives the correct information
  upfront.

- In SIL box serialization, we don't serialize the size of the
  substitution list, since it's available from the generic
  signature. Add a GenericSignature::getSubstitutionListSize()
  method, but that will go away soon once SubstitionList
  serialization only serializes replacement types for generic
  parameters.

- A few remaining uses now call enumeratePairedRequirements()
  directly.
2017-03-02 22:57:52 -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
Slava Pestov
41eba98902 Gardening: Fix some unused variable warnings in no-assert builds 2017-02-15 12:57:35 -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
Jordan Rose
54be4e17ca [Serialization] Fix one PrettyStackTrace, add another. (#7436)
We want to see /what/ types are failing here.
2017-02-13 16:42:14 -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
Hugh Bellamy
cb3bdcc2a3 Merge pull request #7408 from hughbe/llvm-fallthrough
Use relatively new LLVM_FALLLTHROUGH instead of our own SWIFT_FALLTHROUGH
2017-02-13 17:39:59 +07:00
Slava Pestov
ec4a95be21 AST: Witness stores SubstitutionList instead of SubstitutionMap
This simplifies serialization and removes some calls of
SubstitutionMap::addSubstitution() and addConformance().
2017-02-12 00:51:26 -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
5a031d8500 Merge pull request #6154 from DougGregor/generic-env-serialization
[Serialization] Serialize archetypes as generic environment + interface type
2017-02-10 01:30:54 -08:00
Doug Gregor
90f021485d [Serialization] Serialize archetypes as generic environment + interface type.
Rather than serializing the complete structure of all archetypes
(which is completely redundant), serialize a reference to their owning
generic environment as well as their interface type. The archetype
itself will be reconsituted by mapping the interface type into that
generic environment.
2017-02-09 23:50:17 -08:00
Doug Gregor
90189358a8 [Serialization] Don't cross-reference module-scope generic parameter decls.
With serialization of the interface types of archetypes, we can end up
cross-referencing module-scope generic parameter declarations when
writing those interface types. Desugar such types on serialization to
fix a regression introduced by the change to generic environment
serialization.
2017-02-09 23:50:15 -08:00
Doug Gregor
44b2e6b959 [Serialization] Fail fast w/ debug information if a parameter has a bogus type.
Another spurious failure we're seeing occasionally in CI: a
deserialization issue involving the interface types of parameter
declarations. If this happens---either when serializing or
deserializing---dump some more debugging information.
2017-02-09 16:35:50 -08:00
Huon Wilson
74091fbcef [AST] Store and serialize a protocol's requirement signature.
This is the "canonical" representation of the type-level requirements of
a protocol, and we intend to use it pervasively in the compiler.
2017-02-08 13:08:31 -08:00
Slava Pestov
3519e0cd25 AST: Introduce new SubstitutionList type to replace ArrayRef<Substitution>
SubstitutionList is going to be a more compact representation of
a SubstitutionMap, suitable for inline allocation inside another
object.

For now, it's just a typedef for ArrayRef<Substitution>.
2017-02-06 21:36:33 -08:00
Saleem Abdulrasool
1b48e5bce3 Serialization: avoid flushing via a stringification
Pass the generated string to the emitter rather than invoking str to
create the string to flush the buffer and then referencing the backing
store.  NFC.
2017-02-05 21:27:16 -08:00
Jordan Rose
6f63c77353 [Serialization] Distinguish between static and non-static vars. (#7176)
Every other declaration kind gets this for free in its interface type,
but properties don't. Just add a bit, it's simple enough.

rdar://problem/30289803
2017-02-01 09:55:41 -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
99d47619e6 Merge pull request #7067 from jrose-apple/nested-type-lookup-table
[Serialization] Add a "nested types" lookup table for partial modules
2017-01-27 08:55:41 -08:00
Andrew Trick
1abeddcc5d [SILType] SILFunctionConventions API.
Separate formal lowered types from SIL types.
The SIL type of an argument will depend on the SIL module's conventions.
The module conventions are determined by the SIL stage and LangOpts.

Almost NFC, but specialized manglings are broken incidentally as a result of
fixes to the way passes handle book-keeping of aruments. The mangler is fixed in
the subsequent commit.

Otherwise, NFC is intended, but quite possible do to rewriting the logic in many
places.
2017-01-26 15:35:48 -08:00
Jordan Rose
8145cd0b22 [Serialization] Add a "nested types" lookup table for partial modules.
There's a class of errors in Serialization called "circularity
issues", where declaration A in file A.swift depends on declaration B
in file B.swift, and B also depends on A. In some cases we can manage
to type-check each of these files individually due to the laziness of
'validateDecl', but then fail to merge the "partial modules" generated
from A.swift and B.swift to form a single swiftmodule for the library
(because deserialization is a little less lazy for some things). A
common case of this is when at least one of the declarations is
nested, in which case a lookup to find that declaration needs to load
all the members of the parent type. This gets even worse when the
nested type is defined in an extension.

This commit sidesteps that issue specifically for nested types by
creating a top-level, per-file table of nested types in the "partial
modules". When a type is in the same module, we can then look it up
/without/ importing all other members of the parent type.

The long-term solution is to allow accessing any members of a type
without having to load them all, something we should support not just
for module-merging while building a single target but when reading
from imported modules as well. This should improve both compile time
and memory usage, though I'm not sure to what extent. (Unfortunately,
too many things still depend on the whole members list being loaded.)

Because this is a new code path, I put in a switch to turn it off:
frontend flag -disable-serialization-nested-type-lookup-table

https://bugs.swift.org/browse/SR-3707 (and possibly others)
2017-01-26 15:04:42 -08:00
Jordan Rose
5d89d86a97 [Serialization] Simplify the crawl for interesting nested decls.
- We aren't using derived top-level declarations anymore.
- We're looking for more than just operators.
- Nested members of local decls are still local, so we don't need to record
  their Objective-C methods.

No intended functionality change.
2017-01-25 16:09:32 -08:00