-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add development-time assertions to catch errors where two llbuild commands are created with the same name #3587
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
…mands are created with the same name. Otherwise this results in silently replacing some commands in the graph. We can discuss whether a future improvement would be to make these internal errors reported at runtime.
@swift-ci please smoke test |
So it seems that this can happen also on macOS, at least when running unit tests manually using The inputs are not the same, however; in one case @artemcm do you know if this is expected? I can elaborate more about this, but wanted to first check it it was expected that multiple LLBuild manifest commands would be generated with the same name and only one of them kept. It's possible that this is harmless, but it could also be an intermittent bug if there is some nondeterminism to the order in which these commands are created. |
Yes, with explicit modules (the test in question), it is expected that we may produce multiple jobs to build the same module. If we're separately planning any two targets, The desired outcome is that these identical commands get de-duplicated by making sure they result in only one executable job in LLBuild. The fact that one of the input files here differs (in name, not in content...) may prevent that though, and is something we should fix.
This is a great point, we should make the code do this explicitly. |
Sounds good. I'll leave this PR open in Draft mode until then, so that we can get these development-time checks in after that lands, in order to catch future problems. |
@artemcm Is this something we can bring back at this point? i.e. has the issue with SwiftDriver creating duplicate commands been resolved? |
The missing piece is not preventing SwiftDriver from creating duplicate commands, but rather filtering those duplicate commands before they make it down to LLBuild. SwiftDriver should not have the context to know whether a job it is emitting is duplicate as part of the larger build because it only handles building a single module at a time. Maybe when translating the driver's |
It should happen somewhere above the manifest generation, because otherwise there isn't a good place to detect accidental overwriting of previous commands (as happened in the original bug that prompted this PR). Basically, whoever is emitting llbuild commands should use some criteria to determine whether two commands it has generated are the same, and if so, not emit the second (or third, etc) ones. If SwiftDriver doesn't know, then whatever translates |
@artemcm How do we move forward on this? Having the default behavior for llbuild manifests be that commands get silently dropped seems bad (this whole thing started because of a bug in plugins that was due to accidentally overwriting multiple commands). I could see an option to allow it, or deduping at a higher level, or a variety of other solutions that don't involve silently dropping commands on the ground in the default case. That's just more bugs awaiting to happen. |
@abertelrud, I think deduplication at a higher level is the way to address this. |
Thanks @artemcm that sounds great. If we do need an option (which clients would have to opt into) to say "yes replace any existing command with the same name" then that would work too, but if it makes sense to do at a higher level I think that would be preferable (as "Builder" patterns don't usually involve replacing parts of what was already added to the builder during the same build). |
@abertelrud #3769 is an attempt to ensure we don't add duplicates to the LLBuild manifest. |
Otherwise this results in silently replacing some commands in the graph. We can discuss whether a future improvement would be to make these internal errors reported at runtime.
Motivation:
Without these assertions, adding two or more commands with the same name result in only the last of them remaining, which can lead to hard-to-diagnose build failures. I have to not come across any cases of this happening intentionally, but there is currently a Linux-specific test failure that I need to look closer at. It could be a bug that this is catching or could be that this needs to be made more lenient. Even if the replacement behavior is intentional, it seems like the kind of thing that should be done explicitly in the code. This was motivated by an unintentional replacement of a build command.
Modifications:
Result:
In debug builds and in tests, any replacement of llbuild commands will be made apparent.