Commit Graph

93 Commits

Author SHA1 Message Date
QuietMisdreavus
f0c96b1c97 Merge pull request #41141 from apple/QuietMisdreavus/symgraph-synth-init
[SymbolGraph] don't filter out all implicit decls
2022-02-03 16:25:05 -07:00
Victoria Mitchell
08fe7c2134 [SymbolGraph] don't filter out all implicit decls 2022-02-02 12:57:40 -07:00
Victoria Mitchell
9bd3454566 [SymbolGraph] consider underscored symbols as private if they're internal
rdar://86294802
2022-02-02 09:56:50 -07:00
Victoria Mitchell
3011a3cfca [SymbolGraphGen] don't emit access control attributes in declarations
rdar://85280786
2021-12-22 16:35:12 -07:00
Ben Barham
6aa3e0fd00 [SymbolGraph] Determine optional requirement by presence of OptionalAttr
Rather than checking the underlying ObjectiveC decl, use the presence of
`OptionalAttr` to determine if a requirement is optional instead. This
is already added by the importer when necessary. An added benefit here
is that this also works for optional requirements defined in Swift (ie.
`@objc optional ...`).
2021-09-25 11:50:53 +10:00
Victoria Mitchell
dd39496098 do not synthesize subclass methods
rdar://80091081
2021-07-02 14:43:53 -06:00
Victoria Mitchell
d281722589 add symbol-graph flag to include SPI symbols
rdar://70794131
2021-05-20 15:10:49 -06:00
QuietMisdreavus
08d1c33e6f Merge pull request #37278 from apple/QuietMisdreavus/default-relation
[SymbolGraph] add "memberOf" relations for remote protocol implementations
2021-05-07 16:19:18 -06:00
Victoria Mitchell
633ffece87 compare module names instead of pointers 2021-05-06 10:08:09 -06:00
Victoria Mitchell
4b5045f25a add "memberOf" relations for remote protocol implementations
rdar://75729692
2021-05-05 15:44:28 -06:00
Alex Hoppen
e7d56037e8 Merge pull request #37133 from ahoppen/pr/serialize-text-module-symbolgraph
[SymbolGraph] Fix crasher when retrieving cursor info of method defined in ObjC
2021-04-30 23:13:15 +02:00
Alex Hoppen
5d3fb8f26d [SymbolGraph] Fix crasher when retrieving cursor info of method defined in ObjC
In a mixed Objective-C / Swift module, we have a Clang module overlay that’s a Source file, not a serialized AST as is currently assumed. That assumption caused a crash when retrieving the symbol graph as part of a cursor info request to SourceKit, which was invoked on a method defined in the Objective-C part of the module.

To fix the crash, recursively use the same logic that already exists to serialize a module to also serialize the clang overlay module since that function alreayd correctly handles the distinction between source files and serialized ASTs.

Resolves rdar://76951147
2021-04-29 17:54:18 +02:00
Alex Hoppen
370128e6b6 [SymbolGraph] Fix a crash for member in invalid extension
Don’t record a `memberOf` relationship if we couldn’t look up the target, e.g. because the member is declared in an extension whose extended type doesn’t exist.

Resolves rdar://74063899
2021-04-29 14:21:52 +02:00
Victoria Mitchell
19e6144be4 always print enum elements
in some situations, enum element decls are being skipped when rendering
declaration fragments. this trips an assertion in the declaration
fragment renderer that ensures that it always renders something. by
always rendering enum elements, we can sidestep this issue.
2021-03-19 10:43:52 -06:00
Victoria Mitchell
db3685aa29 don't emit navigator name if it's the same as subHeading 2021-03-01 10:57:54 -07:00
Ashley Garland
69c4fc47cb Add optional -emit-symbol-graph output when emitting modules
rdar://71497047
2021-01-28 09:55:33 -08:00
Varun Gandhi
f9570b2d34 [NFC] Pass full convention printing boolean for types etc.
When -experimental-print-full-convention is set, we should be printing
the full convention in diagnostics, doc comments etc.
2021-01-25 18:47:39 -08:00
Nathan Hawes
388052b6ab [SymbolGraph][CursorInfo] Add option to SourceKit's CursorInfo request to include the SymbolGraph JSON
Adds a new 'key.retrieve_symbol_graph' option to the request. When set to 1 it
includes the JSON for a SymbolGraph containing a single node for the symbol at
the requested position.

