Skip to content

Commit d2d37e5

Browse files
ssbrcopybara-github
authored andcommitted
Simplify HasBindings by removing Maybe.
It literally only applies to functions, as a general category of thing. Or at least, we can divide it on types in the IR, instead of writing it down here. Removing it is a strict simplification, see delta, and makes future changes a bit easier potentially. It also changes "this only applies to functions" from a thing that happens to be true but isn't easy to see by reading the codebase, to something that is explicitly noted with a `!matches!(item, Item::Func)`. PiperOrigin-RevId: 747938928 Change-Id: I6c09aeec61e0662bf852a292c3c7db33910df51a
1 parent ef02741 commit d2d37e5

File tree

3 files changed

+2
-25
lines changed

3 files changed

+2
-25
lines changed

rs_bindings_from_cc/generate_bindings/has_bindings.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,9 @@ use std::rc::Rc;
1010

1111
#[derive(Clone, PartialEq, Eq)]
1212
pub enum HasBindings {
13-
/// This item is guaranteed to have bindings. If the translation unit
14-
/// defining the item fails to generate bindings for it, it will not
15-
/// compile.
13+
/// This item will have bindings. This is *guaranteed*, if the item isn't a `Func`.
1614
Yes,
1715

18-
/// This item is not guaranteed to have bindings. There is no way to tell if
19-
/// bindings were generated unless the item is defined in the current
20-
/// translation unit.
21-
Maybe,
22-
2316
/// These bindings are guaranteed not to exist.
2417
No(NoBindingsReason),
2518
}
@@ -71,13 +64,6 @@ pub fn has_bindings(db: &dyn BindingsGenerator, item: &Item) -> HasBindings {
7164
error: no_parent_bindings.into(),
7265
});
7366
}
74-
HasBindings::Maybe => {
75-
// This shouldn't happen, Maybe is meant for Func items.
76-
return HasBindings::No(NoBindingsReason::DependencyFailed {
77-
context: item.debug_name(&ir),
78-
error: anyhow!("parent item might not be defined"),
79-
});
80-
}
8167
HasBindings::Yes => {}
8268
}
8369

@@ -95,9 +81,6 @@ pub fn has_bindings(db: &dyn BindingsGenerator, item: &Item) -> HasBindings {
9581
}
9682

9783
match item {
98-
// Function bindings aren't guaranteed, because they don't _need_ to be guaranteed. We
99-
// choose not to generate code which relies on functions existing in other TUs.
100-
Item::Func(..) => HasBindings::Maybe,
10184
Item::TypeAlias(alias) => match db.rs_type_kind(alias.underlying_type.clone()) {
10285
Ok(_) => HasBindings::Yes,
10386
Err(error) => HasBindings::No(NoBindingsReason::DependencyFailed {

rs_bindings_from_cc/generate_bindings/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ fn generate_item(db: &dyn BindingsGenerator, item: Item) -> Result<ApiSnippets>
231231
UnsupportedItem::new_with_cause(db.ir(), &enum_, Some(unsupported_item_path), err)
232232
}
233233
_ => {
234-
if has_bindings(db, &item) == HasBindings::Yes {
234+
if has_bindings(db, &item) == HasBindings::Yes && !matches!(item, Item::Func(_)) {
235235
return Err(err);
236236
}
237237
// FIXME(cramertj): get paths here in more cases. It may be that

rs_bindings_from_cc/generate_bindings/rs_type_kind.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,6 @@ pub fn rs_type_kind(db: &dyn BindingsGenerator, ty: CcType) -> Result<RsTypeKind
103103
{
104104
return db.rs_type_kind(fallback_type.clone());
105105
}
106-
(HasBindings::Maybe, _) => {
107-
bail!(
108-
"Type {} may or may not exist, and cannot be used.",
109-
item.debug_name(&ir)
110-
);
111-
}
112106
(HasBindings::No(reason), _) => {
113107
return Err(reason.into());
114108
}

0 commit comments

Comments
 (0)