Replace duck typing with protocols for target and CustomTargetIndex types - #15930
Open
bonzini wants to merge 21 commits into
Open
Replace duck typing with protocols for target and CustomTargetIndex types#15930bonzini wants to merge 21 commits into
bonzini wants to merge 21 commits into
Conversation
11 tasks
dnicolodi
reviewed
Jun 16, 2026
dnicolodi
reviewed
Jun 16, 2026
dnicolodi
reviewed
Jun 16, 2026
dnicolodi
reviewed
Jun 16, 2026
bonzini
marked this pull request as ready for review
June 16, 2026 13:36
bonzini
force-pushed
the
typing-protos
branch
2 times, most recently
from
June 18, 2026 11:03
93d177b to
81b1442
Compare
dnicolodi
reviewed
Aug 12, 2026
dnicolodi
reviewed
Aug 12, 2026
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
It can be handled simply like CustomTarget in eval_custom_target_command. This means that flatten_command does little more than collecting dependencies now. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
After the previous change, the only change made to the command is the resolution of LocalPrograms, which in turn is necessary to properly add their underlying Files to depend_files or dependencies. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
It cannot include GeneratedList, but it can include other RunTargets. While not allowed by the front-end, it is allowed by the RunTarget class and used by modules. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This is called with isinstance checks on CommandTypes, so the right type is BuildTargetTypes (coming from the Union). Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
t.get_outputs()[0] returns the same as get_filename() for both CustomTarget and CustomTargetIndex. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
__str__ is defined for target types as self.name, but not for CustomTargetIndex. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
... where CustomTargetIndexes or even CustomTargets are not possible. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This will help with resolving BothLibraries recursively. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Document precisely what is required, and in particular that AnyTargetProto is not hashable. The old type union is not needed anymore. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Document precisely what is required, the old type union is not needed anymore outside the interpreter. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Replace the abstract class LinkableTarget and the LinkableTargetTypes union with a protocol. For the abstract class, in particular, there are no concrete methods and there is no need for isinstance tests, so they are interchangeable. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
It is expected by InternalDependency. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Document precisely what's needed, and remove the last two union types. Union types should be reserved for "faking" sum types via isinstance. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Making a CommandTarget superclass out of RunTarget and CustomTarget is not really possible because RunTarget allows non-BuildTargetProtos in dependencies; or at least it would do nothing more than a protocol, and in particular it would not be able to include flatten_command(). So use a protocol instead. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Contributor
Author
|
I plan to commit this in a couple of weeks, to give more time for review. Updates to the protocols on conflicts have been easy to apply, and never ballooned to the declarations. Furthermore, simplifications in the types (especially the removal of unions) will make it much easier to fix #16159. So I think this concept has more or less proved itself. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR continues the idea of limiting Union to cases where individual members are categorized with
isinstancetests. Instead, cases where Meson mostly uses duck typing between CustomTargetBase and BuildTarget are now handled with protocols. Whileisinstancetests are occasionally used with types declared as*Prototypes, this use is relatively rare, especially in the interpreter->build interface.