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
Add async method code generation #490
Conversation
src/analysis/bounds.rs
Outdated
) -> (Option<String>, Option<String>) { | ||
let type_name = bounds_rust_type(env, par.typ); | ||
let mut type_string = | ||
if async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose you could write it like this:
if async && async_param_to_remove(&par.name) {
return (None, None);
} else {
type_name.into_string()
}
src/analysis/bounds.rs
Outdated
info_for_next_type: false, | ||
}); | ||
return true; | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This else
condition is unnecessary since the if
returns.
src/analysis/bounds.rs
Outdated
@@ -196,18 +236,20 @@ impl Bounds { | |||
pub fn get_parameter_alias_info(&self, name: &str) -> Option<(char, BoundType)> { | |||
self.used | |||
.iter() | |||
.find(move |n| if n.parameter_name == name { | |||
.find(move |n| { | |||
if n.parameter_name == name { | |||
!n.info_for_next_type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indent is broken in here. :p
src/analysis/function_parameters.rs
Outdated
}; | ||
|
||
if async_func { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if async_func && async_param_to_remove(&par.name) {
add_rust_parameter = false;
}
src/analysis/rust_type.rs
Outdated
) -> Result { | ||
use library::Type::*; | ||
let type_ = env.library.type_(type_id); | ||
let rust_type = rust_type_full(env, type_id, nullable, ref_mode); | ||
match *type_ { | ||
Fundamental(super::library::Fundamental::Pointer) if async => Ok("TODO4".to_string()), // FIXME: remove |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wut?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, some TODO that are not generated.
I'll have to figure out why.
What I'm seeing for the moment seems correct (even if it seems incomplete). However I'm not the maintainer in here hehe. |
Can you create a PR for gio with the changes this would add, i.e. all the implementations for the async methods in GFile? |
src/codegen/function_body_chunk.rs
Outdated
.map(|param| (param, type_mem_mode(env, param))) | ||
.map(|(param, mode)| format!("let mut {} = {};\n", param.name, mode_to_string(mode))) | ||
.collect::<Vec<_>>() | ||
.join(" "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change it to "\t\t\t\t"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll instead change that to use Chunk
directly, to avoid having code as strings.
src/codegen/function_body_chunk.rs
Outdated
Ok(({result})) | ||
}} else {{ | ||
Err(from_glib_full(error)) | ||
}}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO let result =
better be oneliner.
if id == namespaces::MAIN { | ||
return "ffi".to_string(); | ||
} | ||
format!("{}_ffi", name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Namespace.ffi_crate_name
is not same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ffi_crate_name
is only available on the other Namespace
struct.
@antoyo Overall is good idea, I slightly not like "internal trampoline" but it not so big problem. Thanks. |
@sdroege I'll do it when I get back to Canada, so maybe in one week. Thanks to all of you for your comments. |
@antoyo don't worry about trampolines. |
I've fixed all the issues you mentioned and I've fixed the async trampoline code generation. |
@antoyo No we don't have :( |
@GuillaumeGomez we add async function it this release? |
I added some comments about the generated code here gtk-rs/gio#63 |
IMHO this is good to go, judging from the generated code. |
@GuillaumeGomez Its good for me too. |
Yes if possible so I'll handle the release tomorrow as the latest (won't be able to do it before next week-end otherwise). |
@sdroege @GuillaumeGomez I wanted to fix the |
This will require to add |
For me it was already good so as you wish! |
It's ready to be merged. |
See my comment there |
I've fixed this issue in the latest commit. |
@sdroege I've fixed the other issues mentionned in the gio PR. |
@antoyo Thanks. |
Actually gtk also have async functions in |
Created fix, will add regen for Gtk too. |
Looks good to me, just need to add support for the "progress-callback" pattern in the future, as used by various async operations |
Add async method code generation
For now, it's usable (tested with gio, gtk and sourceview), but we could improve the heuristic as mentionned in the TODO comment.
The other two things that will be implemented in next PRs will be the annotation to specify what is the finish function when it cannot be guessed and writing Unimplemented next to Cancellable when this type does not exist (i.e. when the user forgets to add it to
Gir.toml
).I believe some code should be improved, especially the trampoline code generation.
If you have any other improvements, I'd be glad to hear them.