Commit Graph

229 Commits

Author SHA1 Message Date
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
Daniel Grumberg
3b093d7938 Avoid recursing into non swift modules when collecting exported imports (#75619)
rdar://132593532
2024-08-13 09:05:50 -06:00
Becca Royal-Gordon
fd84e7273d Rename module.map -> module.modulemap in tests
The legacy `module.map` spelling of module map files was deprecated by llvm/llvm-project#75142 and clang expects to remove support for them in the future. Switch all tests to use the supported spelling.

Fixes rdar://128431478.
2024-08-12 17:47:26 -07:00
Alex Hoppen
eec3d752cb Inherit doc comments from default implementations of inherited protocols
For example when we have

```swift
protocol BaseProtocol {}

extension BaseProtocol {
  /// Say hello
  func hello() { }
}
struct MyStruct: BaseProtocol {
  func hello() {}
}
```

Then `MyStruct.hello` should inherit the doc comment from the implementation of `BaseProtocol.hello`. Currently no doc comment is associated with `MyStruct.hello`.

rdar://126240546
2024-08-02 11:26:51 -07:00
Hamish Knight
bfa3ad063d [ASTPrinter] Print some as a keyword
This is consistent with how the TypeRepr is
printed.
2024-07-13 14:55:35 +01:00
Joseph Heck
d3ff97dfc0 inspects class to determine if its a class, actor, or distributed actor for symbol graph generation (#74155)
rdar://84751310
2024-06-25 09:37:35 -06:00
Daniel Grumberg
d960101422 Add test to check nested exported imports in SymbolGraphGen 2024-04-25 11:33:15 +01:00
Daniel Grumberg
9964884809 Recursively collect exported imports to allow fetching all visible Decls for symbol graph generation
This change is two fold. Firstly it enables collection of exported
imports from non source file units. Additionally this recurses through
the exported imports to ensure the transitive set is collected.

Fixes https://github.com/apple/swift/issues/59920
rdar://89687175
2024-04-25 11:33:11 +01:00
QuietMisdreavus
27443e03ab fix test to match multiple lines at once (#72396) 2024-03-19 08:36:35 -06:00
Sofía Rodríguez
082f2b01c9 [SymbolGraphGen] Import ObjC forward declarations by default. (#71947)
rdar://123279176
2024-03-04 17:29:18 -08:00
Slava Pestov
892dd4594d SymbolGraph: Fixes for noncopyable generics and some small cleanups 2024-03-01 12:55:08 -05:00
Kavon Farvardin
f296d8e158 NCGenerics: mass XFAIL tests
It's easier to get a handle on regressions while working through
failures if the tests that are known to not pass are XFAIL'd for
NoncopyableGenerics.
2024-02-20 18:26:05 -05:00
David Rönnqvist
24d54a8614 [SymbolGraphGen] Emit "functionSignature" info for initializers and subscripts (#70207)
rdar://111072228
2023-12-20 10:56:01 -07:00
Michael Spencer
b2640e15e4 [test] Rename all module.map files to module.modulemap
`module.map` as a module map name has been discouraged since 2014, and
Clang will soon warn on its usage. This patch renames all instances of
`module.map` in the Swift tests to `module.modulemap` in preparation
for this change to Clang.

rdar://106123303
2023-08-21 15:58:59 -07:00
QuietMisdreavus
632f0a33b9 don't emit symbols and protocols from unconditionally unavailable extensions (#67539)
rdar://112137607
2023-07-26 15:04:25 -06:00
Daniel Rodríguez Troitiño
70376a15f0 [ScanDependencies] Fix JSON generation under certain circunstances. (#67246)
The code of `ScanDependencies.cpp` was creating invalid JSON since #66031
because in the case of having `extraPcmArgs` and `swiftOverlayDependencies`,
but not `bridgingHeader`, a comma will not be added at the end of
`extraPcmArgs`, creating an invalid JSON file. Additionally that same PR
added a trailing comma at the end of the `swiftOverlayDependencies`, which
valid JSON does not allow, but that bug was removed in #66366.

Both problems are, however, present in the 5.9 branch, because #66936
included #66031, but not #66366.

Besides fixing the problem in `ScanDependencies.cpp` I modified every test
that uses `--scan-dependencies` to pass the produced JSON through
Python's `json.tool` in order to validate proper JSON is produced. In
most cases I was able to pipe the output of the tool into `FileCheck`,
but in some cases the validation is done by itself because the checks
depend on the exact format generated by `--scan-dependencies`. In
a couple of tests I added a call to `FileCheck` that seemed to be
missing.

Without these changes, two tests seems to be generating invalid JSON in
my machine:

- `ScanDependencies/local_cache_consistency.swift` (which outputs `Expecting ',' delimiter: line 525 column 11 (char 22799)`)
- `ScanDependencies/placholder_overlay_deps.swift`
2023-07-12 14:19:20 -07:00
QuietMisdreavus
85d59d2e55 don't use Clang modules in the "only re-export public symbols" check (#66610)
rdar://110399757
2023-06-15 10:13:18 -06:00
QuietMisdreavus
e45c9df2a3 always use the argNames constructor for macro DeclNames (#66497)
rdar://110179186
2023-06-12 09:10:02 -06:00