Skip to content

Diagnose and forbid invalid Swift names on inits #79206

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 2 commits into from
Feb 18, 2025

Conversation

beccadax
Copy link
Contributor

@beccadax beccadax commented Feb 7, 2025

Initializers should always have Swift names that have the special DeclBaseName::createConstructor() base name. Although there is an assertion to this effect in the constructor for ConstructorDecl, ClangImporter did not actually reject custom Swift names for initializers that violated this rule. This meant that asserts compilers would crash if they encountered code with an invalid swift_name attribute, while release compilers would silently accept them (while excluding these decls from certain checks since lookups that were supposed to find all initializers didn’t find them).

Modify ClangImporter to diagnose this condition and ignore the custom Swift name.

@beccadax
Copy link
Contributor Author

beccadax commented Feb 7, 2025

@swift-ci please test

@beccadax
Copy link
Contributor Author

beccadax commented Feb 7, 2025

@swift-ci please test source compatibility

@beccadax
Copy link
Contributor Author

@swift-ci please test windows platform

@beccadax
Copy link
Contributor Author

@swift-ci please smoke test

Initializers should always have Swift names that have the special `DeclBaseName::createConstructor()` base name. Although there is an assertion to this effect in the constructor for ConstructorDecl, ClangImporter did not actually reject custom Swift names for initializers that violated this rule. This meant that asserts compilers would crash if they encountered code with an invalid `swift_name` attribute, while release compilers would silently accept them (while excluding these decls from certain checks since lookups that were supposed to find all initializers didn’t find them).

Modify ClangImporter to diagnose this condition and ignore the custom Swift name.
This commit makes a number of adjustments to how the diagnostic verifier handles source buffers and source locations. Specifically:

• Files named by `-verify-additional-file` are read as late as possible so that if some other component of the compiler has already loaded the file, even in some exotic way (e.g. ClangImporter’s source buffer mirroring), it will use the same buffer.
• Expectation source locations now ignore virtual files and other trickery; they are based on the source buffer and physical location in the file.

Hopefully this will make `-verify-additional-file` work better on Windows. As an unintended side effect, it also changes how expectations work in tests that use `#sourceLocation()`.
@beccadax beccadax force-pushed the this-name-is-not-constructive branch from 46737f8 to 0466d5c Compare February 11, 2025 20:06
@beccadax
Copy link
Contributor Author

@swift-ci please test windows platform

@beccadax
Copy link
Contributor Author

Failure seems unrelated; saw it in other Windows PR tests.

@swift-ci please smoke test windows platform

@beccadax
Copy link
Contributor Author

@swift-ci please smoke test

2 similar comments
@beccadax
Copy link
Contributor Author

@swift-ci please smoke test

@beccadax
Copy link
Contributor Author

@swift-ci please smoke test

@beccadax beccadax merged commit d8c8f65 into swiftlang:main Feb 18, 2025
3 checks passed
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