Commit Graph

572 Commits

Author SHA1 Message Date
swift_jenkins
999d033f4f Merge remote-tracking branch 'origin/master' into master-next 2020-04-16 15:57:40 -07:00
Alexis Laferrière
2fbc063b2e [Serialization] Note the misc version field of modules on deser. failures
This added information will hopefully help us understand hard to
reproduce deserialization failures.
2020-04-16 13:50:11 -07:00
Doug Gregor
6f46830bc4 [Serialization] Require module files to match on environment, too.
This prevents mixing simulator and non-simulator modules.
2020-04-16 11:05:15 -07:00
swift_jenkins
7d10d9ae85 Merge remote-tracking branch 'origin/master' into master-next 2020-04-10 20:40:58 -07:00
Slava Pestov
43ee8ae282 Serialization: Implement LocalDeclTableInfo::GetExternalKey()
This allows iterating over serialized decl tables, which is useful
for debugging.
2020-04-10 15:05:54 -04:00
Alex Langford
c04b6b6e32 More StringRef -> std::string explicit conversions 2020-03-27 16:14:45 -07:00
Hamish Knight
6f212634c8 Add getOperatorDecls to FileUnit and ModuleDecl
Query the SourceLookupCache for the operator decls,
and use ModuleDecl::getOperatorDecls for both
frontend stats and to clean up some code
completion logic.

