Commit Graph

1132 Commits

Author SHA1 Message Date
Jordan Rose
764e2b8ce6 Sink private-file import support down to SerializedASTFile
Implementing it in LoadedFile is nice in theory, but causes a leak in
practice because that type is ASTContext-allocated and usually never
destroyed.

https://bugs.swift.org/browse/SR-11366
2019-08-23 17:40:45 -07:00
Jordan Rose
0742e6ffd4 Merge pull request #26775 from jrose-apple/the-point-of-noreturn
[Serialization] Split ModuleFile fatal and non-fatal errors
2019-08-22 17:16:04 -07:00
Slava Pestov
2dbeeb0d3f AST: Make SubstFlags::UseErrorType the default behavior
We've fixed a number of bugs recently where callers did not expect
to get a null Type out of subst(). This occurs particularly often
in SourceKit, where the input AST is often invalid and the types
resulting from substitution are mostly used for display.

Let's fix all these potential problems in one fell swoop by changing
subst() to always return a Type, possibly one containing ErrorTypes.

Only a couple of places depended on the old behavior, and they were
easy enough to change from checking for a null Type to checking if
the result responds with true to hasError().

Also while we're at it, simplify a few call sites of subst().
2019-08-22 01:07:50 -04:00
Jordan Rose
4497a0c69a [Serialization] Split ModuleFile fatal and non-fatal errors
`ModuleFile::error` was being used both for errors of initial parse
and configuration (non-fatal) and format errors during actual
deserialization (fatal, indicating a corrupted module). Split out the
latter to `ModuleFile::fatal()` (to go with the existing
`ModuleFile::fatal(llvm::Error)`) and be more consistent about
explicitly setting statuses for the former.

Since 'fatal()' is always fatal, this also allows deleting dummy
recovery code that would never be used in practice.
2019-08-21 21:20:12 -07:00
Jordan Rose
847dd2f28f [Serialization] Simplify NDEBUG logic skipping a record 2019-08-21 08:46:31 -07:00
Jordan Rose
83e5d544d0 [Serialization] Rename helper struct to match its use
Once upon a time this /was/ an OffsetAndKind pair, but it's been a
DeclAndOffset pair since my last refactoring.

No functionality change.
2019-08-20 20:21:12 -07:00
Jordan Rose
57b1ea8d80 [Serialization] Remove "delayed actions" support
Previously, cycle-breaking logic would delay certain actions until all
re-entrant deserialization was complete for a particular module. That
hasn't been used in a while, though, now that the AST itself supports
more laziness, so let's take it out.

No functionality change; this really was unused.
2019-08-20 20:02:12 -07:00
Slava Pestov
62f18a52c0 Sema: Move attribute checking to typeCheckDecl() 2019-08-20 14:47:52 -04:00
Varun Gandhi
af47110858 Merge pull request #26690 from varungandhi-apple/vg-refactor-validateExtension
Avoid setting the extendedType before and after computing the generic signature.
2019-08-19 14:04:03 -07:00
Jordan Rose
94d1e5efe6 Avoid reserved names in C++ code: "__Consuming" (#26720)
Double-underscored names are reserved for the C++ "implementation"
(language and standard library). Even though "__Consuming" isn't
likely to be part of the C++ standard any time soon, we should follow
the rules.

Note that the API digester will continue to use the string
"__Consuming" for now, even though the underscores aren't really
significant, to avoid invalidating existing dumps.

No functionality change.
2019-08-19 13:06:53 -07:00
Varun Gandhi
c85eae1efb Get rid of the second call to setType() in validateExtension().
This means that we no longer have the invariant that the extendedType always
contains the generic parameters. So we need to fix the assertions/test cases
for it.
2019-08-19 11:37:18 -07:00
Slava Pestov
1c3ac86796 AST: Banish OptionalTypeKind to ClangImporter.h
The only place this was used in Decl.h was the failability kind of a
constructor.

I decided to replace this with a boolean isFailable() bit. Now that
we have isImplicitlyUnwrappedOptional(), it seems to make more sense
to not have ConstructorDecl represent redundant information which
might not be internally consistent.

Most callers of getFailability() actually only care if the result is
failable or not; the few callers that care about it being IUO can
check isImplicitlyUnwrappedOptional() as well.
2019-08-15 18:41:42 -04:00
Slava Pestov
19d283d9dc AST: Replace ImplicitlyUnwrappedOptionalAttr with Decl::{is,set}ImplicitlyUnwrappedOptional() 2019-08-15 18:41:41 -04:00
Harlan Haskins
114b039481 [Serialization] Teach serialization to get a generic signature from opaque types
Previously, if we had an XREF to an opaque type, we would fail trying to
get the generic signature from that type.

Fixes rdar://53958358
2019-08-12 15:08:09 -07:00
Slava Pestov
0063f158be AST: Request-ify synthesis of the implicit destructor 2019-08-09 19:08:47 -04:00
Slava Pestov
d3f65e7b4b AST: Remove SubscriptDecl::isSettable() 2019-07-31 21:26:02 -04:00
Slava Pestov
e41760e44f Sema: Add request to compute if an AccessorDecl is transparent
Implicit accessors are sometimes transparent for performance reasons.
Previously this was done in Sema by maybeMarkTransparent(), which would
add a TransparentAttr. Replace this with a request.
2019-07-31 14:54:57 -04:00
Jordan Rose
b30c8ef4a4 [Serialization] Fix off-by-one error in enum dependency analysis (#26323)
No test case because it's very hard to control the dependency list for
particular enum. All of the existing tests are pretty minimal, so if
it wasn't failing already the first type is probably consistently
something innocuous like the enum itself, but still.

Noticed by inspection.
2019-07-30 18:33:45 -07:00
Slava Pestov
d3cd9c2d7b Serialization: Track vtable slots for VarDecl and SubscriptDecl
Once accessors are no longer listed as members of their parent context,
a failure to deserialize a VarDecl or SubscriptDecl needs to create a
MissingMemberDecl with the total number of vtable entries expected for
all of the accessors of the storage.

Note that until the accessor change actually lands, we always compute
the expected number of vtable entries as 0.
2019-07-30 15:44:53 -04:00
Holly Borla
709efbc52c Sema: implement getInitKind using a request evaluator.
Add the request `InitKind` to lazily compute the kind of an initializer
declaration.
2019-07-26 15:55:09 -07:00
Jordan Rose
28b3d8e0a7 [Serialization] Preserve whether a raw value is explicit (#26324)
...which allows the AST printer to correctly choose whether to print
it, which means it can be printed in a module interface in a non-WMO
build, which is necessary for @objc enums to have a correct run-time
representation when clients use that interface.

rdar://problem/53469608
2019-07-24 10:25:42 -07:00
Holly Borla
10a4e3ef41 Merge pull request #26278 from hborla/existential-type-supported-request
Sema: implement `existentialTypeSupported` using a request evaluator.
2019-07-23 14:05:35 -07:00
Slava Pestov
4eec522578 Sema: Fix inheritance of @requires_stored_property_inits
Previously we would copy this attribute from a superclass to the
subclass when validating a subclass. However, this is only correct
if the superclass is always guaranteed to have been validated
before the subclass.

Indeed, it appears this assumption is no longer true, so we would
sometimes lose track of the attribute, which would result in SILGen
failing to emit the ivar initializer entry point.

Instead, check for the attribute as part of the superclass walk
in checkAncestry(), ensuring the result is always up to date, correct,
and cached.

As a follow-up, we should also convert checkAncestry() into a
request, but I'm not doing that here to keep the fix short.

Fixes <rdar://problem/50845438>.
2019-07-23 12:23:27 -04:00
Slava Pestov
454281b226 AST: Split off StorageImplInfo from AbstractStorageDecl::AccessorRecord
We want to compute the former independently of the latter.
It's only 16 bits so storing it inside the Decl is fine;
it also allows us to eliminate the 'compact' representation
where an AbstractStorageDecl without an accessor record is
assumed to be stored.
2019-07-22 20:19:09 -04:00
Slava Pestov
a532a325e1 AST: Move a few methods from VarDecl down to ParamDecl 2019-07-22 20:19:09 -04:00
Holly Borla
9f19597f73 Sema: implement existentialTypeSupported using a request evaluator.
Add the request `ExistentialTypeSupportedRequest` to lazily determine
if we are allowed to refer to an existential type conforming to a
protocol.
2019-07-22 15:35:10 -07:00
Holly Borla
71fb2629ac Sema: implement requiresClass using a request evaluator.
Add the request `ProtocolRequiresClassRequest` to lazily determine if a
`ProtocolDecl` requires conforming types to be a class.

Note that using the request evaluator to compute `requiresClass` introduces
cycle errors for protocol declarations, where this computation didn't
previously emit diagnostics. For now, we'll allow duplicate diagnostics in this
case, with the eventual goal of removing explicitly checking for cycles
via `checkCircularity` (instead letting the request evaluator handle cycle
diagnostics).
2019-07-17 16:04:24 -07:00
Slava Pestov
a347dce314 Serialization: Actually set VarDecl::isLazyStorageProperty() when deserializing 2019-07-16 14:26:54 -04:00
Jordan Rose
bff83f63eb [Serialization] Drop protocols whose requirements can't be loaded (#25809)
If a protocol inherits from a protocol that can't be loaded, drop it
entirely. Similarly, if it has requirements that reference types in
other modules that can't be loaded, drop the protocol entirely---at
least for now, we don't want to deal with a protocol that exists but
has the wrong requirement signature. That "in other modules" isn't
perfect, but it avoids cases where two protocols depend on each other.
Unfortunately, it means the compiler may still get into exactly the
situation above if a protocol depends on another protocol in the same
module, and /that/ protocol can't be loaded for some other reason. But
it's progress.

This comes up when referencing implementation-only-imported protocols
from non-public protocols, but is also just general deserialization
recovery goodness.

rdar://problem/52141347
2019-06-28 20:03:37 -07:00
Jordan Rose
2fae37824e [Serialization] Stop serializing protocols' generic environments
...they can be trivially recreated.
2019-06-27 14:53:13 -07:00
Jordan Rose
cce8d2fde0 [Serialization] Deserialize protocol requirement signatures lazily
Always good to do less work, and it's a stepping stone towards
recovering from trying to deserialize a protocol with missing
requirements.
2019-06-27 14:52:47 -07:00
Doug Gregor
db5440bdef [SE-0258] Rename wrapperValue to projectedValue. 2019-06-26 07:39:01 -07:00
Doug Gregor
7bb01c743b [SE-0258] Promote projection variables ($foo) to the original property access
When the outermost property wrapper associated with a property has a
`wrapperValue`, create the projection property (with the `$` prefix)
at the same access level as the original property. This puts the
wrapped-value interface and the projection interface at the same level.

The newly-introduced @_projectionValueProperty attribute is implicitly
created to establish the link between the original property and the
projection value within module interfaces, where both properties will
be explicitly written out.
2019-06-26 07:39:01 -07:00
Slava Pestov
8518fc2e4e AST: Remove FuncDecl::hasDynamicSelf() 2019-06-26 01:12:27 -04:00
Slava Pestov
1e1e812768 Sema: Use a request to create lazy property backing storage 2019-06-19 22:12:55 -04:00
Harlan Haskins
d29e6be3e4 Merge pull request #25551 from harlanhaskins/i-saw-lookup-ignoring-super-clause
[Sema] Compute superclass of deserialized protocols via generic signature
2019-06-19 14:02:37 -07:00
Joe Groff
e71bfd38c7 Merge pull request #25600 from jckarter/opaque-xref-extension-module
Serialization: Deserialize opaque type xrefs from the right extension module.
2019-06-19 13:17:02 -07:00
Joe Groff
70aba4d1fe Serialization: Deserialize opaque type xrefs from the right extension module.
When deserializing an opaque type xref inside an extension context, we were looking
incorrectly in the base module of the type being extended, rather than in the module
of the extension, where the opaque type would really be. Fixes rdar://problem/51775500.

This includes a small refactoring of OpaqueTypeDecl deserialization to break the inevitable
cycle between deserializing the namingDecl, and the namingDecl turning around and re-
deserializing its opaque return type. This is NFC but avoids some unnecessary work.
2019-06-19 09:46:49 -07:00
Harlan Haskins
d23101d337 [Sema] Compute superclass of deserialized protocols via generic signature
We don't need to serialize the protocol's superclass, we can compute it from the
generic signature. Previously, we would drop the superclass while
serializing because we didn't check the generic signature in
SuperclassTypeRequest, which would cause us to cache `NULL` when we
called `setSuperclass` for a protocol with a superclass constraint.

Fixes rdar://50526401
2019-06-18 16:38:09 -07:00
Jordan Rose
2d3872a076 [Serialization] If an override is dynamic, missing the base decl is OK
...specifically `@objc dynamic`, that is. This is one case where we
/know/ that the override does not depend on the base in any way---any
attributes have already been propagated down, and there's no vtable
entry. This is especially important for properties, which have no
recovery if their accessors can't be deserialized.

rdar://50827914
2019-06-18 13:46:49 -07:00
Doug Gregor
c02ecf9859 [SE-0258] Rename to Property Wrappers 2019-05-29 22:17:50 -07:00
Slava Pestov
5b2211dde7 Serialization: Recover from failure to deserialize inheritance clause entries
... by dropping them.

Fixes <rdar://problem/50473619>.
2019-05-20 17:38:30 -04: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
6cca050fd9 [Serialization] Retire "shadowed module" in favor of "underlying" (#24711)
Similar to 517f5d6b6a, the "shadowed" terminology didn't end up
describing the most common use of the feature; there is pretty much no
intended case where a Swift module shadows a Clang module without also
re-exporting it. Switch to "underlying", which was already in use in a
few places, and which better parallels "overlay".

No intended functionality change.
2019-05-13 10:20:03 -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
Slava Pestov
fa12d85739 AST: Clean up associated type default representation a bit 2019-04-26 21:47:02 -04:00
Nathan Hawes
1a2680a52f Merge pull request #24212 from nathawes/overriding-convenience-init-module-interface
[Deserialization] Don't add an OverrideAttr if the 'overridden' decl is a convenience init when deserializing
2019-04-24 13:58:16 -07:00
Nathan Hawes
2ae7315adf [Serialization] Don't add an OverrideAttr if the 'overridden' decl is a convenience init when deserializing 2019-04-22 18:08:03 -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