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

Filter out lookup_can_derive_copy for template type #2764

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions bindgen/ir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2767,6 +2767,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
let id = id.into();

!self.lookup_has_type_param_in_array(id) &&
!self.lookup_is_type_param_after_resolve(id) &&
!self.cannot_derive_copy.as_ref().unwrap().contains(&id)
}

Expand Down Expand Up @@ -2796,6 +2797,25 @@ If you encounter an error missing from this list, please file an issue or a PR!"
.contains(&id.into())
}

/// Look up whether the item with `id` is type parameter after resolve.
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs a test, but it seems to me this should happen in the can_derive_copy analysis.

Copy link
Author

Choose a reason for hiding this comment

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

I will add test to verify regression.

As for can_derive_copy analysis, it makes sense to me as this can be analyzed before actual codegen. But it's not clear to me how. I skimmed over CannotDerive.constrain_type() and it's a bit hard where the code required.

image

This is graph from the problematic code. What I was trying is to make Item(2)(_Tp) CanDerive::No. From my undesrtanding, the basis is TypeParam which Union refers need to be CanDevice::No. But I saw it's bit hard because it's back edge from TypeParam.

Am I correctly understanding basic strategy? If then, how can I make _Tp CanDevice::No?

Copy link
Author

Choose a reason for hiding this comment

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

@emilio Gentle reminder.

fn lookup_is_type_param_after_resolve<Id: Into<ItemId>>(
&self,
id: Id,
) -> bool {
if let Some(t) = id
.into()
.into_resolver()
.through_type_refs()
.resolve(self)
.kind()
.as_type()
{
t.is_type_param()
} else {
false
}
}

/// Compute whether the type has float.
fn compute_has_float(&mut self) {
let _t = self.timer("compute_has_float");
Expand Down
Loading