Commit Graph

1565 Commits

Author SHA1 Message Date
Jordan Rose
73d4526943 [Serialization] Drop overriding methods if the base is missing.
Proof-of-concept for this sort of recovery. In the real world, it's
more likely that this will happen due to differences between Swift 3
and Swift 4, rather than changes in what macros are defined, but the
latter can still happen when debugging.

There's a lot to do here to consider this production-ready. There are
no generics involved and no potential circular references, and the
/rest/ of the compiler isn't prepared for this either. But it's cool
to see it working!

Actually recovering is hidden behind the new
-enable-experimental-deserialization-recovery option; without it the
compiler will continue to eagerly abort.
2017-04-05 18:32:08 -07:00
Jordan Rose
e831dca955 [Serialization] Save path traces from failed cross-references.
This is important information in a crash trace, so let's make sure to
preserve it even as the stack unwinds.
2017-04-05 16:40:56 -07:00
Jordan Rose
3dbc9de75b [Serialization] Use llvm::Expected for deserialization failures.
...but don't actually try to handle any of them yet. In fact, don't
even bother to /produce/ them yet, except for resolving
cross-references.
2017-04-05 15:17:01 -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
Jordan Rose
a8e4e72270 [Serialization] Delay all actions in the same module together. (#8123)
Back in December DougG added code to delay the formation of generic
environments until all declarations from a particular module had been
deserialized, to avoid circular dependencies caused by too-eager
deserialization of protocol members. This worked great for fully-built
modules, but still had some problems with module merging, the phase of
multi-file compilation where the "partial" swiftmodules that
correspond to each source file in a target are loaded and remitted as
a single swiftmodule. Fix this by picking one of the partial
swiftmodules as the representative one for delayed actions, and wait
until deserialization is complete for /all/ of the serialized ASTs in
the same target to form the generic environments.

rdar://problem/30984417
2017-03-16 15:22:06 -07:00
Huon Wilson
ca3a398b4a Merge pull request #8021 from huonw/protocol-where-clause
Parse/typecheck/print where clauses on protocols
2017-03-15 11:00:46 -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
Huon Wilson
54f247693c [AST]/[Parse] parse where clauses on protocol declarations. 2017-03-09 16:08:16 -08:00
Slava Pestov
c040c71ea9 AST: Remove some unnecessary SubstitutionList copies
ASTContext::getSpecializedConformance() already copies the
substitutions, so remove some AllocateCopy() calls.

Also, add a new overload taking a SubstitutionMap instead.
This allows removing some gatherAllSubstitutions() calls,
which have an allocation inside them.

Finally, remove the now-unused ModuleDecl parameter from
ProtocolConformance::subst() and make it public.
2017-03-07 15:59:05 -08: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
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
Huon Wilson
8423018057 [Parse] Parse trailing where clauses on associated types. 2017-02-24 19:21:32 -08:00
Jordan Rose
99d2b171d3 [Serialization] If we fail to deserialize a type, dump it.
...rather than just printing it, which isn't giving us enough info.

In pursuit of rdar://problem/30382791.
2017-02-24 16:36:52 -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
880803aaba AST: Initial plumbing for generic subscripts 2017-02-19 21:34:26 -08:00
Slava Pestov
b319a3aa32 AST: Clean up some more duplication using the new GenericContext 2017-02-19 21:00: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
Slava Pestov
41eba98902 Gardening: Fix some unused variable warnings in no-assert builds 2017-02-15 12:57:35 -08:00
Doug Gregor
1f04b2fecf [Serialization] Wire up the generic parameter of a protocol early.
When we deserialize a protocol declaration, we had a bunch of
intervening code before it would deserialize and wire up its generic
parameter (Self), including configuring the generic environment. If
any of that code referenced an AssociatedTypeDecl of that protocol,
the deserialization of the AssociatedTypeDecl could end up computing
an erroneous type.

This might be the source of the nondeterministic deserialization
failure that seems to afflict AssociatedTypeDecls in
rdar://problem/30382791.
2017-02-14 14:14:35 -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
swift-ci
1d5083318a Merge pull request #7375 from DougGregor/serialization-param-debug 2017-02-09 17:37:07 -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
swift-ci
a35fb58ebe Merge pull request #7371 from jrose-apple/asserts-catch-bugs-or-so-i-hope 2017-02-09 16:26:31 -08:00
Jordan Rose
509354f48b [Serialization] Fix a PrettyStackTraceEntry typo.
No functionality change.
2017-02-09 15:24:34 -08:00
Jordan Rose
319cd64c32 [Serialization] Add an assert to try to catch a crash.
Tracked by rdar://problem/30426920.
2017-02-09 15:22:55 -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
bd4f31025f AST: GenericEnvironment::mapTypeIntoContext() no longer needs to take a ModuleDecl
Now, use LookUpConformanceInSignature instead.
2017-02-07 19:25:34 -08:00
Roman Levenstein
e5d5d7d5fd Some LayoutConstraint improvements.
This biggest change is:
- LayoutConstraintInfo is now a FoldingSetNode, which allows for proper canonicalization of LayoutConstraints. This is important for the correctness of type comparisons if types contain layout constraints.

No functionality changes from the client's point of view.
2017-02-07 17:03:11 -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
Jordan Rose
bb09c21774 [Serialization] Don't show a misleading PrettyStackTrace note.
There's a speculative path note warning people about accidentally
using swiftmodules whose dependencies might have changed, but this
doesn't make sense when the module with the problem is also the
module being built (which happens during the module-merging phase
of multi-file compilation). In that case, pay an extra branch to
avoid showing the note.

No intended functionality change.
2017-02-01 18:18:16 -08:00
Doug Gregor
f7f703ad04 [Archetype builder] Canonicalize and minimize same-type constraints.
Introduce an algorithm to canonicalize and minimize same-type
constraints. The algorithm itself computes the equivalence classes
that would exist if all explicitly-provided same-type constraints are
ignored, and then forms a minimal, canonical set of explicit same-type
constraints to reform the actual equivalence class known to the type
checker. This should eliminate a number of problems we've seen with
inconsistently-chosen same-type constraints affecting
canonicalization.
2017-02-01 10:51:02 -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
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
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