Commit Graph

1290 Commits

Author SHA1 Message Date
Jordan Rose
6296a0e21a [Serialization] Make sure we handle all decl kinds
...well, at least a little more than before. This /still/ isn't as
strong as the switch that used to be here because a subtype of an
existing Decl or Type won't show up, but that's probably still worth
the maintainability (and backtrace) tradeoff.
2019-05-23 21:09:48 -07:00
Jordan Rose
dc1653fe63 [Serialization] Factor out a helper for types that wrap other types
...and carry no other information (besides their record code).
No functionality change.
2019-05-23 21:06:14 -07:00
Jordan Rose
f932eafa01 [Serialization] Simplify metatype and function type serialization
No functionality change.
2019-05-23 21:06:14 -07:00
Jordan Rose
f89358fc5c [Serialization] Factor TypeSerializer out of writeType
Like the recent change for DeclSerializer. No functionality change,
just making it easier to read.
2019-05-23 21:06:14 -07:00
Jordan Rose
0a34fe5487 [Serialization] Move a bunch of helpers to DeclSerializer
...and off of the main Serializer class. No functionality change.
2019-05-22 18:58:53 -07:00
Jordan Rose
94712186a8 [Serialization] Move attribute serialization into DeclSerializer 2019-05-22 18:58:52 -07:00
Jordan Rose
eb4b4ecd0d [Serialization] Push more of writeDecl into DeclSerializer
No functionality change.
2019-05-22 18:58:52 -07:00
Jordan Rose
96fcfbf016 [Serialization] Factor out common code for {Pre,Post}fixOperatorDecl 2019-05-22 18:58:52 -07:00
Jordan Rose
21b3766aa3 [Serialization] Finish factoring the switch out to DeclSerializer 2019-05-22 18:58:49 -07:00
Jordan Rose
6ea9cd7165 [Serialization] Start splitting up Decl serialization using a visitor
There's a big switch now; separate functions will make this a little
easier to read. The writing side of f637c754.
2019-05-22 18:56:36 -07:00
Jordan Rose
96e8d56878 [Serialization] Add recovery for structs with non-loadable constraints
That is, if a struct's generic requirements can't be deserialized,
drop the struct. This is the same logic that's already in play for
enums and (as of the previous commit) classes, so it should be pretty
well tested by now. (Hence the sole test I'm adding here, snuck into
superclass.swift because it's a superclass /constraint/ being tested.)

I don't know of any outstanding issues caused by this, but it was
weird to have it for enums and classes but not structs, so here we
are.
2019-05-17 10:25:01 -07:00
Jordan Rose
ff7c6f6702 [Serialization] Drop a class if the superclass can't be found
...instead of crashing. Also drop the class if its generic
requirements depend on a type that can't be loaded (instead of
crashing).

