Skip to content

NFC: Work around 'cycle detected while resolving' warning #71032

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

Conversation

tshortli
Copy link
Contributor

When building the Swift sources of the compiler many instances of the following warning are emitted:

.../swift-project/swift/include/swift/AST/Attr.h:3075:10: warning: cycle detected while resolving 'iterator' in swift_name attribute for 'operator=='
    bool operator==(iterator x) const { return x.attr == attr; }
         ^

These warnings were implemented in #37940 and they indicate that Swift compiler is failing to import a clang decl because of circular references. Something about the structure of some operator declarations in C++ headers triggers this warning. I'm not sure what the correct long term fix for this is, but in the meantime the build log for the compiler is getting drowned in these warnings which makes it difficult to notice and find other diagnostics. Since these declarations are getting dropped instead of imported, we can simply hide them from the Swift compiler in the first place by guarding the declarations with #ifdef __swift__.

When building the Swift sources of the compiler many instances of the following
warning are emitted:

```
.../swift-project/swift/include/swift/AST/Attr.h:3075:10: warning: cycle detected while resolving 'iterator' in swift_name attribute for 'operator=='
    bool operator==(iterator x) const { return x.attr == attr; }
         ^
```

These warnings were implemented in swiftlang#37940
and they indicate that Swift compiler is failing to import a clang decl because
of circular references. Something about the structure of some operator
declarations in C++ headers triggers this warning. I'm not sure what the
correct long term fix for this is, but in the meantime the build log for the
compiler is getting drowned in these warnings which makes it difficult to
notice and find other diagnostics. Since these declarations are getting dropped
instead of imported, we can simply hide them from the Swift compiler in the
first place by guarding the declarations with `#ifdef __swift__`.
@tshortli
Copy link
Contributor Author

@swift-ci please smoke test

Copy link
Contributor

@egorzhdan egorzhdan left a comment

Choose a reason for hiding this comment

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

There is likely a bug in ClangImporter triggering the incorrect diagnostic for some C++ iterator types, I'll look into fixing it properly.
In the meantime, the workaround LGTM.

@tshortli tshortli merged commit ac58db8 into swiftlang:main Jan 22, 2024
@tshortli tshortli deleted the work-around-cycle-detected-while-resolving-warning branch January 22, 2024 20:13
tshortli added a commit to tshortli/apple-llvm-project that referenced this pull request Mar 3, 2024
Swift C++ interop has a bug where certain operator declarations cannot be
imported successfully due to percieved circular references in the declarations.
Since these declarations are already dropped by the ClangImporter, it's helpful
to hide the declarations entirely from Swift to avoid spurious diagnostics that
cannot be addressed. See swiftlang/swift#71032 for a
similar workaround in the Swift compiler implementation.
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