Skip to content

[pigeon] Adds ProxyApi code generation for Dart #5544

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

Closed
wants to merge 89 commits into from

Conversation

bparrishMines
Copy link
Contributor

@bparrishMines bparrishMines commented Dec 3, 2023

Part of flutter/flutter#134777

  • Splits Api into AstHostApi/AstFlutterApi/AstProxyApi. I prefixed it with Ast since the annotations already had the names HostApi, etc...;
  • Api.location was moved to Method.location since AstProxyApi has methods implemented on the host and Flutter side.
  • Replaces a few of the methods in lib/functional.dart with the package:collection equivalent.
  • DartGenerator.writeProxyApi uses code_builder and dart_style which I added to the allowed deps config file.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

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

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.

I left some high-level comments; @tarrinneal should be the main reviewer for most of the details.

I didn't review the generated code since I'm assuming it's not substantially changed from the webview_flutter version. If there's anything there you do want me to look at, let me know!

One thing that wasn't immediately obvious to me without tracing all the logic: are the big blocks of generated code conditional on using them? I.e., would this be basically a no-op for people not using proxy APIs, or would they suddenly get thousands of new lines of generated code they didn't need?

}

/// Represents a constructor for an API.
class Constructor extends Node {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does a constructor have to be a special type? It seems like all the properties are standard method properties.

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 think this is similar to our discussion about parameter vs field. They overlap but some of the parameters don't apply (e.g. static/isAsynchronous). However, if I consider the Method as the message call and not the AST class member, then I suppose they are essentially the same thing. I still need to distinguish the difference between Constructors for the Dart code generation, so I think I will keep the class and have it extend Method.

},
);
indent.format('''
/// Maintains instances used to communicate with the native objects they
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should probably put giant strings like this into a helper file, wrapped in a method that takes all the necessary variables, but without any logic ideally.

]),
),
];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is quite a method.

Maybe we could have a separate file for all the proxy-specific code? Then it would be easier to do things like extract helpers for different sections without overwhelming the rest of this file.

}''');
}

void _writeFlutterMethodMessageHandler(
Copy link
Contributor

Choose a reason for hiding this comment

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

Some of these incidental refactors could ideally be done in a prequel PR that would be trivial to review.

}''');
}

void _writeFlutterMethodMessageHandler(
Copy link
Contributor

Choose a reason for hiding this comment

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

Some of these incidental refactors could ideally be done in a prequel PR that would be trivial to review.

@@ -1335,6 +1767,88 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor<Object?> {
message: 'Expected a named type but found "$node".',
lineNumber: _calculateLineNumber(source, node.offset)));
}
} else if (_currentApi is AstProxyApi) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we extract all of this block to a helper?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in #5861

@@ -699,3 +699,460 @@ class TestMessage {
// ignore: always_specify_types, strict_raw_type
List? testList;
}

/// The core interface that each host language plugin must implement in
Copy link
Contributor

Choose a reason for hiding this comment

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

This may be a case where we do actually want to make a second file instead of putting everything into the one giant file?

@bparrishMines
Copy link
Contributor Author

I'm going to mark this as a draft and split it up into simpler PRs. I will still keep this PR open since it is still useful to demonstrate all the changes put together.

@bparrishMines bparrishMines marked this pull request as draft January 10, 2024 19:41
@bparrishMines
Copy link
Contributor Author

One thing that wasn't immediately obvious to me without tracing all the logic: are the big blocks of generated code conditional on using them? I.e., would this be basically a no-op for people not using proxy APIs, or would they suddenly get thousands of new lines of generated code they didn't need?

Yes, the generation of the InstanceManager/InstanceManagerApi/ProxyApiCode are all dependent on whether there is a ProxyApi. I will include a test for this in the PR that implements the code generation.

auto-submit bot pushed a commit that referenced this pull request Jan 17, 2024
… in the `DartGenerator` (#5859)

Separates message call code generation into separate methods in the  `DartGenerator` for flutter/flutter#134777. The `ProxyApi` generator uses similar code to the `HostApi` and `FlutterApi`, so this makes the code reusable.

Separated from #5544

From suggestion: #5544 (comment)
auto-submit bot pushed a commit that referenced this pull request Jan 17, 2024
… in the KotlinGenerator (#5891)

Separates message call code generation into separate methods in the KotlinGenerator for flutter/flutter#134777. The ProxyApi generator uses similar code to the HostApi and FlutterApi, so this makes the code reusable.

From suggestion: #5544 (comment)
@bparrishMines
Copy link
Contributor Author

closing if favor of #6043

@bparrishMines bparrishMines deleted the pigeon_wrapper_dart branch February 29, 2024 18:22
auto-submit bot pushed a commit that referenced this pull request Mar 5, 2024
… in the SwiftGenerator (#5959)

Separates message call code generation into separate methods in the SwiftGenerator for flutter/flutter#134777. The ProxyApi generator uses similar code to the HostApi and FlutterApi, so this makes the code reusable.

From suggestion: #5544 (comment)
LouiseHsu pushed a commit to LouiseHsu/packages that referenced this pull request Mar 7, 2024
… in the SwiftGenerator (flutter#5959)

Separates message call code generation into separate methods in the SwiftGenerator for flutter/flutter#134777. The ProxyApi generator uses similar code to the HostApi and FlutterApi, so this makes the code reusable.

From suggestion: flutter#5544 (comment)
arc-yong pushed a commit to Arctuition/packages-arc that referenced this pull request Jun 14, 2024
… in the `DartGenerator` (flutter#5859)

Separates message call code generation into separate methods in the  `DartGenerator` for flutter/flutter#134777. The `ProxyApi` generator uses similar code to the `HostApi` and `FlutterApi`, so this makes the code reusable.

Separated from flutter#5544

From suggestion: flutter#5544 (comment)
arc-yong pushed a commit to Arctuition/packages-arc that referenced this pull request Jun 14, 2024
… in the KotlinGenerator (flutter#5891)

Separates message call code generation into separate methods in the KotlinGenerator for flutter/flutter#134777. The ProxyApi generator uses similar code to the HostApi and FlutterApi, so this makes the code reusable.

From suggestion: flutter#5544 (comment)
arc-yong pushed a commit to Arctuition/packages-arc that referenced this pull request Jun 14, 2024
… in the SwiftGenerator (flutter#5959)

Separates message call code generation into separate methods in the SwiftGenerator for flutter/flutter#134777. The ProxyApi generator uses similar code to the HostApi and FlutterApi, so this makes the code reusable.

From suggestion: flutter#5544 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants