Skip to content

Conversation

@Gustl22
Copy link
Contributor

@Gustl22 Gustl22 commented Mar 16, 2024

Part of #137040 and #80374

  • Extracted getting plugin implementation candidates and the default implementation to its own method
  • Extracted resolving the plugin implementation to its own method
  • Simplify candidate selection algorithm
  • Support overriding inline dart implementation for an app-facing plugin
  • Throw error, if a federated plugin implements an app-facing plugin, but also references a default implementation
  • Throw error, if a plugin provides an inline implementation, but also references a default implementation

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Mar 16, 2024
@Gustl22 Gustl22 force-pushed the 80374-refactor-5 branch from 4bd60c1 to b5d72e4 Compare April 5, 2024 05:37
WindowsPlugin.kConfigKey,
];
final List<PluginInterfaceResolution> finalResolution = <PluginInterfaceResolution>[];
final List<PluginInterfaceResolution> pluginResolutions = <PluginInterfaceResolution>[];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adapted the naming, as "final" is not very descriptive. Instead renaming the other scoped variables should add more clarity.

for (final String platformKey in platformKeys) {
// Key: the plugin name
final Map<String, List<Plugin>> possibleResolutions = <String, List<Plugin>>{};
final Map<String, List<Plugin>> pluginImplCandidates = <String, List<Plugin>>{};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Speaking now of "implementation candidates" as used here already.

String? implementsPackage = plugin.implementsPackage;
if (implementsPackage == null || implementsPackage.isEmpty) {
final bool hasInlineDartImplementation =
plugin.pluginDartClassPlatforms[platformKey] != null;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here an "inline dart implementation" is defined when if it has no dart plugin class. Here also it is excluded, if it has the none keyword. I suspect the none String basically is never used so it worked, but I unified the variable here. If you have doubts, let me know.

@Gustl22 Gustl22 marked this pull request as ready for review April 5, 2024 06:28
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact "@test-exemption-reviewer" in the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@Gustl22
Copy link
Contributor Author

Gustl22 commented Apr 5, 2024

\cc @christopherfujino @stuartmorgan for sneak in a review / adding reviewers.

Needs adding test-exempt as its a refactor only. Thanks again for taking the time.

@stuartmorgan-g stuartmorgan-g self-requested a review April 5, 2024 10:31
@stuartmorgan-g
Copy link
Contributor

test-exempt: code refactor with no semantic change

@Gustl22
Copy link
Contributor Author

Gustl22 commented Apr 5, 2024

Thanks for the very fast review 🎉! I try to resolve your comments in the next few days :)

@Gustl22
Copy link
Contributor Author

Gustl22 commented Apr 6, 2024

Thank you very much for the fast and helpful feedback. The method description was admittedly misleading.
I now added a precise method description and renamed some variables to gain more clarity in 12a38f9.
If anything seems odd to you, let me know!

@Gustl22 Gustl22 requested a review from stuartmorgan-g April 6, 2024 08:53
@Gustl22
Copy link
Contributor Author

Gustl22 commented Apr 19, 2024

@stuartmorgan any chance to throw in a review before the weekend. Merci :)

@Gustl22 Gustl22 requested a review from stuartmorgan-g April 20, 2024 15:50
@Gustl22
Copy link
Contributor Author

Gustl22 commented Apr 20, 2024

@stuartmorgan If you have time, can you give me a quick feedback / clarification to my answers, so I'll try to implement them accordingly.

@Gustl22 Gustl22 force-pushed the 80374-refactor-5 branch 2 times, most recently from 13656ab to 918ca5d Compare April 22, 2024 23:51
@Gustl22 Gustl22 changed the title refactor: Rework getting plugin implementation candidates and plugin resolution feat: Rework getting plugin implementation candidates and plugin resolution Apr 23, 2024
Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I find this version far easier to follow! Just small things left.


if (defaultImplPluginName != null) {
if (implementsPackage != null && implementsPackage.isNotEmpty) {
throwToolExit(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this new error? It would certainly be a deeply weird structure for a plugin to be both an implementation of another plugin and also a platform interface for itself, but why do we need to go to the extent of forbidding it?

Copy link
Contributor Author

@Gustl22 Gustl22 Apr 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For explaining that, we have to look into the former implementation. There, the case was not really considered. It was assumed, that if a package has an implementsPackage, it does not also have a defaultImplPlugin, so it was registered as implementation only, but did not reference a default plugin, which is wrong (unless I missed something).

So we can allow this of course, but then I would also add / rewrite that test to support that behavior officially.
Then we also have to evaluate, if the defaultImplPlugin serves also as default implementation for implementsPackage (the app-facing one) or just for the current handled plugin (in the middle of the dependency tree). So consequently the current plugin then must not serve as implementation for the app-facing package, but it's default implementation should have it's role, which brings back the complicated relations between defaultImpl and implements in the code.

The only scenario, I can think of is, that a federated plugin implements multiple platforms (inline, e.g. for ios, macos). But uses a default implementation for e.g. android, which was not added as default implementation in the app-facing package, for whatever reason.

But this behavior wasn't supported until now (at least how I interpret the current code), and this needs precise testing (probably with a real world example, if the changes actually work), in case we want to support it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would propose opening an issue and link it in the error description, so one with a valid use case can further contribute to this. I think this was not explicitly part of the design doc and I would avoid enabling more features, which are beyond the scope of this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we would preserve the existing behavior rather than introduce a new hard error, but on the other hand since currently anything doing this is wrong, I guess I'm fine with a new error. If we get issues filed because some packages are (presumably accidentally) actually doing this, we can re-evaluate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the error description to be more engaging, so the devs know, that this is not a hard limitation (685285f)

@Gustl22 Gustl22 requested a review from stuartmorgan-g April 26, 2024 21:22
@Gustl22
Copy link
Contributor Author

Gustl22 commented Apr 26, 2024

@stuartmorgan Thanks for the review! With exception of the error for disallowing default/implements at the same time, I tackled all the proposals. Let me know, what you think, how we should proceed in this case. Best regards.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@christopherfujino christopherfujino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@christopherfujino christopherfujino added the autosubmit Merge PR when tree becomes green via auto submit App label May 7, 2024
@auto-submit auto-submit bot merged commit be3e916 into flutter:master May 7, 2024
@Gustl22 Gustl22 deleted the 80374-refactor-5 branch May 7, 2024 22:15
@Gustl22
Copy link
Contributor Author

Gustl22 commented May 8, 2024

Thank you both for taking the time!

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 8, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 8, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 8, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 8, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants