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

Builtin macros #927

Open
12 of 61 tasks
CohenArthur opened this issue Feb 15, 2022 · 8 comments
Open
12 of 61 tasks

Builtin macros #927

CohenArthur opened this issue Feb 15, 2022 · 8 comments

Comments

@CohenArthur
Copy link
Member

CohenArthur commented Feb 15, 2022

Bang macros

Attribute macros

  • bench
  • cfg_accessible
  • cfg_eval
  • derive
  • global_allocator
  • test
  • test_case

Derive macros

Directly taken from https://github.com/rust-lang/rust/blob/a240ccd81c74c105b6f5fe84c46f8d36edb7e306/compiler/rustc_builtin_macros/src/lib.rs#L52-L119

Thanks a lot to @bjorn3 for the corrections

Builtin macros which are declared and/or used in libcore 1.49:

  • format_args
  • format_args_nl
  • RustcDecodable
  • RustcEncodable
  • cfg_accessible
  • global_allocator
  • test
  • test_case
  • bench
  • option_env
  • concat_idents
  • module_path
  • asm
  • llvm_asm
  • global_asm
  • log_syntax
  • trace_macros
@bjorn3
Copy link

bjorn3 commented Feb 15, 2022

Deprecated Derive macros

There seems to be a push to destabilize them in rustc. Skipping them in gccrs should be fine I think.

cmdline_attrs

This is not a macro, but the module implementing -Zcrate-attr.

deriving

This is the module containing all builtin #[derive] macros.

proc_macro_harness

This module is for the proc macro implementation.

source_util

Haven't checked, but also likely not a macro.

There are a couple other items on the list that I don't think are actual macros.

@CohenArthur
Copy link
Member Author

@bjorn3 this was mostly created by looking here and by grepping for compiler built-in in the rust repo. I do think it needs some adjustments, so thanks a lot! I'll double check it

bors bot added a commit that referenced this issue Mar 23, 2022
1043: implement include_bytes! and include_str! macros r=CohenArthur a=dafaust

Implement the include_bytes! and include_str! builtin macros.

Addresses:  #927 

Co-authored-by: David Faust <[email protected]>
bors bot added a commit that referenced this issue Mar 24, 2022
1043: implement include_bytes! and include_str! macros r=CohenArthur a=dafaust

Implement the include_bytes! and include_str! builtin macros.

Addresses:  #927 

1064: Handle :tt fragments properly r=CohenArthur a=CohenArthur

:tt fragments stand for token trees, and are composed of either a token,
or a delimited token tree, which is a token tree surrounded by
delimiters (parentheses, curly brackets or square brackets).

This should allow us to handle a lot more macros, including extremely
powerful macro patterns such as TT munchers


Co-authored-by: David Faust <[email protected]>
Co-authored-by: Arthur Cohen <[email protected]>
liushuyu added a commit to liushuyu/gccrs that referenced this issue Apr 3, 2022
liushuyu added a commit to liushuyu/gccrs that referenced this issue Apr 3, 2022
@liushuyu
Copy link
Contributor

liushuyu commented Aug 4, 2022

This table probably needs an update.

Since the last update of this issue, the following macros have been implemented:

  • compiler_error
  • include
  • line
  • cfg (partially?)

Most remainders require the format_args! macro to be implemented (print! and println! family of macros also depend on this).

@CohenArthur
Copy link
Member Author

Yeah, format_args is a big blocker at the moment for a lot of macros including std ones. I wonder how hard it would be to implement it in our current state. The format of format strings (:D) is definitely hard to implement, but ideally it should be relatively easy to add calls into the Display, Debug, Pointer... etc traits to the fmt method. This will definitely be an interesting and complex project on its own :) I hope we can do it gradually and extend it as time goes

@liushuyu
Copy link
Contributor

liushuyu commented Aug 8, 2022

Yeah, format_args is a big blocker at the moment for a lot of macros including std ones.

It also prevents most of the "real world projects" (I would guess >95%) from compiling if it is unimplemented.

I wonder how hard it would be to implement it in our current state.

I would consider the difficulty extremely hard at the moment. format_args! by itself is a 3k+ lines monstrosity in rustc, not including all the other machinery that needs to be added to accommodate its addition.

Also, another potentially problematic macro would be asm! since that would require a change to the current AST structures (a new kind of node needs to be added), and the consequence of that will be most of the existing visitors need to adapt to this change. I am not sure if there exists a way to pass the assembly fragment w/o adding a new kind of ASTNode type.

@CohenArthur
Copy link
Member Author

I think asm is a very difficult one indeed. It's a whole other syntax than what gcc currently supports too, but I think we'll eventually be able to translate one to the other. And yeah, format_args is quite big haha, but it is tremendously important as you point out, even for other builtin macros (unreachable, panic...)

@CohenArthur
Copy link
Member Author

Edited to reflect which macros we really need to focus on for libcore 1.49

@liamnaddell
Copy link
Contributor

@CohenArthur option_env is done :))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Status: Todo
Development

No branches or pull requests

4 participants