rdar://problem/50125674
2019-05-17 10:25:01 -07:00
Jordan Rose
c506747a9c [Serialization] Drop inherited conformances on classes (#23347)
These can be recreated if needed in a client library. To do this, I've
added a new ConformanceLookupKind::NonInherited, which can also be
used elsewhere in the project where we're already filtering out
inherited conformances some other way.

Note that this doesn't drop inherited conformances from the entire
serialized interface, just from the list that a class explicitly
declares. They still get referenced sometimes.

rdar://problem/50541451 and possibly others
2019-05-13 13:41:10 -07:00
Alexis Laferrière
862432fd1b Explicitly request to createGenericParamsIfMissing as it will be lazy
Computing the requirement signature created the generic params as
a side effect. Making getRequirementSignature lazy means that users
of the generic params must make sure they are created before use.
2019-05-08 13:54:03 -07:00
Jordan Rose
6720a7cb74 Merge branch 'master' into artiodactyla 2019-05-06 09:32:56 -07:00
Doug Gregor
7092be6a28 [Property delegates] (De-)serialize property delegates attached to properties
Serialize the relationship between a property that has an attached delegate
and its backing variable, so deserialization can reestablish that link.

Fixes rdar://problem/50447022.
2019-05-05 21:44:54 -07:00
Jordan Rose
b3c5a68acf [Serialization] Reduce file size by splitting dep dirnames from basenames
Dependency tracking for cached compiled modules (compiled from
swiftinterfaces) can lead to a high percentage of the module being
SDK-relative paths when -track-system-dependencies is on. Cut down on
this by storing directory names in a separate record that gets
referenced from each file dependency. (Since a lot of per-file
dependencies are header files in a common directory, this is a win.)

We can do something more clever in the future, but this is a
reasonable start for, say, the overlays.

rdar://problem/50449802
2019-05-04 10:47:46 -07:00
Doug Gregor
e29469b9c0 [Opaque result types] Fix mangling issues with opaque result types.
Fix a trio of issues involving mangling for opaque result types:
* Symbolic references to opaque type descriptors are not substitutions
* Mangle protocol extension contexts correctly
* Mangle generic arguments for opaque result types of generic functions

The (de-)serialization of generic parameter lists for opaque type
declarations is important for the last bullet, to ensure that the
mangling of generic arguments of opaque result types works across
module boundaries.

Fixes the rest of rdar://problem/50038754.
2019-04-22 17:10:45 -07:00
adrian-prantl
f75dea49df Merge pull request #23910 from adrian-prantl/49751363
Record parseable interface imports in the debug info.
2019-04-19 14:23:57 -07:00
Alexis Laferrière
007fbb6ebd Merge pull request #23932 from xymus/IsFinalRequest
Sema: implement `isFinal` using a request evaluator
2019-04-19 13:02:07 -07:00
Joe Groff
5215290f25 Serialization: Cross-reference opaque return types by mangled name. rdar://problem/50005972 2019-04-18 14:41:26 -07:00
Joe Groff
b57f35220e Serialize opaque return type of var/subscript decls. 2019-04-17 14:46:22 -07:00
Joe Groff
399332b75b Parsable interface and type reconstruction support for opaque types.
When printing a swiftinterface, represent opaque result types using an attribute that refers to
the mangled name of the defining decl for the opaque type. To turn this back into a reference
to the right decl's implicit OpaqueTypeDecl, use type reconstruction. Since type reconstruction
doesn't normally concern itself with non-type decls, set up a lookup table in SourceFiles and
ModuleFiles to let us handle the mapping from mangled name to opaque type decl in type
reconstruction.

(Since we're invoking type reconstruction during type checking, when the module hasn't yet been
fully validated, we need to plumb a LazyResolver into the ASTBuilder in an unsightly way. Maybe
there's a better way to do this... Longer term, at least, this surface design gives space for
doing things more the right way--a more request-ified decl validator ought to be able to naturally
lazily service this request without the LazyResolver reference, and if type reconstruction in
the future learns how to reconstruct non-type decls, then the lookup tables can go away.)
2019-04-17 14:46:22 -07:00
Joe Groff
2d19110e38 Serialization: Serialize opaque types and their decls. 2019-04-17 14:43:32 -07:00
Joe Groff
a419754fe9 Support nested types on opaque archetypes (and maybe opened ones). 2019-04-17 14:43:32 -07:00
Joe Groff
dd2b51d6dc Add an OpaqueTypeArchetypeType subclass. 2019-04-17 14:43:32 -07:00
Joe Groff
71912bbfd6 AST: Represent OpaqueTypeDecls.
To represent the abstracted interface of an opaque type, we need a generic signature that refines
the outer context generic signature with an additional generic parameter representing the underlying
type and its exposed constraints. Opaque types also need to be keyed by their originating decl, so
that we can treat values of the same opaque type as the same. When we check a FuncDecl with an
opaque type specified as its return type, create an OpaqueTypeDecl and associate it with the
originating decl. (A representation for *types* derived from the opaque decl will come next.)
2019-04-17 14:43:32 -07:00
Alexis Laferrière
ddef82ab4a Serialization: manually write ‘FinalAttr’ if ‘isFinal’ 2019-04-17 09:17:59 -07:00
Slava Pestov
39a22f3d6a AST: Remove ParameterTypeFlags::Escaping
Escapingness is a property of the type of a value, not a property of a function
parameter. Having it as a separate parameter flag just meant one more piece of
state that could get out of sync and cause weird problems.

Instead, always look at the noescape bit in a function type as the canonical
source of truth.

This does mean that '@escaping' is now printed in a few diagnostics where it was
not printed before; we can investigate these as separate issues, but it is
correct to print it there because the function types in question are, in fact,
escaping.

Fixes <https://bugs.swift.org/browse/SR-10256>, <rdar://problem/49522774>.
2019-04-15 00:25:03 -04:00
Adrian Prantl
8d03cb7a61 Record parseable interface imports in the debug info.
When a Swift module built with debug info imports a library without
debug info from a textual interface, the textual interface is
necessary to reconstruct types defined in the library's interface.  By
recording the Swift interface files in DWARF dsymutil can collect them
and LLDB can find them.

rdar://problem/49751363
2019-04-11 14:50:07 -07:00
Nathan Hawes
58d0ee0888 [ParseableInterface] Distinguish SDK and non-SDK dependencies
This allows the SDK to be relocated without automatically resulting in a
rebuild.

Based on an old patch from Jordan Rose.
2019-04-03 06:35:11 -07:00
Slava Pestov
8292cbe3b3 AST: Remove 'default argument resilience expansion'
This was a Swift 3 mode holdover.
2019-04-02 20:37:01 -04:00
Brent Royal-Gordon
972eda2316 [NFC] AST-level support for static subscripts
* Moves the IsStatic flag from VarDecl to AbstractStorageDecl.
* Adds a StaticSubscriptKind to SubscriptDecl.
* Updates serialization for these changes.
* Updates SubscriptDecl constructor call sites for these changes.
2019-04-01 18:04:00 -07:00
Doug Gregor
a848d12665 Parse unknown attributes as "custom" attributes.
Parse custom attributes with the grammar:

```
'@' type-identifier expr-paren?
```
2019-03-29 23:10:36 -07:00
Jordan Rose
0ba6c495ba Add @_implementationOnly
This is an attribute that gets put on an import in library FooKit to
keep it from being a requirement to import FooKit. It's not checked at
all, meaning that in this form it is up to the author of FooKit to
make sure nothing in its API or ABI depends on the implementation-only
dependency. There's also no debugging support here (debugging FooKit
/should/ import the implementation-only dependency if it's present).

The goal is to get to a point where it /can/ be checked, i.e. FooKit
developers are prevented from writing code that would rely on FooKit's
implementation-only dependency being present when compiling clients of
FooKit. But right now it's not.

rdar://problem/48985979
2019-03-28 15:57:53 -07:00
Jordan Rose
9ed3fe061d Change ModuleDecl::getImportedModules to take an option set
...in preparation for me adding a third kind of import, making the
existing "All" kind a problem. NFC, except that I did rewrite the
ClangModuleUnit implementation of getImportedModules to be simpler!
2019-03-28 14:44:41 -07:00
Ted Kremenek
fe215edb9b Merge pull request #19743 from Azoy/smarter-struct-init
[Sema] Synthesize default values for memberwise init
2019-03-25 17:31:01 -07:00
Harlan Haskins
714a2b4044 Merge pull request #23173 from harlanhaskins/never-trust-the-system
[ParseableInterface] Serialize module into buffer and load from it
2019-03-22 21:37:49 -07:00
Harlan Haskins
f4da34f363 [ParseableInterface] Only open module buffers once while loading
In addition to being wasteful, this is a correctness issue -- the
compiler should only ever have one view of this file, and it should not
read a potentially different file after validating dependencies.

rdar://48654608
2019-03-21 18:17:07 -07:00
Jordan Rose
93616cd49e Push Clang's "exported module name" notion up to Swift's FileUnit
It's a pretty obscure feature (and one we wish we didn't need), but
sometimes API is initially exposed through one module in order to
build another one, and we want the canonical presented name to be
something else. Push this concept into Swift's AST properly so that
other parts of the compiler stop having to know that this is a
Clang-specific special case.

