-
Notifications
You must be signed in to change notification settings - Fork 447
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
Internal protocol conformance can be stripped by accident #1061
Comments
Ouch. I'll take a look. |
The toolchain we build internally is currently at snapshot 2020-08-18, but unfortunately I can't reproduce the failure with any of the public toolchains. The tests pass with the 2020-08-18 both on macOS and on a clean Ubuntu image I just fired up. I also synced our internal toolchain back to a previous state pre-2020-08-18 and it also failed there 🤔 Some This could be an issue that's only related to our internal builds. We'll scrounge around some more. |
Based on the failure messages Thomas shared, I was going to guess it was an issue with casting from a |
I figured out the issue here, after a couple hours of using The conformance There will never be references to symbols in the So, this is basically the same problem Objective-C developers faced with source files containing only categories and why the A fairly simple solution would be to just move the extension out of its own file and into a file that we know would be fetched if the implementation is needed, like JSONDecoder.swift (to pick an arbitrary but related one). Another option would be to create a dummy symbol in the file and then reference it from another dummy symbol in a file that we know will get fetched. I'll need to test if visibility matters here (e.g., |
Nice work! I've been considering adding an Alternatively, we could reasonably bundle this into any of several other files. Hmmm.... |
Given the other files like that, yes, adding something |
I tested it and just having a conformance for The issue is that nothing signals to the linker that the .o file for this conformance needs to be fetched on Linux when it's in a static archive. This is a wider-spread problem for Swift in general than just for swift-protobuf, but the rest of the Swift ecosystem manages to avoid it in various other ways that mask the problem:
The safest thing to do here would be to put the conformances in the same file as the type itself so that if the type is fetched, the conformances are as well, but since those files are generated, that makes it less appealing. This also isn't a problem for just |
So I guess the "safest" thing to do is move all the json conformances into a file that needs them so the they always get picked up? The public helpers in those files can be left as is and they will even strip correct if not needed? |
Either that, or add a symbol in that file and then reference it from a file that will be included, but that might require the symbol to be public and thus leak out of the module.
If by "strip" you mean "the object file will not be fetched by the linker from a static archive if it is not referenced" (as opposed to dead-code stripping), yes. |
Keeping this open to track since it might make sense to tweak things to avoid things breaking if someone builds a lib on linux out of the library, but it is less critical at the moment. |
ps - I forgot to mention, adding to my confusion with this when it first showed up, all of the other new tests added passed without the conformance. i.e. - they would pass for any Enum not just this one, which made me have to go try to figure out why/how they passed. |
As @allevato mentioned, SwiftPM dodges the issue, but the problem is always possible if someone builds things into a library and then links the library. While we can rearrange the sources to avoid this, it almost seems like some sorta automation to try and detect this would be a good things since we could run into this again if we added another protocol for something else. |
|
I'm going to go ahead and close this, unless we come up with a good way to test for this, even shuffling the sources to avoid the problem at the moment seems error prone as we could regress at anytime without noticing. |
Trying to sync in current HEAD to google, we're seeing some of the new tests adding when addressing #1048 fail on linux with a compiler that is close to HEAD. I'm guessing that means compiler bug, but we haven't gotten a chance to dig.
The text was updated successfully, but these errors were encountered: