Commit Graph

107 Commits

Author SHA1 Message Date
Alexis Laferrière
9921cd7c1f Merge pull request #30614 from xymus/fix-deser-indexing
[Serialization] Recover from more failures when reading private declarations
2020-03-24 13:45:00 -07:00
Alexis Laferrière
4e0038f0df [Serialization] Recover from conformances with missing decls
Components of a requirement may be hidden behind an implementation-only
import. Attempts at deserializing them would fail on a 'module not
loaded' error. We only see failures in non-compilation paths, either in
indexing or with tools like ide-test as they try to deserialize
things that are private.
2020-03-24 10:25:02 -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
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
Ashley Garland
7190073a85 Serialize symbol graphs for extended modules separately
When a module extends a type from another module, serialize those symbols into
separated files dedicated to those extended modules. This makes it easier to
ingest and categorize those symbols under the extended module if desired.

rdar://58941718
2020-02-11 13:23:16 -08: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
Alexis Laferrière
a4cf567ac4 [Serialization] Recover from deserializing an enum from a missing module
rdar://problem/58022345
2019-12-20 14:00:26 -08:00
Robert Widmann
ac08fceacc Add loadDynamicallyReplacedFunctionDecl
To support lazy resolution of the cross-referenced function in a serialized @_dynamicReplacement(for: ...) attribute, add a utility to the LazyMemberLoader and plumb it through.  This is a more general utility than the current resolver, which relies on the type checker to strip the attribute off of VarDecls and fan it back out onto accessors, which means serialization has only ever seen AbstractFunctionDecls.
2019-12-03 15:28:19 -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
Francis Visoiu Mistrih
47c6ce2af7 [Bitcode] Update includes: llvm/Bitcode -> llvm/Bitstream
The Bitstream part of Bitcode moved to llvm/Bitstream in LLVM. This
updates the uses in swift.

See r365091 [Bitcode] Move Bitstream to a separate library.

(cherry picked from commit 1cd8e19357)
2019-11-12 10:46:07 -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
Varun Gandhi
903add2c3f [Frontend] Make the module trace emission more robust.
✔ More informative error messages in case of crashes.
✔ Handling and documenting different cases.
✔ Test cases for different cases.
✔ Make SDKDependencies.swift pass again.
2019-10-15 15:44:26 -07:00
Xi Ge
014f863546 SerializeLoc: address more comments from Jordan. NFC 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
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
Jordan Rose
853caa66d4 [AST] Split FileUnit and its subclasses out of Module.h
Most of AST, Parse, and Sema deal with FileUnits regularly, but SIL
and IRGen certainly don't. Split FileUnit out into its own header to
cut down on recompilation times when something changes.

No functionality change.
2019-09-17 17:54:41 -07:00
Alexis Laferrière
7ce86145c8 serialization: recover from missing modules when reading SubstitutionMaps
Harden more of the serialization functions to propagate errors for
the caller to handle these errors gracefully. This fixes a crash in
finishNormalConformance when indexing a system module with an
implementation-only import.

rdar://problem/52837313
2019-09-10 10:13:15 -07:00
Slava Pestov
0405ab5ffc AST: GenericContexts store a GenericSignature instead of a GenericEnvironment
This eliminates the entire 'lazy generic environment' concept;
essentially, all generic environments are now lazy, and since
each signature has exactly one environment, their construction
no longer needs to be co-ordinated with deserialization.
2019-09-06 17:16:04 -04: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
Michael Gottesman
9311672c33 Move ModuleFile.h, ModuleFormat.h, and DeclTypeRecordNodes.def to include/swift/Serialization.
This allows for a secondary tool to access the deserialized Module inside the SerializedASTFile's ModuleFile.

Swift SVN r14173
2014-02-20 22:03:55 +00:00
Joe Groff
7fd26d22d5 Serialization: Fix a couple of issues with serializing context params of generic SILFunctions.
- Parameterize maybeReadGenericParams' BitstreamCursor so that we can read from
  the correct cursor when trying to read the generic params of a SILFunction.
- Only serialize the context generic params for SILFunctions for which we're
  serializing a complete definition. This fixes issues with us getting the
  wrong archetypes forward-declared from references in other modules.

In this version of the patch, we adjust the deserialization point for the
generic param list to correctly come before we check if the SILFunction block
is empty, and we add a kludge to keep the JIT from crapping itself when it sees
the same transparent definition in multiple REPL lines' modules
<rdar://problem/16094902>.

The previous commit solves a problem this exposed at r14050 in inout deshadowing
that caused memory corruption when transparent functions were imported. This
should now be safe to commit.

Swift SVN r14109
2014-02-19 22:47:25 +00:00
Greg Parker
675952c719 Revert r14030 which appears to segfault performance test hash2.swift.
Swift SVN r14038
2014-02-18 13:18:17 +00:00
Joe Groff
61f7a7c482 Serialization: Fix a couple of issues with serializing context params of generic SILFunctions.
- Parameterize maybeReadGenericParams' BitstreamCursor so that we can read from the correct cursor when trying to read the generic params of a SILFunction.
- Only serialize the context generic params for SILFunctions for which we're serializing a complete definition. This fixes issues with us getting the wrong archetypes forward-declared from references in other modules.

In this version of the patch, we adjust the deserialization point for the generic param list to correctly come before we check if the SILFunction block is empty, and we add a kludge to keep the JIT from crapping itself when it sees the same transparent definition in multiple REPL lines' modules <rdar://problem/16094902>.

Swift SVN r14030
2014-02-18 07:30:11 +00:00
Joe Groff
21429cbfae Revert "Serialization: Fix a couple of issues with serializing context params of generic SILFunctions."
This reverts commit 57ec1ee1e888b7ed61b731237218cd9529143d2d. It fixes r13984
but breaks ToT.

Swift SVN r14006
2014-02-17 20:32:04 +00:00
Joe Groff
67fd13ed66 Serialization: Fix a couple of issues with serializing context params of generic SILFunctions.
- Parameterize maybeReadGenericParams' BitstreamCursor so that we can read from the correct cursor when trying to read the generic params of a SILFunction.
- Only serialize the context generic params for SILFunctions for which we're serializing a complete definition. This fixes issues with us getting the wrong archetypes forward-declared from references in other modules.

This gets me a clean build when applied against r13984.

Swift SVN r14005
2014-02-17 20:05:46 +00:00
Jordan Rose
7995dde448 Module::getImportedModules can now get public, private, or all imports.
...whereas before the only options were "public" and "all".

No functionality change.

Swift SVN r13849
2014-02-12 23:57:43 +00:00
Joe Groff
0c0d30d5eb SIL: Make ContextGenericParams a constructor parameter of SILFunction.
Edge SILFunction one step closer to independence from SILFunctionType context by taking the generic param list as a separate constructor parameter, and serializing those params alongside the function record. For now we still pass in the context params from the SILFunctionType in most cases, because the logic for finding the generic params tends to be entangled in type lowering, but this pushes the problem up a step.

Thanks Jordan for helping work out the serialization changes needed.

Compared to r13036, this version of the patch includes the decls_block RecordKind enumerators for the GENERIC_PARAM_LIST layouts in the sil_block RecordKind enumerator, as Jordan had suggested before. r13036 caused buildbot failures when building for iOS, but I am unable to reproduce those failures locally now.

Swift SVN r13485
2014-02-05 16:52:02 +00:00
Michael Gottesman
800ea37c34 Revert r13036 as per Joe's request.
Swift SVN r13063
2014-01-28 21:36:06 +00:00
Joe Groff
5d58f10e48 SIL: Make ContextGenericParams a constructor parameter of SILFunction.
Edge SILFunction one step closer to independence from SILFunctionType context by taking the generic param list as a separate constructor parameter, and serializing those params alongside the function record. For now we still pass in the context params from the SILFunctionType in most cases, because the logic for finding the generic params tends to be entangled in type lowering, but this pushes the problem up a step.

Thanks Jordan for helping work out the serialization changes needed.

Swift SVN r13036
2014-01-28 02:17:46 +00:00
Jordan Rose
3513184bd7 Pass the decl in question to LazyMemberLoader's callback.
No functionality change, but used in the next commit.

Swift SVN r12684
2014-01-22 00:54:45 +00:00
John McCall
5da6defa1f Clean up the linkage model and the computation of linkage.
In general, this forces SILGen and IRGen code that's grabbing
a declaration to state whether it's doing so to define it.

Change SIL serialization to serialize the linkage of functions
and global variables, which means also serializing declarations.

Change the deserializer to use this stored linkage, even when
only deserializing a declaration, and to call a callback to
inform the client that it has deserialized a new entity.

Take advantage of that callback in the linking pass to alter
the deserialized linkage as appropriate for the fact that we
imported the declaration.  This computation should really take
advantage of the relationship between modules, but currently
it does not.

Swift SVN r12090
2014-01-09 08:58:07 +00:00
Doug Gregor
1482256a04 Make operator methods to module-scope name lookup.
Fixes the operator name lookup issue in <rdar://problem/15715996>.

Swift SVN r11724
2013-12-29 20:41:07 +00:00
Jordan Rose
531b240ca0 [serialization] Rework cross-references to be more general / more robust.
Previously, cross-references just carried a chain of identifiers and a
top-level module, plus a type to validate against, a generic parameter index,
or an operator fixity. However, referencing "the first generic parameter
of the prefix function ++ that takes a ForwardIndex" requires /all three/
of these filters to unambiguously select the right declaration.

Now, cross-references consist of a chain of trailing records, one for each
link in the path. There are (currently) five kinds of links:

Type: a declaration that cannot have overloads
Value: a declaration that can have overloads (filtered by type)
Extension: filter to decls within extensions on another module
Operator:
- as the first path piece, an operator declaration
- as a later path piece, a fixity filter for operator functions
Generic Param: an indexed generic parameter of the previous result

This should allow us to uniquely cross-reference any Swift declaration we
need to.

Swift SVN r11399
2013-12-17 23:03:34 +00:00
Jordan Rose
c2bd6eb2b0 Lazily deserialize members from AST files.
NominalTypeDecls and ExtensionDecls have a list of members. Rather than
eagerly populating that list when the nominal or extension is just referenced,
just include a pointer back to the ModuleFile, so that they can be
deserialized when we actually look into the decl. The design here is
general enough that we could do something similar with imported Clang decls.

Clang is even more lazy here: the on-disk representation is a hash table,
so lookup only forces deserialization of members with the same name. We
probably want that some day, but this might be enough to get by for now.

This is groundwork for loading partial ASTs, where eagerly deserializing
members leads to circular references we're not able to handle.

Swift SVN r11219
2013-12-12 23:31:15 +00:00
Dmitri Hrybenko
41b5f2486c AST printer: pretty-print import declarations while printing deserialized modules
Swift SVN r11144
2013-12-11 21:48:57 +00:00
Jordan Rose
fac5659813 [serialization] Sprinkle PrettyStackTrace throughout deserialization code.
Since we don't have soft-failure yet from deserialization, it's helpful to
at least know where to start looking when something crashes. There are some
rough edges here but it should be much better than nothing.

This also pulls the list of record nodes out into a separate file, so that
we can avoid repeating it.

Example crash:
1.	While reading from ./CTypes.swiftmodule
2.	While deserializing 'CBool' (StructDecl)
3.	While deserializing decl #26 (XREF)
4.	Cross-reference to 'LogicValue' in swift
(don't worry, this is an example where I'm tweaking things)

<rdar://problem/14838332>

Swift SVN r11057
2013-12-10 00:23:40 +00:00
Jordan Rose
439ba3e624 Accept swiftmodule files on the command line as partial AST inputs.
Each loaded file gets added to the main module, rather than being a standalone
separate module. In theory, this will be used to assemble several partial
ASTs into a complete module. In practice, there's still a ways to go...but
this can already round-trip a single module file.

This also factors out the FileUnit-creating part of SerializedModuleLoader,
which should help clients like SourceKit that don't need to search for a
swiftmodule file associated with a particular import.

Swift SVN r10952
2013-12-07 00:14:01 +00:00
Joe Groff
27d96bbdc9 SIL: Generalize archetype_method to accept concrete types.
Allow archetype_method to look up a witness from a concrete ProtocolConformance record. This will allow generic specialization to apply to constrained generic functions independent of archetype_method devirtualization. <rdar://problem/14748543>

Swift SVN r10950
2013-12-07 00:00:51 +00:00
Jordan Rose
417b5d3982 Merge TranslationUnit into Module, and eliminate the term "translation unit".
This completes the FileUnit refactoring. A module consists of multiple
FileUnits, which provide decls from various file-like sources. I say
"file-like" because the Builtin module is implemented with a single
BuiltinUnit, and imported Clang modules are just a single FileUnit source
within a module.

Most modules, therefore, contain a single file unit; only the main module
will contain multiple source files (and eventually partial AST files).

The term "translation unit" has been scrubbed from the project. To refer
to the context of declarations outside of any other declarations, use
"top-level" or "module scope". To refer to a .swift file or its DeclContext,
use "source file". To refer to a single unit of compilation, use "module",
since the model is that an entire module will be compiled with a single
driver call. (It will still be possible to compile a single source file
through the direct-to-frontend interface, but only in the context of the
whole module.)

Swift SVN r10837
2013-12-05 01:51:15 +00:00
Jordan Rose
be12d86ddd Turn ClangModule into ClangModuleUnit.
Part of the FileUnit restructuring. A Clang module (whether from a framework
or a simple collection of headers) is now imported as a TranslationUnit
containing a single ClangModuleUnit.

One wrinkle in all this is that Swift very much wants to do searches on a
per-module basis, but Clang can only do lookups across the entire
TranslationUnit. Unless and until we get a better way to deal with this,
we're stuck with an inefficiency here. Previously, we used to hack around
this by ignoring the "per-module" bit and only performing one lookup into
all Clang modules, but that's not actually correct with respect to visibility.

Now, we're just taking the filtering hit for looking up a particular name,
and caching the results when we look up everything (for code completion).
This isn't ideal, but it doesn't seem to be costing too much in performance,
at least not right now, and it means we can get visibility correct.

In the future, it might make sense to include a ClangModuleUnit alongside a
SerializedASTFile for adapter modules, rather than having two separate
modules with the same name. I haven't really thought through this yet, though.

Swift SVN r10834
2013-12-05 01:51:11 +00:00
Jordan Rose
8b8cc8ee62 Turn SerializedModule into SerializedASTFile.
Part of the FileUnit restructuring. A serialized module is now represented as
a TranslationUnit containing a single SerializedASTFile.

As part of this change, the FileUnit interface has been made virtual, rather
than switching on the Kind in every accessor. We think the operations
performed on files are sufficiently high-level that this shouldn't affect us.

A nice side effect of all this is that we now properly model the visibility
of modules imported into source files. Previously, we would always consider
the top-level imports of all files within a target, whether re-exported or
not.

We may still end up wanting to distinguish properties of a complete Swift
module file from a partial AST file, but we can do that within
SerializedModuleLoader.

Swift SVN r10832
2013-12-05 01:51:09 +00:00
Jordan Rose
63731584b6 [serialization] Introduce ModuleID, with codes for special modules.
ModuleID is compatible with IdentifierID, but uses 0 to mean “the builtin module”
and 1 to mean “the current module”. Anything else is a top-level module name,
as an identifier. As an implementation detail, 1 is now never a valid IdentifierID.
(0 remains “the empty string”.)

Using this, simplify the encoding of the owner of a conformance.

Swift SVN r9944
2013-11-04 23:50:46 +00:00
Jordan Rose
1ecf1fb593 Distribute Module's lookup cache to its subclasses.
Each one has a different kind of lookup cache anyway, and there's no real
reason to have them share storage at the cost of type-safety.

Swift SVN r9242
2013-10-12 00:08:09 +00:00