-
Notifications
You must be signed in to change notification settings - Fork 159
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
[ #1806 ] Add option_env support #3094
base: master
Are you sure you want to change the base?
Conversation
6262158
to
62a89ef
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
honestly, well done - this isn't an easy part of the codebase, and you did a really good job :) don't worry about the tokenstream stuff, we can think about fixing this later. for the path issue, you're hitting a very frustrating issue which I'm trying to fix in #3068. ideally, we should be able to create paths to lang items (such as Option::Some
and Option::None
) so that we don't care about the module structure, or the name, or anything - we just care about hitting the proper type from the standard library. good work!
enum Option<T> { | ||
Some(T), | ||
None, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...something like this:
enum Option<T> { | |
Some(T), | |
None, | |
} | |
mod core { | |
mod option { | |
enum Option<T> { | |
Some(T), | |
None, | |
} | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed this for the tests. However, to get the compilation to work, I needed an extra
use core::option::Option;
Is that expected behavior? I would assume this is incorrect behavior, maybe a separate issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm... this is weird. you can investigate the generated code by using -frust-dump-all
and looking at the generated gccrs.ast-pretty-expanded.dump
file. it should show exactly the code you've generated with your macro expansion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like the expected behavior, since we don't have a prelude at the moment:
liam@gentoo ~/option_env2 $ rustc main.rs
error[E0412]: cannot find type `Option2` in this scope
--> main.rs:23:13
|
23 | let _ : Option2< &'_ str > = core2::option2::Option2::Some("/home/liam/option2_env2");
| ^^^^^^^
--> /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/option.rs:571:1
|
= note: similarly named enum `Option` defined here
|
help: an enum with a similar name exists
|
23 | let _ : Option< &'_ str > = core2::option2::Option2::Some("/home/liam/option2_env2");
| ~~~~~~
help: consider importing this enum
|
9 + use core2::option2::Option2;
|
error[E0412]: cannot find type `Option2` in this scope
--> main.rs:24:13
|
24 | let _ : Option2< &'_ str > = core2::option2::Option2::None;
| ^^^^^^^
--> /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/option.rs:571:1
|
= note: similarly named enum `Option` defined here
|
help: an enum with a similar name exists
|
24 | let _ : Option< &'_ str > = core2::option2::Option2::None;
| ~~~~~~
help: consider importing this enum
|
9 + use core2::option2::Option2;
|
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0412`.
liam@gentoo ~/option_env2 $ cat main.rs
//#![feature(rustc_attrs)]
//#[rustc_builtin_macro] macro_rules! option2_env {
// () => { };
//}
//#[lang = "sized"]
//trait Sized< > { }
pub mod core2 {
pub mod option2 {
pub enum Option2< T > {
Some(T),
None,
}
}
}
//use core2::option2::Option2;
fn main() {
let _ : Option2< &'_ str > = core2::option2::Option2::Some("/home/liam/option2_env2");
let _ : Option2< &'_ str > = core2::option2::Option2::None;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did mess up the "pub" on the module names in the test though, This is fixed :)
Thank you :) |
8350b2c
to
dd8612c
Compare
36cd2a3
to
2034102
Compare
74ad9b9
to
1f41fa7
Compare
@CohenArthur Should I update this PR to use the lang-item paths from #3068 ? |
1f41fa7
to
3f39ce6
Compare
ca99a70
to
962dc4d
Compare
gcc/rust/ChangeLog: * expand/rust-macro-builtins-utility.cc: Add macro expansion for option_env with eager expansion * expand/rust-macro-builtins.cc: Add option_env to builtin list * expand/rust-macro-builtins.h: Add option_env handler to header file gcc/testsuite/ChangeLog: * rust/compile/macros/builtin/option_env1.rs: Add success case for option_env * rust/compile/macros/builtin/option_env2.rs: Add failure case for option_env * rust/compile/macros/builtin/option_env3.rs: Add second failure case for option_env * rust/execute/torture/builtin_macro_option_env.rs: Add execution case for option_env Signed-off-by: Liam Naddell <liam.naddell@mail.utoronto.ca>
I've been trying to catch up on that issue (sorry for the delay!). We should probably rely on lang item path because right now the tests make use of a |
Ok, I can wait until the lang items path stuff is usable. If appropriate, we can also revisit some of the other macros then as well to integrate lang items. |
Converting to a Draft PR until we have lang items integrated. |
Note to reviewers: I do not really get the token stream stuff, I omitted adding a token stream to AST::Fragment, since I wasn't sure how to test the generated token stream.
Fixes #1806
Addresses #927, #1791
Here is a checklist to help you with your PR.
make check-rust
passes locallyclang-format
gcc/testsuite/rust/
Adds compiler support for option_env, adds eager expansion for option_env, adds tests for option_env