This also extends the SymbolGraph library with a new entry point to get a graph
for a single symbol, and to additionally support type substitution to match the
existing CursorInfo behavior (e.g. so that when invoked on `first` in
`Array<Int>().first`, the type is given as `Int?` rather than `Element?`).

Resolves rdar://problem/70551509
2020-12-12 14:38:41 +10:00
Victoria Mitchell
bfb2793e8a include cross-import overlay information in the symbol graph itself 2020-12-10 19:13:37 -07:00
Ashley Garland
ecf8d556e5 [SymbolGraph] Don't link type identifier fragments to private symbols
These links will never resolve because the symbols are never emitted
in the first place.

rdar://64178490
2020-08-07 14:20:28 -07:00
Ashley Garland
dd7a7f7c89 [SymbolGraph] Print non-underscored attributes in declarations
rdar://63338507
2020-06-05 13:36:22 -07:00
Ashley Garland
a72231128e [SymbolGraph] Don't print inherited list in declaration fragments
Add a new `PrintInherited` flag to `PrintOptions` to support this.

rdar://63033669
2020-06-04 11:52:51 -07:00
Ashley Garland
975d2520e8 [SymbolGraph] Print where clause in full declaration fragments
rdar://63233737
2020-06-02 11:33:42 -07:00
Ashley Garland
51ce1f2b0f [SymbolGraph] Look for @_spi on extensions
Consider declarations inside `@_spi` extensions to be internal.

Clean up the "implicitly private" check to work for `Decl` and not just
`ValueDecl`, allowing it to be used directly on extensions instead of having to
look for extensions everywhere.

rdar://63361634
2020-05-27 16:00:15 -07:00
Ashley Garland
720d3d2f2a [SymbolGraph] Show get/set on property/subscript full declarations
But don't show them in subheading contexts.

rdar://63233897
2020-05-20 14:16:45 -07:00
Ashley Garland
f2c10d2ed4 [SymbolGraph] Use identifier for type name fragments
In the cases where we specialize the presentation of type declarations in a
subheading or navigator setting, make sure to use the `identifier` fragment
kind instead of `typeIdentifier` to keep it consistent with the normal or
"full" setting.