No functionality change in this commit; will be used in the next
commit.
2019-03-21 15:16:21 -07:00
Azoy
6f7d20b99e Synthesize default values for memberwise init
Introduce stored property default argument kind

Fix indent

Assign nil to optionals with no initializers

Don't emit generator for stored property default arg

Fix problem with rebase

Indentation

Serialize stored property default arg text

Fix some tests

Add missing constructor in test

Print stored property's initializer expression

cleanups

preserve switch

complete_constructor

formatting

fix conflict
2019-03-13 18:57:36 -05:00
Harlan Haskins
7d71579950 [Serialization] Allow either hash-based or mtime-based deps
Add a bit to the module to determine whether the dependency’s stored bit pattern is a hash or an mtime.

Prebuilt modules store a hash of their dependencies because we can’t be sure their dependencies will have the same modtime as when they were built.
2019-03-05 11:46:21 -08:00
Arnold Schwaighofer
f0492690d1 public storage with private accessor is also a problem 2019-03-05 07:46:39 -08:00
Arnold Schwaighofer
5d160b68a5 Fix compile error 2019-03-04 13:26:38 -08:00
Arnold Schwaighofer
1719f0cdf1 Serialization: Also serialize the filename for internal storage decls with private accessors
If a value decl is internal hasTestableOrPrivateImport will succeed (or
fail) without looking at the filename. However this breaks when we query
an internal storage decl with private formal access for a private
setter: the query would fail because no filename was serialized for the
decl (we only serialize filenames for private decls). So in the special
case of a internal storage with private accessor also serialize the
filename.

rdar://48516545
2019-03-04 13:12:39 -08:00
Joe Groff
64488b19f9 Serialization: Rework serialization of nested archetypes.
Explicitly serialize the parent archetype so that it can be any kind of root archetype.
2019-02-20 12:53:18 -08:00
Joe Groff
0cfca9496a Give opened archetypes a generic environment.
And maybe allow nested types to live on them.
2019-02-20 12:52:48 -08:00
Doug Gregor
d31ef61a28 Eliminate "sorting" of DeclContext-local protocols / conformances.
Sorting of DeclContext-local protocols and conformances shouldn't ever
be necessary, because the underlying data structures that produce
these lists should be deterministic. Sorting can hide any
non-determinism, so stop doing it and we can address the underlying
nondeterminism.
2019-02-15 14:16:48 -08:00
Jordan Rose
2301bff548 Add some defensive checks against invalid serialization (#22466)
If a non-serializable Decl or Type makes it into serialization logic
in a release build, an invalid swiftmodule might be produced silently,
leading to crashes in clients. Try to catch this with an on-in-Release
check that /something/ was serialized. (This is my best guess at how
rdar://problem/47459323 occurred.)
2019-02-08 09:04:08 -08:00
Harlan Haskins
6f94720b01 [Serialization] Use mtime instead of hash for file dependencies
Hashing the contents of the interface files is overkill. In practice, size and last modification time are enough to determine if a file has changed on disk, and therefore should be rebuilt.
2019-02-04 13:26:38 -08:00