In addition, this commit switches getPrecedenceGroups
over to querying SourceLookupCache.
2020-03-27 09:44:55 -07:00
Dan Zheng
28315487dc [AutoDiff upstream] Serialize derivative function configurations. (#30672)
Serialize derivative function configurations per module.

`@differentiable` and `@derivative` attributes register derivatives for
`AbstractFunctionDecl`s for a particular "derivative function configuration":
parameter indices and dervative generic signature.

To find `@derivative` functions registered in other Swift modules, derivative
function configurations must be serialized per module. When configurations for
a `AbstractFunctionDecl` are requested, all configurations from imported
modules are deserialized. This module serialization technique has precedent: it
is used for protocol conformances (e.g. extension declarations for a nominal
type) and Obj-C members for a class type.

Add `AbstractFunctionDecl::getDerivativeFunctionConfigurations` entry point
for accessing derivative function configurations.

In the differentiation transform: use
`AbstractFunctionDecl::getDerivativeFunctionConfigurations` to implement
`findMinimalDerivativeConfiguration` for canonical derivative function
configuration lookup, replacing `getMinimalASTDifferentiableAttr`.

Resolves TF-1100.
2020-03-27 06:40:27 -07:00
Hamish Knight
a502246f34 [AST] Add OperatorFixity
Use this instead of DeclKind in a few places.
2020-03-23 09:17:58 -07:00
AG
93d700001a Merge pull request #29874 from bitjammer/acgarland/rdar-58339492-sg-source-locations
SymbolGraph: Serialize source locations and doc comment ranges
2020-02-27 15:35:57 -08:00
Alexis Laferrière
0e7029dfb5 Use "SPI group" for the name used in an @_spi attribute 2020-02-19 14:18:11 -08:00
Alexis Laferrière
6a5a858408 [SPI] Serialize SPI attributes on imports 2020-02-19 14:17:14 -08:00
Alexis Laferrière
501f458879 [AST] Intro service lookupImportedSPIs to find direct SPI imports of a module 2020-02-19 14:17:14 -08:00
Brent Royal-Gordon
e248f82773 Add support for loading cross-import files 2020-02-18 11:06:12 -08:00
Ashley Garland
be77d57121 SymbolGraph: Serialize decl and raw comment locations
- Add DocRangesLayout to the `.swiftsourceinfo`.
  This is a blob containing an array of `SingleRawComment`
  source locations.

- Add DocLocWriter for serializing `SingleRawComment` locs into the
  `DocLocsLayout` buffer.
  Serialize start line, start column, and length of `SingleRawComment`
  pieces in `.swiftsourceinfo`

- Read doc locs when loading basic declaration locs from a ModuleFile.
  - Load `DOC_LOCS` blob into ModuleFile::DocLocsData
  - Reconstitute RawComment ranges when available from .swiftsourceinfo

- Allow requesting serialized raw comment if available

rdar://problem/58339492
2020-02-17 16:20:59 -08:00
Slava Pestov
0b502d8c84 AST: loadNamedMembers() never fails
This allows us to simplify lookupDirect() a fair bit as well.
2020-02-12 18:32:46 -05:00
Slava Pestov
d5cc01da0c Serialization: Don't fail out of loadNamedMembers()
This cleanup exposed a problem with deserialization recovery and
property wrappers. If deserializing a property backed by a wrapper
failed, the lazy member lookup would fail, but subsequently a
loadAllMembers() call would still load the property.

This behavior is actually incorrect, because silently dropping a
stored property of a @frozen struct can result in miscompiles.
I've filed rdar://59403542 and rdar://59403617 to track fixing this.

In the meantime, I've tweaked the logic a bit to preserve the old
behavior.
2020-02-12 18:32:46 -05:00
John McCall
faee21b626 Implement Swift serialization and deserialization of Clang types.
As part of this, we have to change the type export rules to
prevent `@convention(c)` function types from being used in
exported interfaces if they aren't serializable.  This is a
more conservative version of the original rule I had, which
was to import such function-pointer types as opaque pointers.
That rule would've completely prevented importing function-pointer
types defined in bridging headers and so simply doesn't work,
so we're left trying to catch the unsupportable cases
retroactively.  This has the unfortunate consequence that we
can't necessarily serialize the internal state of the compiler,
but that was already true due to normal type uses of aggregate
types from bridging headers; if we can teach the compiler to
reliably serialize such types, we should be able to use the
same mechanisms for function types.

This PR doesn't flip the switch to use Clang function types
by default, so many of the clang-function-type-serialization
FIXMEs are still in place.
2020-02-06 22:09:00 -05:00
Kita, Maksim
ea6a2dc094 SR-11889: Fixed code review issues
1. Updated Located field names with Pascal Case
2. Updated Located constuctor
3. Formatted lines with more than 80 symbols
2019-12-20 17:18:59 +03:00
Kita, Maksim
b7cb3b67bf SR-11889: Using Located<T> instead of std::pair<SourceLoc, T> 2019-12-20 17:18:58 +03:00
Brent Royal-Gordon
6a8598a99c [NFC] Remove DeclNameRef staging calls 2019-12-11 00:55:18 -08:00
Brent Royal-Gordon
da88512eda [NFC] Take DeclNameRef in UnqualifiedLookup and lookupQualified() 2019-12-11 00:55:17 -08:00
Adrian Prantl
bdc1eec983 Use the same alignment for writing and readin .swift_ast section contents.
This fixes a bug that made it impossible to read any subsequent Swift modules
out of a .swift_ast section a previous section had a size divisible by 4.

rdar://problem/57110020
2019-12-04 14:39:12 -08:00
Alexis Laferrière
e9abba2eab [Serialization] Filter Decl to deserialize by their attributes
Add an alternative to getTopLevelDecls and getDeclChecked to limit which
decls are deserialized by first looking at their attributes. If the
attributes are accepted by a function passed as argument the decl is
fully deserialized, otherwise it is ignored.

The filter is included in the signature of existing functions in the
Serilalization services, but I’ve added new methods for it in FileUnit
and its subclasses to leave existing implementations untouched.
2019-11-21 10:06:37 -08:00
JF Bastien
e56e311a23 Fix Swift following bitstream reader API update (#25845)
* Fix Swift following bitstream reader API update

Upstream change in rL364464 broke downstream Swift.

(cherry picked from commit 50de105bf1)

 Conflicts:
	lib/Serialization/Deserialization.cpp
	lib/Serialization/ModuleFile.cpp
	tools/driver/modulewrap_main.cpp
2019-11-12 10:46:07 -08:00
Xi Ge
0abcc1db40 SerializeLoc: address Jordan's previous code review comments 2019-10-22 18:35:55 -07:00
Xi Ge
014f863546 SerializeLoc: address more comments from Jordan. NFC 2019-10-09 15:29:52 -07:00
Xi Ge
5c092e7988 SerializeLoc: use decl_locs_block consistently. NFC 2019-10-09 15:29:52 -07:00
Xi Ge
dd33540231 AST: rename printDeclUSRForModuleDoc to printDeclUSR. NFC 2019-10-09 15:29:52 -07:00
Xi Ge
c9647bb02e SerializeLoc: remove NameLoc entry in the serialized format
Having both Loc and NameLoc fields seems to be redundant.
2019-10-09 15:29:52 -07:00
Xi Ge
8293bdc9e9 SerilizeLoc: refactor table structures per Jordan's comments
After this change, we only use one single hash table for USR to USR id
mapping. The basic source locations are an array of fixed length
records that could be retrieved by using the USR id since each
USR id is guaranteed to be associated with one basic location entry.

The source file paths are refactored to a blob of 0-terminated strings.
Decl locations use offset in this blob to refer to the source file path
where the decl was defined.
2019-10-09 15:29:52 -07:00
Xi Ge
adb9e1d42c SerializeLoc: add some comments about record structures. NFC 2019-10-09 15:29:52 -07:00
Xi Ge
e9dfdea6fd SerializeLoc: serialize basic decl source location information to .swiftsourceinfo file
After setting up the .swiftsourceinfo file, this patch starts to actually serialize
and de-serialize source locations for declaration. The binary format of .swiftsourceinfo
currently contains these three records:

BasicDeclLocs: a hash table mapping from a USR ID to a list of basic source locations. The USR id
could be retrieved from the following DeclUSRs record using an actual decl USR. The basic source locations
include a file ID and the results from Decl::getLoc(), ValueDecl::getNameLoc(), Decl::getStartLoc() and Decl::getEndLoc().
The file ID could be used to retrieve the actual file name from the following SourceFilePaths record.
Each location is encoded as a line:column pair.

DeclUSRS: a hash table mapping from USR to a USR ID used by location records.

SourceFilePaths: a hash table mapping from a file ID to actual file name.

BasicDeclLocs should be sufficient for most diagnostic cases. If additional source locations
are needed, we could always add new source location records without breaking the backward compatibility.
When de-serializing the source location from a module-imported decl, we calculate its USR, retrieve the USR ID
from the DeclUSRS record, and use the USR ID to look up the basic location list in the BasicDeclLocs record.

For more details about .swiftsourceinfo file: https://forums.swift.org/t/proposal-emitting-source-information-file-during-compilation
2019-10-09 15:29:51 -07:00
Robert Widmann
5a8d0744c3 [NFC] Adopt TypeBase-isms for GenericSignature
Structurally prevent a number of common anti-patterns involving generic
signatures by separating the interface into GenericSignature and the
implementation into GenericSignatureBase.  In particular, this allows
the comparison operators to be deleted which forces callers to
canonicalize the signature or ask to compare pointers explicitly.
2019-09-30 14:04:36 -07:00
Harlan Haskins
c82c9b8210 [ModuleInterfaces] Remove references to 'parseable' interfaces everywhere
Now that we've settled on Module Interface as the name, let's remove the
vestiges of "Parseable Interfaces"
2019-09-13 14:55:48 -07:00
Slava Pestov
2656220222 Serialization: Simplify GenericEnvironment (de-)serialization
Now that GenericSignatures store their single unique GenericEnvironment,
we can remove similar logic from deserialization to preserve identity
of GenericEnvironments.
2019-09-06 17:16:04 -04:00
Jordan Rose
3c2d709996 [Serialization] Move a bunch of internal headers to lib/ (#27012)
This will discourage their use outside of Serialization, which is a
good thing for encapsulation.
2019-09-04 08:58:06 -07:00
Jordan Rose
c06e105bd0 [Serialization] Switch to a better hash seed for lookup tables
...fulfilling the promised audit from 0747d9a339. No intended
functionality change /other/ than the order of already-unsorted lists.
This affected a number of SIL tests that relied on deserialization
order matching the original source order; I have no idea why the old
hash logic would make that the case. If we think that's a valuable
property, we should serialize a list of functions in addition to the
iterable table. (Maybe just in SIB mode?)
2019-08-29 09:20:18 -07:00
Jordan Rose
b0ad06ae30 [Serialization] The hash seed for DeclCommentTableInfo can't change
Unlike compiled modules, swiftdoc files are considered a stable
format, so we can't change how information is stored in them. If we
add any more string-hashed tables to swiftdoc files, we should
consider using a new hash seed for those.
2019-08-29 09:19:49 -07:00
Jordan Rose
62f947d6ba [Serialization] Drop GenericEnvironmentID for GenericSignatureID (#26862)
A generic environment is always serialized as a GenericSignature with
a lazily-recreated environment, though sometimes it has to include
extra info specifically for generic environments used by SIL. The code
that was doing this claimed a bit for disambiguating between the two,
shrinking the permitted size of a compiled module from 2^31 bits to
2^30. (The code isn't just needlessly complicated; GenericEnvironments
used to be serialized with more information.)

Rather than have two representations for GenericEnvironmentID, this
commit just drops it altogether in favor of referencing
GenericSignatures directly.  This causes a negligible file size
shrinkage for swiftmodules in addition to eliminating the problematic
disambiguation bit.

For now, the Deserialization logic will continue to cache
GenericEnvironments that are used directly by Deserialization, but
really that should probably be done at the AST level. Then we can
simplify further to ModuleFile tracking a plain list of
GenericSignatures.
2019-08-28 09:38:19 -07:00
Jordan Rose
9e1b206984 [Serialization] Collapse indirection in DeclContextID
...by making it a tagged union of either a DeclID or a
LocalDeclContextID. This should lead to smaller module files and be
slightly more efficient to deserialize, and also means that every
AST entity kind is serialized in exactly one way, which allows for
the following commit's refactoring.
2019-08-27 11:39:16 -07:00
Jordan Rose
5c785d42b3 Enforce that FileUnit + LoadedFile have trivial destructors
We already do this for other ASTContext-allocated types (see
Decl.cpp). This will prevent the sort of mistakes in the previous two
commits.

Note that if any particular subclass of FileUnit wants to have its
destructor run, it can opt into that manually using
ASTContext::addDestructorCleanup. SourceFile and BuiltinUnit both do
this. But we generally don't /want/ to do this if we can avoid it
because it adds to compiler teardown time.
2019-08-23 17:40:46 -07:00
Jordan Rose
e479e1398d [Serialization] Use the module interface as the name of the file
...rather than the buffer, for a compiled module that came from a
module interface.

This was already happening at a higher level
(ModuleDecl::getModuleFilename) so pushing it down to the low-level
ModuleFile::getModuleFilename doesn't really change things much. The
important fix that goes with this is that SerializedASTFile no longer
leaks this name by storing it outside of ModuleFile.

https://bugs.swift.org/browse/SR-11365
2019-08-23 17:40:45 -07:00
Jordan Rose
c45f3a37cc [Serialization] Stop storing the load Status in ModuleFile itself
The code tried extra hard to make sure this stayed in sync with the
returned ValidationInfo, but there's no real reason for that. Just
keep a single "HasError" bit for checking that the module's not being
obviously misused. (I snuck some groundwork for this into the previous
commit.)
2019-08-21 21:20:12 -07: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
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
Ben Langmuir
a861e760e7 Merge pull request #24520 from benlangmuir/cc-crash-keypath
[code-completion] Avoid invalid member substitution for keypath dynamic lookup
2019-05-06 15:28:50 -07:00
Ben Langmuir
34da079aa6 Pass DynamicLookupInfo through VisibleDeclConsumers NFC
This commit adds a new type DynamicLookupInfo that provides information
about how a dynamic member lookup found a particular Decl. This is
needed to correctly handle KeyPath dynamic member lookups, but for now
just plumb it through everywhere.
2019-05-06 10:02:39 -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
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