Commit Graph

240 Commits

Author SHA1 Message Date
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
Ashley Garland
7d7a8d35e5 [SymbolGraph] Don't trim comment segments past the first nonspace offset
Otherwise, the `SourceManager` may skip over a blank line, causing
it to have a line number off by one.

Measure initial indentation from the first non-blank line.

rdar://61827368
2020-04-16 14:24:23 -07:00
AG
ed28d8bd95 Merge pull request #31045 from bitjammer/acgarland/sgf-0.5.0
[SymbolGraph] Bump format version to 0.5.0 NFC
2020-04-15 17:01:01 -07:00
AG
21e9307dd9 Merge pull request #31047 from bitjammer/acgarland/rdar-61746582-dont-use-innermost-context
[SymbolGraph] Don't use innermost context for swiftExtension
2020-04-15 15:43:27 -07:00
AG
240a86f5e0 Merge pull request #31044 from bitjammer/acgarland/rdar-61843516-ext-use-isimplicitlyprivate
[SymbolGraph] Use isImplicitlyPrivate for extended types
2020-04-15 15:03: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
d62e4ac4d7 [SymbolGraph] Don't use innermost context for swiftExtension
`getInnerMostContext` can return the same value if it is a type, but
`swiftExtension` should always look upward for an extension.

rdar://61746582
2020-04-15 13:59:54 -07:00
Ashley Garland
bad8904c9d [SymbolGraph] Bump format version to 0.5.0 NFC 2020-04-15 13:12:10 -07:00
Ashley Garland
98d8eb9074 [SymbolGraph] Use isImplicitlyPrivate for extended types
This was just using `hasUnderscoredNaming` before but this only checks the
leafmost type. When filtering extended types, it should continue to look up
through nesting types to see if they are also implicitly private.

rdar://61843516
2020-04-15 13:01:15 -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
AG
f9610de25b Merge pull request #31000 from bitjammer/acgarland/rdar-61178480-indirect-default-impls
[SymbolGraph] Look at inherited protocols for default implementations
2020-04-14 09:18:15 -07:00
Ashley Garland
72dbdb097d [SymbolGraph] Look at inherited protocols for default implementations
rdar://61178480
2020-04-13 15:47:46 -07:00
Ashley Garland
06d1d502a1 [SymbolGraph] Ignore some Self requirements
To ease the burden on the client, ignore some generic requirements involving
Self. For example, `Self: P` where we already know that `Self` conforms to `P`.

An example case:

```
public struct S: Equatable {
  public static func ==(lhs: S, rhs: S) -> Bool { ... }
}
```

`!=` is defined in terms of `Self` and the default implementation has a `Self:
Equatable`. For the purposes of documentation, it's not necessary to specify
that again on the page of documentation for `!=`.

rdar://60963924
2020-04-13 13:17:33 -07:00
AG
4e85c51b07 Merge pull request #30857 from bitjammer/acgarland/rdar-60796811-rootmost-extension-sgf
[SymbolGraph] Put extending declarations in rootmost module
2020-04-08 09:41:25 -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
d6e49a98db [SymbolGraph] Put extending declarations in rootmost module
When extending another module's type in your module, serialize declarations in
the extension into the other module's "extension" symbol graph file, including
relationships. This mechanic should continue up to the rootmost module. For
example:

A.AStruct <- B.BStruct < C.CStruct

Both BStruct and CStruct should go in `@A` symbol graph files because AStruct
owns BStruct and by extension owns CStruct. This is reflected in
documentation curation in some form already.

rdar://60796811
2020-04-07 15:41:59 -07:00
Ashley Garland
58edd83f37 [SymbolGraph] Completely filter unavailable/obsoleted symbols
Symbol graph files are processed per platform--documentation for symbols that
are unconditionally unavailable or obsoleted on a platform shouldn't be shown
for that same platform.

Also, removes `isUnconditionallyUnavailable` from the JSON format. If it's
unconditionally unavailable, it won't show up at all.

rdar://60193675
2020-03-18 09:43:08 -07:00
Ashley Garland
ac6132a2c0 [SymbolGraph] Bump format version to 0.4.0 NFC
rdar://60541965
2020-03-17 09:49:21 -07:00
Ashley Garland
eaad8a7241 [SymbolGraph] Serialize Location uri and position together
or not at all. This information comes as one unit from .swiftsourceinfo so the
code should reflect that.

rdar://60499122
2020-03-16 10:10:10 -07:00
Ashley Garland
5b6becf186 [SymbolGraph] Omit empty docComment fields
rdar://59500543
2020-03-10 19:37:39 -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
72715eaf71 SymbolGraph: Add more granular kinds
This is necessary to disambiguate some symbols with the same path components
and makes the data clearer to debug.

rdar://problem/59841727
2020-03-02 12:34:03 -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
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
07bee5cdda Bump SymbolGraph format version (NFC)
rdar://58853310
2020-02-06 17:29:56 -08:00
AG
2d59365d93 Merge pull request #29414 from bitjammer/acgarland/rdar-58853310-interface-language
SymbolGraph: Serialize interface language
2020-01-29 15:20:24 -08:00
Ashley Garland
42345dabd3 SymbolGraph: Move pathComponents up and include interfaceLanguage
`pathComponents` doesn't help with disambiguation, so it shouldn't be a part of
the identifier, but can be moved up one level. Include an interface language in
the identifier instead.

rdar://problem/58853310
2020-01-28 12:56:59 -08:00
Saleem Abdulrasool
d8b3b626fe build: use modern target property handling
Use specific operations for setting the compile flags, link flags,
linked libraries, and library search paths.  This allows us to use CMake
more effectively, simplifies the logic, and will ensure that flags are
not duplicated.
2020-01-25 16:08:51 -08:00
Devin Coughlin
082421048a [AST/Sema] Add availability attributes for macCatalyst
Add a platform kind and availability attributes for macCatalyst. macCatalyst
uses iOS version numbers and inherits availability from iOS attributes unless
a macCatalyst attribute is explicitly provided.
2020-01-21 20:27:14 -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