Skip to content
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

UniFFI Dart Binding Generator Refactor and Added Async Support #37

Merged
merged 67 commits into from
Aug 25, 2024

Conversation

chavic
Copy link
Contributor

@chavic chavic commented Jul 30, 2024

Here's a summary overview of what's in this PR, some things were skipped because the codebase was in a satisfactory state, and it may not include other possible improvements (undone)... This should be enough to continue adding features

  • Adopted modular structure for primitives (separate files for different types)
  • Reorganized project structure for better maintainability
  • Integrated explicit async support (async_poll, async_complete, async_free)
  • Ensured compatibility with existing synchronous operations
  • Implemented separate files for boolean, string, and duration types
  • Refactored existing primitive types for consistency
  • Enhanced record implementation with read, write, and allocation size methods
  • Implemented comprehensive enum support, including complex variants with fields
  • Updated existing enum usages to leverage new capabilities
  • Integrated external_type_package_name method
  • Documented usage of external type handling
  • Combined detailed FFI type conversion with a simplified approach
  • Implemented unified FFI conversion strategy
  • Integrated DurationCodeType
  • Ensured proper usage in relevant parts of the codebase
  • Implemented LiftRetVal struct for more precise lifting
  • Updated existing lifting operations to use new structure
  • Implemented refined UniffiInternalError
  • Updated error handling throughout the codebase
  • Merged best practices from both codebases
  • Implemented a more structured approach to code generation
  • Merged TypeHelpersRenderer, keeping useful methods from both codebases
  • Ensured consistent usage of type helpers throughout the project
  • Evaluated and combined the best parts of object handling
  • Optimized critical paths for better performance
  • Implemented benchmarks for key operations

@chavic chavic requested review from gnunicorn and gtalha07 July 30, 2024 13:58
src/gen/enums.rs Outdated
final $(var_name(f.name())) = $(var_name(f.name()))_lifted.value;
new_offset += $(var_name(f.name()))_lifted.bytesRead;
)
return LiftRetVal($(class_name(obj.name()))$cls_name._(
$(for f in obj.fields() => $(var_name(f.name())),)
), new_offset);
), new_offset - buf.offsetInBytes);
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems incorrect, why are you substracting the original offset?

Copy link
Contributor Author

@chavic chavic Aug 21, 2024

Choose a reason for hiding this comment

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

I'll revert this, interestingly it didn't trigger an error in the tests for both chases

Copy link
Contributor

Choose a reason for hiding this comment

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

is this just a move? if so, where is the code of the original being removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this branch is a backup of what we had before I made any "destructive" changes that would make it harder to track the history of changes

Copy link
Contributor

Choose a reason for hiding this comment

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

same here... is that actually new or just a move? If so, where is the diff to remove the original?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, most of the code would consist of moves from yours and my history, with changes whenever approaches need to be combined or the better one is chosen and refactors are required

@@ -64,7 +64,7 @@ pub fn generate_enum(obj: &Enum, type_helper: &dyn TypeHelperRenderer) -> dart::
}

class $ffi_converter_name {
static $cls_name lift(RustBuffer buffer) {
static $cls_name lift( RustBuffer buffer) {
Copy link
Contributor

Choose a reason for hiding this comment

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

the diff of this file contains mainly spaces after ( ... why?


use crate::gen::oracle::DartCodeOracle;
use crate::gen::render::AsRenderable;

use super::oracle::AsCodeType;
use super::render::TypeHelperRenderer;

// #[allow(unused_variables)]
Copy link
Contributor

Choose a reason for hiding this comment

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

???? why is this added?

src/gen/mod.rs Outdated
@@ -30,6 +31,25 @@ pub struct Config {
external_packages: HashMap<String, String>,
}

// impl MergeWith for Config {
Copy link
Contributor

Choose a reason for hiding this comment

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

and this? why re-add this?

pub fn generate_method(func: &Method, type_helper: &dyn TypeHelperRenderer) -> dart::Tokens {
#[allow(unused_variables)]
pub fn generate_method(func: &Method, type_helper: &dyn TypeHelperRenderer) -> dart::Tokens {
// let api = "_api";
Copy link
Contributor

Choose a reason for hiding this comment

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

here again?!?

src/gen/types.rs Outdated
@@ -166,6 +168,268 @@ impl Renderer<(FunctionDefinition, dart::Tokens)> for TypeHelpersRenderer<'_> {
import "package:ffi/ffi.dart";
$(imports)

// class UniffiInternalError implements Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't get it. what are all these about?

@@ -136,14 +137,19 @@ impl TypeHelperRenderer for TypeHelpersRenderer<'_> {
}

impl Renderer<(FunctionDefinition, dart::Tokens)> for TypeHelpersRenderer<'_> {
// TODO: Implimient a two pass system where the first pass will render the main code, and the second pass will render the helper code
Copy link
Contributor

Choose a reason for hiding this comment

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

please do not put FIXME or TODOs in the code. They belong as issues in the issue tracker.

@@ -270,7 +270,23 @@ impl<T: AsType> AsCodeType for T {
Type::Record { name, module_path } => {
Box::new(records::RecordCodeType::new(name, module_path))
}
_ => todo!("As Type for Type::{:?}", self.as_type()),
_ => todo!("As Type for Type::{:?}", self.as_type()), // Type::Bytes => Box::new(primitives::BytesCodeType),
Copy link
Contributor

Choose a reason for hiding this comment

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

what are these comments about?

@gnunicorn
Copy link
Contributor

I've reviewed only the newly added commits compared to what I have already seen, but I don't quite understand what is going on there. There is a lot of commented code added for an known reason but nothing really seem of material value ..?

@gnunicorn
Copy link
Contributor

It has become impossible to follow this. Let's fix the CI, merge this and handle the fallout from there.

@chavic chavic changed the title UniFFI Dart Binding Generator Refactor and Added Async Support (Quashed History) UniFFI Dart Binding Generator Refactor and Added Async Support Aug 19, 2024
@chavic chavic requested a review from gnunicorn August 19, 2024 10:37
@chavic
Copy link
Contributor Author

chavic commented Aug 21, 2024

It has become impossible to follow this. Let's fix the CI, merge this and handle the fallout from there.

okay, this is mostly due to the way I handled merging the two branches... but there's a backup of the code before I did that in this branch

@chavic chavic merged commit 46f9f7b into acterglobal:main Aug 25, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants