Skip to content

Document common manipulations and operations #91

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

Open
Michael-F-Bryan opened this issue Mar 15, 2018 · 6 comments
Open

Document common manipulations and operations #91

Michael-F-Bryan opened this issue Mar 15, 2018 · 6 comments
Labels
A-contributor-onboarding Area: contributor on-boarding advice (e.g. for new contributors) A-examples Area: examples C-enhancement Category: enhancement E-help-wanted Call for participation: extra help is wanted E-medium Difficulty: might require some prior knowledge or code reading T-compiler Relevant to compiler team

Comments

@Michael-F-Bryan
Copy link
Contributor

Michael-F-Bryan commented Mar 15, 2018

While playing around using rustc internals as a library I found it was pretty difficult to discover how to do a bunch of "common" operations. We might be able to improve discoverability by documenting these in an appendix.

Off the top of my head, it'd be nice to know how to:

  • Get the fully qualified name of a type given its HIR representation and location (e.g. c_char -> libc::c_char or std::os::raw::c_char, depending on context)
  • Get a Path for a given Item
  • Find the DefId of a function or struct declaration
  • How to pretty-print a function declaration

Feel free to add other "common" questions or shortcuts in the comments and I'll update this list accordingly.

CC: #74

@Michael-F-Bryan
Copy link
Contributor Author

I'd be happy to write this up but I'll probably need a little guidance because I only know how to do the second thing (find DefId) at the moment.

@mark-i-m
Copy link
Member

I don't even know enough to know what is a common operation, but something like that would definitely be helpful. Something like a cookbook appendix...

@Michael-F-Bryan
Copy link
Contributor Author

To be honest, I was planning to use it as more of a "post questions here if Michael can't figure out how to do something seemingly simple" kind of thing.

For example, I know we do name resolution before rustc_driver fires the after_analysis callback, yet for the life of me I can't figure out how to get the fully qualified name for all a type. For context, I need to convert something like fn inc(a: c_int) -> c_int into fn inc(a: ::std::os::raw::c_int) -> ::std::os::raw::c_int.

@mark-i-m mark-i-m added E-help-wanted Call for participation: extra help is wanted E-medium Difficulty: might require some prior knowledge or code reading labels Mar 16, 2018
@mark-i-m
Copy link
Member

mark-i-m commented Jun 4, 2018

How to get a string from a Span (e.g. for printing errors)... Use codemap.span_to_snippet(span)

@mark-i-m
Copy link
Member

mark-i-m commented Jun 7, 2020

@mark-i-m
Copy link
Member

mark-i-m commented Jun 7, 2020

How to get an Item from a DefId: https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20do.20I.20get.20an.20Item.20from.20a.20DefId.3F

Also, would be good to talk about def_kind

@jieyouxu jieyouxu added A-contributor-onboarding Area: contributor on-boarding advice (e.g. for new contributors) T-compiler Relevant to compiler team C-enhancement Category: enhancement A-examples Area: examples labels Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-contributor-onboarding Area: contributor on-boarding advice (e.g. for new contributors) A-examples Area: examples C-enhancement Category: enhancement E-help-wanted Call for participation: extra help is wanted E-medium Difficulty: might require some prior knowledge or code reading T-compiler Relevant to compiler team
Projects
None yet
Development

No branches or pull requests

3 participants