Skip to content

Commit

Permalink
Added MaybeUninit and code size options
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Ovadia committed May 25, 2024
1 parent f40d736 commit 861148d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
6 changes: 3 additions & 3 deletions ValeRuster/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ fn infer_missing_owners(
let direct_child_keys =
include_impls_children(
crates, &primitive_name_to_uid, direct_child_uids_without_methods)?;
println!("Direct child keys: {:?}", &direct_child_keys);
// println!("Direct child keys: {:?}", &direct_child_keys);
let direct_child_uids = collapse_children(&direct_child_keys);
println!("Direct child uids: {:?}", &direct_child_uids);
// println!("Direct child uids: {:?}", &direct_child_uids);
// Now look for all their methods.
let mut method_keys = Vec::new();
for direct_child_uid in direct_child_uids {
Expand Down Expand Up @@ -498,7 +498,7 @@ fn determine_ultimate_owner(
.map(|id| (id.clone(), lookup_uid(crates, id)))
.collect::<Vec<(UId, &Item)>>();
parent_uids_and_items.sort_by_key(|(_uid, item)| item.span.as_ref().unwrap().filename.to_str().as_ref().unwrap().len());
println!("Heuristic, estimating owner for {:?} is {:?}", item_uid, parent_uids_and_items.iter().next().unwrap().clone());
// println!("Heuristic, estimating owner for {:?} is {:?}", item_uid, parent_uids_and_items.iter().next().unwrap().clone());
parent_uids_and_items
.into_iter()
.map(|x| x.0)
Expand Down
38 changes: 23 additions & 15 deletions ValeRuster/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,10 +609,16 @@ mod capi;

let output = Command::new(&cargo_path)
.args(&[
"+nightly",
"cbuild",
"--release",
&("--manifest-path=".to_string() + output_dir_path + "/Cargo.toml"),
"--destdir=clibthing",
"--target", "aarch64-apple-darwin",
"-Z", "build-std-features=panic_immediate_abort",
"-Z", "build-std=std,panic_abort",
"--library-type", "staticlib"])
.env("RUSTFLAGS", "-Zlocation-detail=none")
.output()
.with_context(|| "Failed to execute cbuild command")?;
if output.status.code() == Some(0) {
Expand Down Expand Up @@ -868,7 +874,7 @@ fn impl_from_matches_generic_args(
if let Some(trait_) = &impl_.trait_ {
if let Some(args) = &trait_.args {
match args.as_ref() {
GenericArgs::AngleBracketed { args: args, .. } => {
GenericArgs::AngleBracketed { args, .. } => {
args
}
GenericArgs::Parenthesized { .. } => unimplemented!(),
Expand Down Expand Up @@ -964,6 +970,18 @@ fn match_generic_arg_valtype(
current_height: i64,
) -> Option<i64> {
match (generic_arg, generic_param) {
// The order of these cases is important, for example we want to match
// any type to a generic variable T before we do anything else.
(_, Type::Generic(generic_param_name)) => {
generics.insert(
generic_param_name.clone(),
SimpleType {
imm_ref: false,
mut_ref: false,
valtype: generic_arg.clone()
});
Some(current_height)
}
(_, _) if is_primitive(&item_index.primitive_uid_to_name, &generic_arg.id) => {
if let Type::Primitive(generic_param_primitive_name) = generic_param {
if item_index.primitive_uid_to_name.get(&generic_arg.id).unwrap() == generic_param_primitive_name {
Expand All @@ -983,16 +1001,6 @@ fn match_generic_arg_valtype(
None
}
}
(_, Type::Generic(generic_param_name)) => {
generics.insert(
generic_param_name.clone(),
SimpleType {
imm_ref: false,
mut_ref: false,
valtype: generic_arg.clone()
});
Some(current_height)
}
(
_,
Type::ResolvedPath(rustdoc_types::Path { name: generic_param_name, args: _generic_params, .. })
Expand Down Expand Up @@ -1220,9 +1228,9 @@ fn instantiate_struct(
builder += "#[repr(C)]\n";
builder += "pub struct ";
builder += as_;
builder += " ([u8; ";
builder += " (std::mem::MaybeUninit<[u8; ";
builder += &size.to_string();
builder += "]);\n";
builder += "]>);\n";
builder += "const_assert_eq!(std::mem::size_of::<";
builder += &rustify_simple_type(&crates, &item_index, &needle_type, None)?;
builder += ">(), ";
Expand Down Expand Up @@ -1303,7 +1311,7 @@ fn instantiate_func(
}
rust_builder += &rustify_simple_type(&crates, &item_index, needle_type, Some(func))?;
rust_builder += "(";
for (param_name, param_type) in params {
for (param_name, _param_type) in params {
rust_builder += param_name;
rust_builder += "_rs,";
}
Expand All @@ -1330,7 +1338,7 @@ fn instantiate_func(
}

fn list_struct_and_methods(v: &Crate, struct_name: &String) {
for (id, item) in &v.index {
for (_id, item) in &v.index {
match &item.inner {
ItemEnum::Struct(struuct) => {
match &item.name {
Expand Down

0 comments on commit 861148d

Please sign in to comment.