Skip to content

Add more information for ForeignDef #61

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

Closed
momvart opened this issue Jan 24, 2024 · 9 comments · Fixed by rust-lang/rust#120982
Closed

Add more information for ForeignDef #61

momvart opened this issue Jan 24, 2024 · 9 comments · Fixed by rust-lang/rust#120982
Assignees

Comments

@momvart
Copy link

momvart commented Jan 24, 2024

ForeignDef items may correspond to functions, statics, or types. Based on rustc_hir::ForeignItem, we need an equivalent of ForeignItemKind.

For these variants:

  • Fn: Can FnDef be reused?
  • Static: The existing information on CrateDef should be enough.
  • Ty: Not sure if it is stable yet (#rust/43467)

Similar to existing kind types, the following changes are expected:

  • adding method foreign_item_kind to Context
  • adding method kind to FnDef calling the method above
@celinval
Copy link
Contributor

Do you mean adding kind function to ForeignDef?

@momvart
Copy link
Author

momvart commented Jan 25, 2024

Do you mean adding kind function to ForeignDef?

That's right.

@celinval
Copy link
Contributor

@oli-obk wondering if you know what kind of information users get from the ForeignDef besides name? I couldn't find any other use case in MIRI, rustc codegen or Kani. I am tempted to just have a simple ForeignItemKind enum for now to provide the kind.

@oli-obk
Copy link
Contributor

oli-obk commented Jan 25, 2024

Yea, you can't obtain more than the kind (and thus information like a static's type or a function's signature). Not sure that information is useful to anyone, as you can't rely on the other end of the foreign item to actually match

@celinval
Copy link
Contributor

celinval commented Jan 26, 2024

In theory, I think it would make sense for kind to be:

enum ForeignItemKind {
    Fn(FnDef),
    Static(StaticDef),
    Ty(Ty),
}

That said, we would need to ensure all the methods of FnDef and StaticDef work as expected. I believe we currently implement impl From<StaticDef> for CrateItem which wouldn't hold since CrateItem has to have a body. That said, I suspect that it doesn't hold for static objects that are defined outside of the compiled crate, and we should use TryFrom instead where we only convert if the item has a body.

@momvart
Copy link
Author

momvart commented Jan 26, 2024

which wouldn't hold since CrateItem has to have a body

The same happens for FnDef. Should we make the body function optional for these or introduce a super type?

we should use TryFrom instead where we only convert if the item has a body.

But it means that StaticDef (and FnDef) has to be associated with a body, which means they shouldn't be used in ForeignItemKind then.

@celinval
Copy link
Contributor

@celinval
Copy link
Contributor

I believe StaticDef doesn't necessarily need to have a body either, so that's why the conversion might be the place to fix at this point. CrateItem today has to have a body, but we have an issue open to polish that type (#34).

@momvart
Copy link
Author

momvart commented Jan 29, 2024

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 15, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 15, 2024
Rollup merge of rust-lang#120982 - momvart:smir-61-foreign_kind, r=oli-obk

Add APIs for fetching foreign items

Closes rust-lang/project-stable-mir#61
@momvart momvart closed this as completed Feb 23, 2024
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 a pull request may close this issue.

3 participants