Skip to content
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

Adding a conformance apparently corrupts metadata cache? #62498

Open
dabrahams opened this issue Dec 10, 2022 · 9 comments
Open

Adding a conformance apparently corrupts metadata cache? #62498

dabrahams opened this issue Dec 10, 2022 · 9 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. conformances Feature → protocol: protocol conformances crash Bug: A crash, i.e., an abnormal termination of software run-time crash Bug → crash: Swift code crashed during execution

Comments

@dabrahams
Copy link
Contributor

dabrahams commented Dec 10, 2022

Description
If I add a conformance to my project—one that isn't even used—I get a crash during testing.

Steps to reproduce
Check out the swift-conformance-crasher tag of the Val project. swift test --filter testEmitter. For me, this crashes (see attached screenshot).
Now delete the conformance of WideUInt to BinaryInteger and run the test again. For me, the test passes.

Furthermore, I can add

extension WideUInt: UnsignedInteger {}

to another module (e.g. Compiler) without incident.

Of course this doesn't prove the bug is in the compiler/runtime, but it's highly suspicious.

Expected behavior
The presence of that conformance should have no effect.

Environment

  • Swift compiler version info swift-driver version: 1.62.15 Apple Swift version 5.7.1 (swiftlang-5.7.1.135.3 clang-1400.0.29.51)
    Target: arm64-apple-macosx13.0
  • Xcode version info Xcode 14.1
    Build version 14B47b
  • Deployment target: not explicitly set.

image

@dabrahams dabrahams added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Dec 10, 2022
@AnthonyLatsis AnthonyLatsis added run-time crash Bug → crash: Swift code crashed during execution conformances Feature → protocol: protocol conformances crash Bug: A crash, i.e., an abnormal termination of software labels Dec 10, 2022
@dabrahams
Copy link
Contributor Author

I'm still reproducing this in the hylo project, FWIW.

@mikeash
Copy link
Contributor

mikeash commented Dec 1, 2023

I wasn't able to reproduce this locally, but from your screenshot it looks like you're somehow encountering infinite recursion. It just so happens that the MetadataCache code is what runs off the end of the stack and crashes. Seems that adding that conformance somehow makes part of this code call back into itself, where it doesn't do so otherwise.

@dabrahams
Copy link
Contributor Author

@mikeash, I'm really surprised it doesn't reproduce for you, as I've seen it on multiple machines. Did you try with the Hylo project, moving the WideUInt: UnsignedInteger conformance from Sources/IR/Operands/Constant/IntegerConstant.swift to Sources/Utils/WideUInt.swift?

@mikeash
Copy link
Contributor

mikeash commented Dec 1, 2023

I tried it with the swift-conformance-crasher tag of both Hylo and Val. I'm using Xcode 15.0.1, not sure if that matters. When I try to build Hylo main, it fails to build due to not finding the types SPMBuildCommand and SPMBuildToolPlugin.

@dabrahams
Copy link
Contributor Author

dabrahams commented Dec 2, 2023 via email

@dabrahams
Copy link
Contributor Author

@mikeash Even with xcode 15.0.1, swift --version still says 5.9, and swift package --version says 5.9.0. I'm running this build using SPM, so I don't see how xcode can come into the picture. How am I supposed to tell SPM that this requires xcode 15.0.1?

@mikeash
Copy link
Contributor

mikeash commented Dec 2, 2023

swift will use whatever Xcode you have selected, or the Command Line Tools if you have those installed. You can run xcode-select -p to see what's selected, and xcode-select -s /path/to/copy/of/Xcode.app to change it. You can also change it temporarily by setting the DEVELOPER_DIR environment variable to the path you want to use locally.

If the issue doesn't happen with 15.0.1 then I'd guess there's some change in method or function resolution which previously resulted in choosing a function that produced recursion, and now it doesn't. Hard to say if it was a bug fix or a just a change, but either way, it's good that it works now.

@dabrahams
Copy link
Contributor Author

I think you're misunderstanding my question. If I am going to put the conformance back where it belongs I need to use a swift-tools-version spec in Package.swift to declare that Xcode 15.0.1 is required, right? How can I do that if the Swift version didn't change between Xcode 15.0 and 15.0.1?

@mikeash
Copy link
Contributor

mikeash commented Dec 3, 2023

Oh, I see. Does it break with 15 but work with 15.0.1? That would be really weird. I don’t think there were any changes to the compiler.

@hborla hborla removed the triage needed This issue needs more specific labels label Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. conformances Feature → protocol: protocol conformances crash Bug: A crash, i.e., an abnormal termination of software run-time crash Bug → crash: Swift code crashed during execution
Projects
None yet
Development

No branches or pull requests

4 participants