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

Define queries using a proc macro #56462

Merged
merged 4 commits into from
Mar 19, 2019
Merged

Define queries using a proc macro #56462

merged 4 commits into from
Mar 19, 2019

Conversation

Zoxc
Copy link
Contributor

@Zoxc Zoxc commented Dec 3, 2018

cc @rust-lang/compiler

@rust-highfive
Copy link
Collaborator

r? @zackmdavis

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 3, 2018
@rust-highfive

This comment has been minimized.


rustc_query_append! { [define_queries!][ <'tcx>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mind-bending, but cool!

@rust-highfive

This comment has been minimized.

@Zoxc Zoxc force-pushed the query-macro branch 2 times, most recently from 92fcbc5 to 20b9c1b Compare December 3, 2018 17:16
src/librustc/query/mod.rs Outdated Show resolved Hide resolved
@rust-highfive

This comment has been minimized.

@mark-i-m
Copy link
Member

mark-i-m commented Dec 3, 2018

@Zoxc This is cool :)

When it merges, could you please update https://rust-lang.github.io/rustc-guide/query.html ? That would be much appreciated!

@rust-highfive

This comment has been minimized.

@petrochenkov
Copy link
Contributor

Perhaps I didn't work with queries enough, but I don't understand what's the point of the change and why is this an improvement.

@eddyb
Copy link
Member

eddyb commented Dec 4, 2018

@petrochenkov This is pretty much just replacing a macro_rules macro (define_queries!) with a proc macro that has nicer (and simpler) input syntax.

The PR is more confusing atm though, because it kept both macros and daisy-chained them, to allow gradually moving from the old one to the new one.

@Zoxc
Copy link
Contributor Author

Zoxc commented Dec 7, 2018

I forgot to include syntax for QueryDescription:

impl<'tcx> QueryDescription<'tcx> for queries::type_op_prove_predicate<'tcx> {
    fn describe(_tcx: TyCtxt<'_, '_, '_>, goal: CanonicalTypeOpProvePredicateGoal<'tcx>)
                -> Cow<'static, str> {
        format!("evaluating `type_op_prove_predicate` `{:?}`", goal).into()
    }
}

Anyone have some good ideas for that?

@eddyb
Copy link
Member

eddyb commented Dec 7, 2018

I'd say something like this:

description("evaluating `type_op_prove_predicate` `{:?}`", goal)

@Zoxc
Copy link
Contributor Author

Zoxc commented Dec 7, 2018

@eddyb That looks very unbound.

How about:

query type_of(DefId) -> Ty<'tcx> {
 	"evaluating `finding type of `{:?}`", $key
}

@mark-i-m
Copy link
Member

mark-i-m commented Dec 7, 2018

Why not use a doc comment?

@eddyb
Copy link
Member

eddyb commented Dec 7, 2018

@mark-i-m Literally this?

/// "finding type of `{:?}`", $key`

Or something neater? Maybe like this:

/// finding type of `{key:?}`

@rust-highfive

This comment has been minimized.

@rust-highfive
Copy link
Collaborator

The job mingw-check of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:05b801f8:start=1544224442596761929,finish=1544224512640402127,duration=70043640198
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#Pull-Requests-and-Security-Restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=mingw-check
---
[00:07:26] configure: build.locked-deps    := True
[00:07:26] configure: llvm.ccache          := sccache
[00:07:26] configure: build.cargo-native-static := True
[00:07:26] configure: dist.missing-tools   := True
[00:07:26] configure: build.configure-args := ['--enable-sccache', '--disable-manage-submodu ...
[00:07:26] configure: writing `config.toml` in current directory
[00:07:26] configure: 
[00:07:26] configure: run `python /checkout/x.py --help`
[00:07:26] configure: 
---
[00:12:27]     Checking rustc-demangle v0.1.9
[00:12:27]     Checking num_cpus v1.8.0
[00:12:31]     Checking memmap v0.6.2
[00:12:31]    Compiling rustc_llvm v0.0.0 (/checkout/src/librustc_llvm)
[00:12:33] error[E0463]: can't find crate for `rustc_macros` which `rustc` depends on
[00:12:33]    |
[00:12:33] 45 | #[macro_use] extern crate rustc;
[00:12:33]    |              ^^^^^^^^^^^^^^^^^^^ can't find crate
[00:12:33] 
[00:12:33] 
[00:12:33] error: aborting due to previous error
[00:12:33] 
[00:12:33] For more information about this error, try `rustc --explain E0463`.
[00:12:33] error: Could not compile `rustc_codegen_llvm`.
[00:12:33] 
[00:12:33] To learn more, run the command again with --verbose.
[00:12:33] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "check" "--target" "i686-pc-windows-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--manifest-path" "/checkout/src/librustc_codegen_llvm/Cargo.toml" "--message-format" "json"
[00:12:33] travis_fold:start:stage0-rustc_codegen_llvm
travis_time:start:stage0-rustc_codegen_llvm
failed to run: /checkout/obj/build/bootstrap/debug/bootstrap check --target=i686-pc-windows-gnu --host=i686-pc-windows-gnu
[00:12:33] Build completed unsuccessfully in 0:03:56
---
travis_time:end:100940bc:start=1544225275217129397,finish=1544225275222627296,duration=5497899
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:04205a02
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:04627458
travis_time:start:04627458
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:099010d8
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@Zoxc
Copy link
Contributor Author

Zoxc commented Dec 8, 2018

I don't think using comments is a good idea. You'd want to use those to document the queries. Also it's very surprising that comments are executable.

@rust-highfive
Copy link
Collaborator

The job mingw-check of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:00c700f5:start=1544278669563959679,finish=1544278723777822350,duration=54213862671
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#Pull-Requests-and-Security-Restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=mingw-check
---
[00:07:32] configure: build.locked-deps    := True
[00:07:32] configure: llvm.ccache          := sccache
[00:07:32] configure: build.cargo-native-static := True
[00:07:32] configure: dist.missing-tools   := True
[00:07:32] configure: build.configure-args := ['--enable-sccache', '--disable-manage-submodu ...
[00:07:32] configure: writing `config.toml` in current directory
[00:07:32] configure: 
[00:07:32] configure: run `python /checkout/x.py --help`
[00:07:32] configure: 
---
[00:12:39]     Checking rustc_save_analysis v0.0.0 (/checkout/src/librustc_save_analysis)
[00:12:39]     Checking rustc_codegen_ssa v0.0.0 (/checkout/src/librustc_codegen_ssa)
[00:12:44]     Checking rustc-main v0.0.0 (/checkout/src/rustc)
[00:12:45]     Finished release [optimized] target(s) in 3m 21s
[00:12:45] thread 'main' panicked at 'failed to copy `/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/release/deps/librustc_macros-9f012a3c4a8560db.so` to `/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_macros-9f012a3c4a8560db.so`: No such file or directory (os error 2)', src/bootstrap/lib.rs:1180:17
[00:12:45] travis_fold:end:stage0-rustc

[00:12:45] travis_time:end:stage0-rustc:start=1544279296114616927,finish=1544279497326681879,duration=201212064952

---
travis_time:end:09b0810d:start=1544279498047769029,finish=1544279498053695603,duration=5926574
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:0bee4ee4
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:0914b014
travis_time:start:0914b014
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:1a96e650
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a nit and a potential refactoring

r=me with both addressed

src/librustc_macros/src/query.rs Outdated Show resolved Hide resolved
src/librustc_macros/src/query.rs Outdated Show resolved Hide resolved
src/librustc_macros/src/query.rs Show resolved Hide resolved
src/librustc_macros/src/query.rs Outdated Show resolved Hide resolved
@oli-obk
Copy link
Contributor

oli-obk commented Mar 18, 2019

@bors r+

@bors
Copy link
Contributor

bors commented Mar 18, 2019

📌 Commit 198dfce has been approved by oli-obk

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 18, 2019
@bors
Copy link
Contributor

bors commented Mar 18, 2019

⌛ Testing commit 198dfce with merge 3a05002e245eb2c9fe06c1ab62ef48e0c7f0f69c...

@bors
Copy link
Contributor

bors commented Mar 18, 2019

💥 Test timed out

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 18, 2019
@Zoxc
Copy link
Contributor Author

Zoxc commented Mar 18, 2019

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 18, 2019
@bors
Copy link
Contributor

bors commented Mar 18, 2019

⌛ Testing commit 198dfce with merge 3bf064b...

bors added a commit that referenced this pull request Mar 18, 2019
@bors
Copy link
Contributor

bors commented Mar 19, 2019

☀️ Test successful - checks-travis, status-appveyor
Approved by: oli-obk
Pushing 3bf064b to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 19, 2019
@bors bors merged commit 198dfce into rust-lang:master Mar 19, 2019
@Zoxc Zoxc deleted the query-macro branch March 19, 2019 07:11
rasendubi added a commit to rasendubi/rustc-guide that referenced this pull request Apr 15, 2019
There was a big macro rewrite in these pull requests:
rust-lang/rust#56462
rust-lang/rust#59517

Update the query chapter to describe the new macro usage.
mark-i-m pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Apr 16, 2019
There was a big macro rewrite in these pull requests:
rust-lang/rust#56462
rust-lang/rust#59517

Update the query chapter to describe the new macro usage.
mark-i-m pushed a commit to spastorino/rustc-dev-guide that referenced this pull request Jan 2, 2020
There was a big macro rewrite in these pull requests:
rust-lang/rust#56462
rust-lang/rust#59517

Update the query chapter to describe the new macro usage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet