Skip to content

[SymbolGraphGen] synthesize child symbols for type aliases of private decls #78959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 29, 2025

Conversation

QuietMisdreavus
Copy link
Contributor

Resolves rdar://141460819

Consider the following C code:

typedef struct {
  int myField;
} MyStruct;

typedef struct OtherStruct {
  int myField;
} OtherStruct;

When this C code is processed in ClangImporter, it initially sees four top-level Clang decls: two typedefs and their respective underlying struct decls, one anonymous and one named. In canSkipOverTypedef, it then folds the underlying type into the typedef decl, creating two final Swift top-level decls.

However, when processing this code:

typedef struct _MyStruct {
  int myField;
} MyStruct;

...this folding process fails, instead creating Swift decls for both the typedef and its underlying type.

When these decls are then rendered in SymbolGraphGen, the underlying struct decl is then hidden, due to its underscored name, leaving the converted type alias pointing to nowhere.

This PR adds behavior in SymbolGraphGen to effectively fold these decls together: When a type alias (including a converted Clang typedef) is encountered whose underlying type is (1) from the same module and (2) hidden by the current settings, it will crawl the underlying type and create synthesized symbols to clone its children as children of the type alias.

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please smoke test

@@ -232,6 +232,18 @@ void SymbolGraph::recordEdge(Symbol Source,

void SymbolGraph::recordMemberRelationship(Symbol S) {
const auto *DC = S.getLocalSymbolDecl()->getDeclContext();
const ValueDecl *ParentDecl = DC->getSelfNominalTypeDecl();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we also need to support the other kinds of relationships like inheritsFrom, requirementOf, etc.?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I handled the other kinds of relationship that are necessary for type declarations in b7079f4 - this includes inheritsFrom and conformsTo, since requirementOf only applies to method declarations on protocols. Any other relationship kind that applies to the synthesized children will happen as these symbols are processed.

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please smoke test

@QuietMisdreavus QuietMisdreavus merged commit b1871fb into main Jan 29, 2025
3 checks passed
@QuietMisdreavus QuietMisdreavus deleted the vgm/underscore-typedef branch January 29, 2025 19:39
QuietMisdreavus added a commit that referenced this pull request Feb 6, 2025
)

* Revert "Revert "[SymbolGraphGen] synthesize child symbols for type aliases of private…" (#79062)"

This reverts commit cac8297.

* clean up use of DenseMap in SymbolGraphGen

rdar://143865173
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants