Commit Graph

956 Commits

Author SHA1 Message Date
Slava Pestov
728e97c36d Serialization: Switch serialization to the new function type representation
Instead of serializing the input type of a function type, which is a
TupleType or ParenType, serialize the individual parameters instead.

This means that we no longer need to serialize TupleTypes or
ParenTypes with custom flags, nor do we ever serialize standalone
InOutTypes, so all of that can be removed.
2018-08-10 22:37:36 -07:00
Slava Pestov
f3b207ed67 Serialization: Don't serialize types of various decls
We can recover function, destructor, constructor, enum element
and subscript types from their parameter types and result type
(if present), by calling the AST's various computeType()
methods.

These methods don't do any more work than would be done if
we had deserialized the type and reconstructed it, so let's
just recompute it instead.

Note that we still serialize a ton of function types, due
to XREFs.

With my build configuration, this reduces the size of
Swift.swiftmodule by 237KiB (out of 20MiB).
2018-08-10 22:32:52 -07:00
Slava Pestov
6812fd63b8 Serialization: Remove an old hack
SILFunctions no longer have a GenericParamList, so all of these
circularity and ordering problems are gone.

We *do* deserialize the generic parameters before creating decls
that have them though, so serialize generic parameters as if
their DeclContext was the DeclContext of the owner decl.

