Commit Graph

246 Commits

Author SHA1 Message Date
Ben Cohen
58f661cfba Allow Equatable: ~Escapable (#85854)
Adds `~Escapable` to #85746
2025-12-08 09:50:50 -08:00
Ben Cohen
fbb420f38d Allow Equatable: ~Copyable (#85746)
Under review
[here](https://forums.swift.org/t/se-0499-support-copyable-escapable-in-simple-standard-library-protocols/83297).
Multi-part version of #85079.
2025-12-03 05:45:38 -08:00
Dylan Sturgeon
4b4f9f18fc Add an option for symbol graph to support long module names. (#83782)
Currently symbol graphs are always written in files that contain 1 to 2
module names. It's possible for Swift module names to be very long, so
combining 2 of them in file name like `module1@module2...` in the same
path component means the name can be too long for some file systems. The
new option `-symbol-graph-shorten-output-names` changes the symbol graph
output files to use a MD5 hash of the module name(s) as the filename and
outputs an additional JSON file with the original names mapped to the
real filename. The module names JSON can be used to construct a VFS
overlay with the original naming scheme.

fix #83723

I considered using vfsoverlay, which seems like a viable solution, but
the vfsoverlay options don't seem to apply to any of the outputs from
the compiler. When I set an overlay to remap the symbol graph file
outputs, the remapped external paths aren't used so the root problem of
too long file names remains.
2025-11-06 19:30:44 -08:00
QuietMisdreavus
40690aa67f [SymbolGraphGen/Tests] require StringProcessing in the Macros test (#84406)
This test implicitly loads `_StringProcessing`; add that to the
requirements of this test so that is correctly reflected.

Resolves rdar://158821486
2025-09-19 20:12:27 -07:00
Chris McGee
d4ae4c3652 Make a doc comment test 2025-09-11 07:12:33 -04:00
Chris McGee
214bc77f45 Fix compile error 2025-09-10 21:37:33 -04:00
Chris McGee
42aa038f8d Fix compile error 2025-09-10 20:29:14 -04:00
Chris McGee
e71009b3ff Add symbol graph option for skipping inherited docs 2025-09-10 19:01:29 -04:00
Chris McGee
1380a3e2a9 Merge pull request #83044 from cmcgee1024/add_more_symbol_graph_opts_swiftc
Add pretty print and skip synthesized members to the frontend options
2025-09-09 15:24:27 -04:00
Chris McGee
5048345664 Add a test case for skipping synthesized members 2025-09-08 20:18:42 -04:00
Chris McGee
6a38bbe73d Qualify the skip synthesized members option with symbol graph for the compiler frontend
Rollback the additional usages of the new options and test cases
2025-08-07 15:44:33 -04:00
Allan Shortlidge
c616f3b718 Restrict infer-target.swift to configs that don't cross-compile. 2025-08-04 09:48:04 -07:00
Allan Shortlidge
916f28bfdb Revert "Tests: Delete SymbolGraph/infer-target.swift."
This reverts commit 6271a4629f.
2025-08-04 09:46:45 -07:00
Allan Shortlidge
6271a4629f Tests: Delete SymbolGraph/infer-target.swift.
Having a test for this was a nice idea but there just doesn't seem like there's
a way to test it reliably given that cross compilation happens in a wide
variety of CI bot configs.

Resolves rdar://157170133.
2025-08-01 16:52:30 -07:00
Chris McGee
26168f57cc Create tests for the two new symbol graph options
Add options to the driver and frontend options
2025-07-30 10:24:56 -04:00
Allan Shortlidge
f5b67e2495 swift-symbolgraph-extract: Fix -target inference test.
Only test `-target` inference in CI configurations that are not
cross-compiling.

Resolves rdar://156991775.
2025-07-29 16:38:40 -07:00
Allan Shortlidge
e8ced33b81 swift-symbolgraph-extract: Infer target triple.
Infer the `-target` argument to `swift-synthesize-interface` to be the host
triple when unspecified instead of emitting an error.
2025-07-28 12:43:37 -07:00
QuietMisdreavus
235f140b4c [SymbolGraphGen] check implicit clang decls for having extension parents (#83143)
Resolves rdar://151911998

This PR addresses an uncommon situation in the symbol graph when
importing Objective-C symbols into Swift. When a class conforms to a
protocol that includes an initializer, that initializer is automatically
generated for that class in the AST. This initializer has the same USR
as the original protocol symbol, but is housed in a different
DeclContext to indicate the membership.

Right now, we catch this situation when the protocol conformance is
declared on the class definition: There's a branch to check for
"implicit" decls with an underlying Clang symbol, and creates a
synthesized USR if that symbols DeclContext points to a type. However,
when the protocol conformance is added in a category extension, the
DeclContext for the generated initializer points to the extension,
causing the symbol to bypass that check and get added to the symbol
graph with a duplicated USR. This PR adds a check to look for
ExtensionDecls as the DeclContext so that the symbol can correctly
receive a synthesized USR.

One of the tests in this PR
(`SymbolGraph/ClangImporter/ObjCInitializer.swift`) tests a similar
situation where this "implicit decl with a Clang node" is created: Some
initializers in Objective-C get imported into Swift twice, with
differently-adapted parameter names. This is covered by the original
code, but i wanted to leave the test in because i broke this case in my
initial investigation! 😅 The other test
(`SymbolGraph/ClangImporter/ProtocolInitializer.swift`) tests the new
behavior that is fixed by this PR.
2025-07-18 09:04:16 -06:00
QuietMisdreavus
1948907eb3 use RespectOriginallyDefinedIn when mangling extension contexts (#82348)
Resolves rdar://152598492

Consider the following Swift, adapted from a real-world framework:

```swift
@available(macOS 10.8, *)
@_originallyDefinedIn(module: "another", macOS 11.0)
public struct SimpleStruct {}

@available(macOS 12.0, iOS 13.0, *)
public extension SimpleStruct {
    struct InnerStruct {}
}
```

In this scenario, `SimpleStruct` was originally in a module called
`another`, but was migrated to this module around the time of macOS
11.0. Since then, the module was ported to iOS and gained a nested type
`SimpleStruct.InnerStruct`. When mangling USRs for this nested type, the
result differs depending on whether we're targeting macOS or iOS.
They're mostly the same, but the macOS build yields a USR with an `AAE`
infix, designating that the `InnerStruct` was defined in an extension
from a module with the name of the base module. On iOS, this infix does
not exist.

The reason this is happening is because of the implementation of
`getAlternateModuleName` checking the availability spec in the
`@_originallyDefinedIn` attribute against the currently active target.
If the target matches the spec, then the alternate module name is
reported, otherwise the real module name is. Since the iOS build reports
the real module name, the mangling code doesn't bother including the
extension-context infix, instead just opting to include the parent
type's name and moving on.

This PR routes around this issue by passing the
`RespectOriginallyDefinedIn` variable to the
`ExtensionDecl::isInSameDefiningModule` method, and using that to skip
the alternate module name entirely. It also sets
`RespectOriginallyDefinedIn` to `false` in more places when mangling
USRs, but i'm not 100% confident that it was all necessary. The goal was
to make USRs more consistent across platforms, regardless of the
surrounding context.
2025-06-30 12:57:12 -06:00
Allan Shortlidge
e358cd6309 Tests: Correct invalid platform versions in @available attributes. 2025-06-10 22:11:05 -07:00
QuietMisdreavus
0cc46765ec [SymbolGraphGen] distinguish between headers of the same name in different modules (#82112)
Resolves rdar://152676102

In Objective-C, it's reasonable to sort extensions of your dependency's
types into headers that match the name of that type. However, this runs
into a bug in SymbolGraphGen when it comes time to generate Swift symbol
graphs for that Objective-C code: At the moment, it only differentiates
between modules based on their base name, regardless of their parent
modules (if any). This causes these extensions to be incorrectly sorted
into the _extending module's_ symbol graph, rather than in an extension
symbol graph where it can be displayed with the _extended module_. When
processed with Swift-DocC, it would cause these symbols to disappear.

This PR updates the `areModulesEqual` function used by the
`SymbolGraphASTWalker` to consider the fully-qualified module name for
comparisons, rather than just the module's base name, causing situations
like the test's `Dependency.DependencyClass` and
`HeaderCollision.DependencyClass` to be properly distinguished from each
other.
2025-06-09 15:11:31 -06:00
Anthony Latsis
0a1b8b0d50 [test] Fix misspelled FileCheck directives 2025-05-29 15:09:36 +01:00
Vera Mitchell
e8be13f08b fix AvailabilityFilter test to be resilient against path names 2025-04-17 15:54:36 -06:00
Pavel Yaskevich
e302d73c87 [AST] ASTPrinter: Make sure that attributes are printed as attributes and specifiers as keywords 2025-04-15 16:29:20 -07:00
QuietMisdreavus
41120da702 [SymbolGraphGen] add flags to filter platforms out of availability metadata (#80778)
* add option to filter availability metadata in symbol graphs

* filter out platform-specific availability in the stdlib docs

rdar://144379124
2025-04-14 15:20:22 -07:00
QuietMisdreavus
3f4519e7a5 add Sendable to the allowed attributes in declaration fragments (#80465)
rdar://142903358
2025-04-04 14:33:20 -06:00
QuietMisdreavus
f5c531c8f9 only recurse public-private type aliases from Clang (#79996)
rdar://145980187
2025-03-31 09:10:58 -06:00
Dylan Sturgeon
2c8e337f25 Merge pull request #80074 from dylansturg/objc_enum_refs
The Error enum synthesized declarations, e.g. the struct and its static accessors, should generally appear to be identical to the underlying Clang definitions. There are some specific use cases where the synthesized declarations are necessary though.

I've added an option for USR generation to override the Clang node and emit the USR of the synthesized Swift declaration. This is used by SwiftDocSupport so that the USRs of the synthesized declarations are emitted.

Fixes 79912
2025-03-25 11:21:21 +00:00
Doug Gregor
e24598bca1 Use a marker protocol SendableMetatype to model T.Type: Sendable
Introduce a marker protocol SendableMetatype that is used to indicate
when the metatype of a type will conform to Sendable. Specifically,
`T: SendableMetatype` implies `T.Type: Sendable`. When strict
metatype sendability is enabled, metatypes are only sendable when `T:
SendableMetatype`.

All nominal types implicitly conform to `SendableMetatype`, as do the
various builtin types, function types, etc. The `Sendable` marker
protocol now inherits from `SendableMetatype`, so that `T: Sendable`
implies `T.Type: Sendable`.

Thank you Slava for the excellent idea!
2025-02-13 22:48:05 -08:00
QuietMisdreavus
57450f5d18 [SymbolGraphGen] Un-revert #78959 and clean up usage of DenseMap (#79124)
* Revert "Revert "[SymbolGraphGen] synthesize child symbols for type aliases of private…" (#79062)"

This reverts commit cac82978bc.

* clean up use of DenseMap in SymbolGraphGen

rdar://143865173
2025-02-06 08:34:16 -07:00
QuietMisdreavus
cac82978bc Revert "[SymbolGraphGen] synthesize child symbols for type aliases of private…" (#79062)
This reverts commit b1871fb333.
2025-01-30 19:38:41 -08:00
QuietMisdreavus
ab26b8b9d7 add support to getTopLevelDecls for clang submodules (#76401)
rdar://126031510
2025-01-30 09:39:58 -07:00
QuietMisdreavus
b1871fb333 [SymbolGraphGen] synthesize child symbols for type aliases of private decls (#78959) 2025-01-29 12:39:26 -07:00
Daniel Rodríguez Troitiño
5abb1ea6ac [test] Remove some REQUIRES: for features not longer used in those files
While doing #76740 I iteratively was adding new `REQUIRES:` as new
usages of the features were found, but I did not realize that at the
same time other people might be removing some of those usages. The tests
in this commit had some `REQUIRES:` line for a previous
`-enable-experimental/upcoming-feature`, but they not longer use those
features, so the `REQUIRES:` were effectively disabling the tests (at
least in the case of `KeyPathWithStaticMembers`. In other cases they
might still had executed).
2024-11-04 20:53:07 -08:00
Daniel Rodríguez Troitiño
ba68faaed5 [test] Mark tests that use experimental/upcoming features as such
Find all the usages of `--enable-experimental-feature` or
`--enable-upcoming-feature` in the tests and replace some of the
`REQUIRES: asserts` to use `REQUIRES: swift-feature-Foo` instead, which
should correctly apply to depending on the asserts/noasserts mode of the
toolchain for each feature.

Remove some comments that talked about enabling asserts since they don't
apply anymore (but I might had miss some).

All this was done with an automated script, so some formatting weirdness
might happen, but I hope I fixed most of those.

There might be some tests that were `REQUIRES: asserts` that might run
in `noasserts` toolchains now. This will normally be because their
feature went from experimental to upcoming/base and the tests were not
updated.
2024-11-02 11:46:46 -07:00
QuietMisdreavus
108ad6f115 fix nondeterminism in OptionalRequirementOf test (#77276)
rdar://138773605
2024-10-31 14:18:34 -06:00
David Rönnqvist
b8481da042 Include explicitly unnamed parameter names in function signature (#77222)
rdar://138630917
2024-10-30 15:29:53 -07:00
azharudd
560fe75031 Merge pull request #77212 from bnbarham/2024-rebranch-to-main
Update LLVM to stable/20240723
2024-10-28 16:02:02 -07:00
QuietMisdreavus
d5d00011f3 [SymbolGraphGen] improve handling of underscored protocols (#77251)
* treat children of underscored protocols as public

Children of underscored protocols should be treated as native children
of their conforming types. To accomplish this, ignore underscored
protocols in the isInherentlyPrivate check.

rdar://124483146

* include underscored protocol methods even when skipping protocols

rdar://128143861
2024-10-28 13:44:03 -07:00
swift-ci
6ea9995a81 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-19 18:57:20 -07:00
Allan Shortlidge
cb578172ea Tests: Remove -disable-availability-checking in more tests that use concurrency.
Use the `%target-swift-5.1-abi-triple` substitution to compile the tests for
deployment to the minimum OS versions required for use of _Concurrency APIs,
instead of disabling availability checking.
2024-10-19 12:35:20 -07:00
swift-ci
2b5ffa0941 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-18 15:52:56 -07:00
QuietMisdreavus
2f184f7bac don't emit both requirementOf and optionalRequirementOf for the same relationship (#76983)
rdar://83519993
2024-10-18 16:48:39 -06:00
swift-ci
415b83acd6 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-24 05:54:22 -07:00
Hamish Knight
73baf7d690 [test] Tweak a SymbolGraph test
Add `-wmo` to the invocation to ensure we don't
end up doing merge-modules, which makes the test
consistent across both the old and new driver.
2024-09-22 21:15:45 +01:00
swift-ci
3a84dea9bb Merge remote-tracking branch 'origin/main' into rebranch 2024-08-22 08:54:27 -07:00
Ben Langmuir
fd1875dcfb [test] Move availability tests to later fake OS versions
10.50 was once greater than any real macOS version, but now it compares
less than real released versions, which makes these tests depend on the
deployment target unnecessarily. Update these tests to use even larger
numbers to hopefully keep them independent a little longer.
2024-08-21 11:38:54 -07:00
swift-ci
21575354f7 Merge remote-tracking branch 'origin/main' into rebranch 2024-08-15 14:55:35 -07:00
QuietMisdreavus
bafe819e8d don't drop underscored protocol implementation symbols (#75848)
rdar://133086270
2024-08-15 14:41:17 -07:00
swift-ci
fa1860c1db Merge remote-tracking branch 'origin/main' into rebranch 2024-08-13 08:08:08 -07:00