rdar://62953144
2020-05-06 17:28:28 -07:00
Varun Gandhi
65577940d0 [NFC] Get rid of -Wrange-loop-analysis warnings. (#31324) 2020-04-27 09:47:52 -07:00
Ashley Garland
d4e5c6f438 [SymbolGraph] Add navigator declaration fragments
Only print the type name for a type's navigator fragments.

Don't print where clauses for navigator or subHeading fragments.

rdar://62353465
2020-04-24 20:20:19 -07:00
Ashley Garland
d5aa0d0543 [SymbolGraph] Pick best synthesized member when possible
A type can have multiple overloads available from different protocols from
which it inherits. Ask the type checker to pick the best one where possible.

rdar://60193198
2020-04-24 18:24:54 -07:00
Anthony Latsis
74252028ca AST: Rename getFullName -> getName on ValueDecl & MissingMemberDecl 2020-04-23 05:16:55 +03:00
Ashley Garland
9d6ec078c2 [SymbolGraph] Filter @_spi declarations
These definitely shouldn't be showing up in symbol graphs with a minimum access
level of `public`, and it's not clear whether another minimum access level
should show these. For now, filter them unconditionally.

rdar://62081711
2020-04-21 14:01:58 -07:00
Ashley Garland
115a8de9ae [SymbolGraph] Type subheadings: don't print generics/inheritance
Subheadings for types are treated more as a title element and can't be
overloaded in the same way that other declarations can be. Abridge these
fragments to only contain the keyword and identifier.

rdar://62040714
2020-04-20 14:25:19 -07:00
AG
4e56349399 Merge pull request #31032 from bitjammer/acgarland/rdar-61459287-no-members-for-defaultimplementations-of-requirements
[SymbolGraph] Don't emit memberOf for default implementations or requ…
2020-04-15 14:03:18 -07:00
Ashley Garland
8316157c5e [SymbolGraph] Don't emit memberOf for default implementations or requirements
To differentiate between freestanding extensions of protocols and matching
default implementations with their requirements. Otherwise, it's difficult to
filter out "duplicate" entries for protocols.

rdar://61459287
2020-04-14 20:13:00 -07:00
Ashley Garland
9611047d4a [SymbolGraph] Add internal/externalParam declaration fragment
These were previously mapped to identifier. Some clients may wish to render
these differently in their declaration blocks.

rdar://61782916
2020-04-14 16:06:56 -07:00
Ashley Garland
72dbdb097d [SymbolGraph] Look at inherited protocols for default implementations
rdar://61178480
2020-04-13 15:47:46 -07:00
Dan Zheng
c834696bfa Add SynthesizedFileUnit.
`SynthesizedFileUnit` is a container for synthesized declarations. Currently, it
only supports module-level declarations.

It is used by the SIL differentiation transform, which generates implicit struct
and enum declarations.
2020-04-07 18:29:26 -07:00
Ashley Garland
7ce6753231 [SymbolGraph] Track conditional conformance
Requirements on extensions were only being gathered indirectly. This adds a new
optional field to `conformsTo` relationship edges, `swiftConstraints`, which
provides the requirements there.

rdar://60091161
2020-03-09 20:06:49 -07:00
Ashley Garland
f0887fa245 [SymbolGraph] Emit synthesized members
Emit copies of default implementations in protocol extensions and superclass declarations in conforming types and subclasses respectively using a virtual USR, i.e. `${REAL_USR}::SYNTHESIZED::${CONFORMING_OR_SUBCLASS_TYPE_USR}`.

- Add a -skip-synthesized-members option to skip these synthesized members.

- Create a new wrapping `Symbol` type that can also contain a base type declaration as well as the inherited declaration for those synthesized cases. Move some symbol-specific APIs there.

- Doc comments can “cascade” down to protocol extensions or refinements in concrete types. When emitting the doc comment for a symbol, look up through to superclasses or protocol requirements for where a doc comment is actually written.

- Clean up filtering of implicitly private (e.g. “public underscored”) types

rdar://problem/59128787
2020-03-04 16:04:21 -08:00
Ashley Garland
58bbe1ec04 SymbolGraph: Don't unconditionally add edge targets to the graph
Edge targets might point outside the module, so don't include them
unconditionally.

rdar://58876107
2020-02-11 13:23:16 -08: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
Ashley Garland
be68f864e0 Move Symbol logic into SymbolGraph
Up to now, the `SymbolGraphASTWalker` was only concerned with one module. This
change prepares for emitting multiple symbol graph files, for each module that
the module of interest extended. There is only one walker, so extract the
symbol logic into `SymbolGraph`, where it can be reused.

rdar://58941718
2020-02-11 13:23:04 -08:00
Ashley Garland
7a3a0a9e23 Symbol graph support
Adds a tool `swift-symbolgraph-extract` that reads an existing Swift
module and prints a platform- and language-agnostic JSON description of
the module, primarly for documentation.

Adds a small sub-library `SymbolGraphGen` which houses the core
implementation for collecting relevant information about declarations.
The main entry point is integrated directly into the driver as a mode:
the tool is meant to be run outside of the normal edit-compile-run/test
workflow to avoid impacting build times.

Along with common options for other tools, unique options include
`pretty-print` for debugging, and a `minimum-access-level` options for
including internal documentation.

A symbol graph is a directed graph where the nodes are symbols in a
module and the edges are relationships between them. For example, a
`struct S` may have a member `var x`. The graph would have two nodes for
`S` and `x`, and one "member-of" relationship edge. Other relationship
kinds include "inherits-from" or "conforms to". The data format for a
symbol graph is still under development and may change without notice
until a specificiation and versioning scheme is published.

Various aspects about a symbol are recorded in the nodes, such as
availability, documentation comments, or data needed for printing the
shapes of declarations without having to understand specifics about the
langauge.

Implicit and public-underscored stdlib declarations are not included by
default.

rdar://problem/55346798
2020-01-10 09:53:37 -08:00