This is what we do when we parse generic parameters too; in
both cases, the constructor for the owner decl gives the
generic parameters the right DeclContext.
2018-08-10 18:24:23 -07:00
Slava Pestov
4b258e86e6 AST: Stop setting contextual types on ParamDecls
VarDecl::getType() lazily maps the interface type into context if needed.
2018-08-10 13:33:12 -07:00
Jordan Rose
0e10f89964 Preserve default argument text through serialization (#18579)
This allows us to dump it in the generated interface, though it's
still not syntax-highlighted. This is necessary for textual module
interfaces, but it's also just a longstanding request for Xcode's
"Generated Interface" / "Jump to Definition" feature.

rdar://problem/18675831
2018-08-09 11:06:22 -07:00
John McCall
5f3eaa8feb Fix a couple of oversights relating to modify coroutines. 2018-08-08 19:11:03 -04:00
Jordan Rose
9ebbf2fbaf [Serialization] Remove PARAMETERLIST_ELT node (#18570)
Way back in 6afe77d597 Chris removed the 'Parameter' type that tracked
extra information about parameters, collapsing it into ParamDecl and
making ParameterList "an overblown array of ParamDecl*'s". Do the same
thing for Serialization: push the few fields tracked in
PARAMETERLIST_ELT records down into PARAM_DECL, and then simplify the
PARAMETERLIST record to directly reference its parameters.

No functionality change.
2018-08-08 14:15:47 -07:00
swift-ci
5830e237ff Merge remote-tracking branch 'origin/master' into master-next 2018-07-31 13:29:50 -07:00
Doug Gregor
2860557a77 [Name lookup] Use the declaration-based lookupQualified() where it’s easy.
Switch a number of callers of the Type-based lookupQualified() over to
the newer (and preferred) declaration-based lookupQualified(). These are
the easy ones; NFC.
2018-07-31 10:14:44 -07:00
swift-ci
685b007c3f Merge remote-tracking branch 'origin/master' into master-next 2018-07-23 20:39:45 -07:00
John McCall
7a4aeed570 Implement generalized accessors using yield-once coroutines.
For now, the accessors have been underscored as `_read` and `_modify`.
I'll prepare an evolution proposal for this feature which should allow
us to remove the underscores or, y'know, rename them to `purple` and
`lettuce`.

`_read` accessors do not make any effort yet to avoid copying the
value being yielded.  I'll work on it in follow-up patches.

Opaque accesses to properties and subscripts defined with `_modify`
accessors will use an inefficient `materializeForSet` pattern that
materializes the value to a temporary instead of accessing it in-place.
That will be fixed by migrating to `modify` over `materializeForSet`,
which is next up after the `read` optimizations.

SIL ownership verification doesn't pass yet for the test cases here
because of a general fault in SILGen where borrows can outlive their
borrowed value due to being cleaned up on the general cleanup stack
when the borrowed value is cleaned up on the formal-access stack.
Michael, Andy, and I discussed various ways to fix this, but it seems
clear to me that it's not in any way specific to coroutine accesses.

rdar://35399664
2018-07-23 18:59:58 -04:00
swift-ci
b4bae42909 Merge remote-tracking branch 'origin/master' into master-next 2018-07-21 13:49:33 -07:00
Slava Pestov
bfc4121971 AST: Rework AbstractFunctionDecl construction away from multiple parameter lists
There are two general constructor forms here:

- One took the number of parameter lists, to be filled in later.
  Now, this takes a boolean indicating if there is an implicit
  'self'.

- The other one took the actual parameter lists and filled them
  in right away. This now takes a separate 'self' ParamDecl and
  ParameterList.

Instead of storing the number of parameter lists, an
AbstractFunctionDecl now only needs to store if there is a 'self'
or not.

I've updated most places that construct AbstractFunctionDecls to
properly use these new forms. In the ClangImporter, there is
more code that remains to be untangled, so we continue to build
multiple ParameterLists and unpack them into a ParamDecl and
ParameterList at the last minute.
2018-07-21 07:30:30 -07:00
swift-ci
e2acff2bbc Merge remote-tracking branch 'origin/master' into master-next 2018-07-18 23:08:57 -07:00
Doug Gregor
8f23915334 [Type Checker] Introduce a request for “overridden declarations”.
Introduce a new request kind to capture the computation of the set of
overridden declarations of a given declaration, eliminating the
stateful “setOverriddenDecls()” calls from the type checker.
2018-07-18 14:50:38 -07:00
swift-ci
a792448233 Merge remote-tracking branch 'origin/master' into master-next 2018-07-17 14:09:53 -07:00
Slava Pestov
8d6a55fedb Merge pull request #16655 from davezarzycki/formalize_DeclIsBeingValidatedRAII
[AST] NFC: Formalize Decl validation tracking via RAII
2018-07-17 14:07:53 -07:00
swift-ci
9eb4e3a0a4 Merge remote-tracking branch 'origin/master' into master-next 2018-07-16 18:48:54 -07:00
Slava Pestov
fc80f75273 AST: Create new 'invalid' state for ProtocolConformanceRef 2018-07-16 16:44:27 -07:00
David Zarzycki
b29d2784ed [AST] NFC: Formalize Decl validation tracking via RAII
After this change, RAII ensures that the validation state is accurate as
possible.
2018-07-12 10:30:26 -04:00
swift-ci
decf2b1130 Merge remote-tracking branch 'origin/master' into master-next 2018-07-05 11:49:26 -07:00
John McCall
34b0cbc11d Merge pull request #16237 from davezarzycki/metaprogram_ref_storage_types
[AST] NFC: Enable reference storage type meta-programming
2018-07-05 14:45:38 -04:00
Bob Wilson
a53091ee8a Merge remote-tracking branch 'origin/master' into master-next 2018-07-05 10:57:46 -07:00
Ben Cohen
3add0465d4 Remove redundant generic signature pointer (#17745) 2018-07-05 10:15:33 -07:00
swift-ci
a93ce92de1 Merge remote-tracking branch 'origin/master' into master-next 2018-07-02 20:29:09 -07:00
Doug Gregor
764f14807f [AST] Centralize the storage of the overridden declarations of a declaration.
Several kinds of declarations can override other declarations, but the
computation and storage for these “overridden” declarations was scattered in
at least 3 different places, with different resolution paths. Pull them
all together into two bits of LazySemanticInfo in ValueDecl (“have we computed
overrides?” and “are there any overrides?”), with a side table for the
actual list of overrides.

One side effect here is that the AST can now represent multiple overridden
declarations, although only associated type declarations track this
information.

Start using LazyResolver::resolveOverriddenDecl() more consistently, unifying
it with the separate path we had for associated type overrides. All of this
is staging for a move to the request-evaluator for overridden declaration
computation.
2018-07-02 14:51:28 -07:00
swift-ci
f3b8a3cbaf Merge remote-tracking branch 'origin/master' into master-next 2018-06-30 10:09:20 -07:00
John McCall
f81036202d Merge pull request #17566 from rjmccall/storage-impls
Generalize storage implementations to support generalized accessors
2018-06-30 12:58:33 -04:00
swift-ci
3026500f59 Merge remote-tracking branch 'origin/master' into master-next 2018-06-30 06:29:07 -07:00
David Zarzycki
b61c111f12 [Serialization] NFC: Adopt reference storage type meta-programming macros 2018-06-30 06:44:34 -04:00
John McCall
9bee3cac5a Generalize storage implementations to support generalized accessors.
The storage kind has been replaced with three separate "impl kinds",
one for each of the basic access kinds (read, write, and read/write).
This makes it far easier to mix-and-match implementations of different
accessors, as well as subtleties like implementing both a setter
and an independent read/write operation.

AccessStrategy has become a bit more explicit about how exactly the
access should be implemented.  For example, the accessor-based kinds
now carry the exact accessor intended to be used.  Also, I've shifted
responsibilities slightly between AccessStrategy and AccessSemantics
so that AccessSemantics::Ordinary can be used except in the sorts of
semantic-bypasses that accessor synthesis wants.  This requires
knowing the correct DC of the access when computing the access strategy;
the upshot is that SILGenFunction now needs a DC.

Accessor synthesis has been reworked so that only the declarations are
built immediately; body synthesis can be safely delayed out of the main
decl-checking path.  This caused a large number of ramifications,
especially for lazy properties, and greatly inflated the size of this
patch.  That is... really regrettable.  The impetus for changing this
was necessity: I needed to rework accessor synthesis to end its reliance
on distinctions like Stored vs. StoredWithTrivialAccessors, and those
fixes were exposing serious re-entrancy problems, and fixing that... well.
Breaking the fixes apart at this point would be a serious endeavor.
2018-06-30 05:19:03 -04:00
Slava Pestov
94feb373c8 AST: Remove 'checked inheritance clause' bit from TypeDecl and ExtensionDecl 2018-06-30 00:20:36 -07:00
swift-ci
0305938623 Merge remote-tracking branch 'origin/master' into master-next 2018-06-29 01:29:16 -07:00
Bob Wilson
b254041121 Merge remote-tracking branch 'origin/master' into master-next 2018-06-28 23:23:29 -07:00
Doug Gregor
a9d2e4cb69 [Serialization] Consistently (de-)serialize “isObjC” bit of declarations.
We sometimes serialized the “isObjC” state, and sometimes not. When we did serialize it,
we rarely used the bit for anything. Serialize it for all declarations where it makes
sense, and consistently call setIsObjC() with the deserialized value.
2018-06-28 20:23:08 -07:00
Slava Pestov
5f4f55caf8 AST: Add superclass field to ProtocolDecl 2018-06-28 15:19:20 -07:00
Jordan Rose
2a89d5cd51 Start recovering from missing types in SIL deserialization
Now that @inlinable is a supported feature, we need to handle cases
where a function is inlinable but it references some type that imports
differently in different Swift versions. To start, handle the case
where a SIL function's type is now invalid and therefore the entire
function can't be imported. This doesn't open up anything interesting
yet, but it's a start.

Part of rdar://problem/40899824
2018-06-27 11:38:27 -07:00
swift-ci
8bb9dd9911 Merge remote-tracking branch 'origin/master' into master-next 2018-06-21 13:29:19 -07:00
Jordan Rose
1beed09570 [Serialization] Remove bogus limitation on fast path (#17336)
The meaning of this bit changed way back in 3639343c53, but I forgot
to update this fast path. Thanks to this code falling back to the slow
path if things didn't work out, there wasn't a correctness issue here,
but it might have been doing more work than necessary.
2018-06-21 13:10:03 -07:00
swift-ci
cb0520c595 Merge remote-tracking branch 'origin/master' into master-next 2018-06-20 15:10:55 -07:00
Jordan Rose
6b894154d3 [Serialization] Track whether a cross-reference came from Clang (#17333)
Cross-references are identified by their containing module, with the
assumption that two modules will never have the same name. However, an
overlay has the same name as its underlying Clang module, which means
that there can be two declarations with the same name, the same type,
and the same module name. This is the underlying cause of the
'UIEdgeInsetsZero' problem, but it also affects the CloudKit overlay.

By tracking a bit that just says "this came from Clang", we're able
to resolve otherwise ambiguous cross-references.

(Why didn't we do it this way all along? Because if a declaration
moves from Clang to Swift or vice versa, that would break the
cross-reference. But that's only interesting if the swiftmodule format
is meant to be persistent across changing dependencies, and it looks
like we're moving away from that anyway. It's also a little weird for
SerializedModuleLoader to have special cases for Clang, but this isn't
the first.)

Note that I'm not reverting the UIEdgeInsetsZero workaround here; the
end state will have that coming just from UIKit as originally
described.

rdar://problem/40839486
2018-06-20 14:51:17 -07:00
swift-ci
2a0e83dc0d Merge remote-tracking branch 'origin/master' into master-next 2018-06-18 11:00:19 -07:00
Jordan Rose
05d0a2dfef [Serialization] Mark decls that can never be cross-referenced (#17223)
This allows us to filter them out in cases that would otherwise be
ambiguous. The particular prompting situation looks a lot like the
test case: a protocol, plus a forward-declared class with the same
name. (Normally we ignore forward-declared classes, but SourceKit's
module interface generation feature makes dummy ClassDecls for them
instead.)

https://bugs.swift.org/browse/SR-4851
2018-06-18 10:50:35 -07:00
swift-ci
4538ce9818 Merge remote-tracking branch 'origin/master' into master-next 2018-06-17 15:38:24 -07:00
John McCall
69f4dd1ec9 Generalize accessor storage to preserve the original accessor list.
Only not NFC because it's detectable by source tools.
2018-06-16 18:16:31 -04:00
Bob Wilson
5df3d1f100 Merge remote-tracking branch 'origin/master' into master-next 2018-06-14 20:51:48 -07:00
John McCall
9022b5152f Rename accessor kinds from IsGetter -> IsGet, etc.
Introduce some metaprogramming of accessors and generally prepare
for storing less-structured accessor lists.

NFC except for a change to the serialization format.
2018-06-14 17:08:55 -04:00
Bob Wilson
83f6d9649f Merge pull request #17160 from bob-wilson/llvm-r334399
[master-next] Adjust for VersionTuple moving from clang to llvm.
2018-06-12 16:47:25 -07:00
Bob Wilson
c3e02955bb [master-next] Adjust for VersionTuple moving from clang to llvm.
LLVM r334399 (and related Clang changes) moved clang::VersionTuple to
llvm::VersionTuple. Update Swift to match.

Patch by Jason Molenda.
rdar://problem/41025046
2018-06-12 16:44:11 -07:00
Jordan Rose
bcc1ed29e3 [Serialization] Slightly improve cross-reference failure crash traces (#17148)
Trade a tiny bit of speed in the happy path for a more sensible
result, and make sure to preserve the information about what was being
looked up when a cross-reference turns out to be ambiguous. No
intended functionality change.
2018-06-12 16:25:40 -07:00