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

More information on attributes #104

Open
phansch opened this issue Mar 27, 2018 · 10 comments
Open

More information on attributes #104

phansch opened this issue Mar 27, 2018 · 10 comments
Assignees
Labels
A-AST Area: abstract syntax tree A-attributes Area: attributes A-HIR Area: high-level intermediate representation (HIR) C-enhancement Category: enhancement E-hard Difficulty: might require advanced knowledge T-compiler Relevant to compiler team

Comments

@phansch
Copy link
Member

phansch commented Mar 27, 2018

I recently wrote a clippy lint that deals with attributes (mostly outer attributes) and found very little information on how they are implemented. Most of the information I gathered through PR comments and issues in the rust repo. The reference only explains how to use the different attributes.

Do you think it would make sense to have a chapter on attributes in the guide?

Some weird things and questions I came across:

  • The AST seems to contain attributes that are not in the actual source code (Is this because of macro expansion?) (Warn on empty lines after outer attributes rust-clippy#2340 (comment))
  • some expanded attributes seem to have an empty TokenStream and some not
  • cfg_attr is special somehow
  • In general lots of inconsistencies in the data from the syntax crate?

I would be happy to start something myself, but would need some pointers as to where the attribute stuff happens.

@mark-i-m
Copy link
Member

I think it would be great to add this! I personally have often wondered how attributes work.

Do you happen to know how they interact with custom drive and proc macros?

@petrochenkov
Copy link
Contributor

petrochenkov commented Mar 27, 2018

The implementation history for libsyntax(_ext) looked roughly like "let's urgently patch things up for 1.0" -> "let's urgently implement mostly working macros 1.1" -> "let's attract new contributors to tick some boxes for the proc macros rfc here and there", and soon "let's urgently implement mostly working macros 1.2 and also attributes for tools" all while keeping the old infrastructure for legacy syntax plugins. You can imagine the amount of technical debt.
jseyfried did a lot of work to reduce this chaos, but not enough to fully conquer it.

@mark-i-m
Copy link
Member

Do you think that libsyntax2.0 will replace all of this choas (if it happens)?

@nagisa
Copy link
Member

nagisa commented Mar 28, 2018

There will be discussion about libsyntax 2.0 on friday @ all hands. I pre-ask this question :)

cc @matklad I hear you organise discussion for that?

@matklad
Copy link
Member

matklad commented Mar 29, 2018

@nagisa yep! And this attribute processing actually a nice illustration for he lossy nature of the current libsyntax. However libsyntax 2 is a hypothetical far away future, so it seems to me that the more actionable item here is to try to refactor the current attribute handling?

@mark-i-m mark-i-m added E-help-wanted Call for participation: extra help is wanted and removed E-help-wanted Call for participation: extra help is wanted labels Apr 10, 2018
@mark-i-m
Copy link
Member

@phansch Did you still want to take a stab at this?

@phansch
Copy link
Member Author

phansch commented Apr 10, 2018

@mark-i-m Sorry I'm currently not in the position to dig into this :/

@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 E-hard Difficulty: might require advanced knowledge labels Apr 10, 2018
@jieyouxu
Copy link
Member

jieyouxu commented Nov 4, 2024

Triage: attribute rework is happening in rust-lang/rust#131808 thanks to @jdonszelmann. cc tracking issue rust-lang/rust#131229.

@jieyouxu jieyouxu added A-HIR Area: high-level intermediate representation (HIR) A-attributes Area: attributes A-AST Area: abstract syntax tree T-compiler Relevant to compiler team C-enhancement Category: enhancement E-hard Difficulty: might require advanced knowledge and removed E-medium Difficulty: might require some prior knowledge or code reading E-help-wanted Call for participation: extra help is wanted E-hard Difficulty: might require advanced knowledge A-HIR Area: high-level intermediate representation (HIR) T-compiler Relevant to compiler team A-attributes Area: attributes labels Nov 4, 2024
@jdonszelmann
Copy link
Contributor

hi! that's right, and I'll also write some things down about it. In general, the new rustc_attr crate already contains copious amounts of docs on my own system. Will try to push things soon

@jdonszelmann
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-AST Area: abstract syntax tree A-attributes Area: attributes A-HIR Area: high-level intermediate representation (HIR) C-enhancement Category: enhancement E-hard Difficulty: might require advanced knowledge T-compiler Relevant to compiler team
Projects
None yet
Development

No branches or pull requests

7 participants