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

Use hir::Place instead of Symbol in closure_kind_origin #36

Merged
merged 1 commit into from
Jan 17, 2021

Conversation

roxelo
Copy link
Member

@roxelo roxelo commented Dec 3, 2020

Modifies closure_kind_origins such that Place is used instead of Symbol to describe which variable influenced the decision of selecting a specific closure kind (FnMut, FnOnce, Fn)

Remainging work: Figure out why for 4 of the tests, some stderr info are missing.

Closes rust-lang/project-rfc-2229/issues/21


This change is Reviewable

LL | pub trait Debug {
| --------------- required by this bound in `Debug`
LL | type A: Iterator<Item: Debug>;
| ^^^^^ `<<Self as Case1>::A as Iterator>::Item` cannot be formatted using `{:?}` because it doesn't implement `Debug`
Copy link
Member Author

@roxelo roxelo Dec 3, 2020

Choose a reason for hiding this comment

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

Still investigating why some of the information is missing from stderr

compiler/rustc_middle/src/hir/place.rs Outdated Show resolved Hide resolved
compiler/rustc_middle/src/hir/place.rs Outdated Show resolved Hide resolved
compiler/rustc_middle/src/ty/context.rs Outdated Show resolved Hide resolved
compiler/rustc_middle/src/ty/mod.rs Outdated Show resolved Hide resolved
@@ -29,7 +29,7 @@ LL | let c2 = || {
| ^^ this closure implements `FnMut`, not `Fn`
...
LL | drop::<&mut U>(_x2);
| --- closure is `FnMut` because it mutates the variable `_x2` here
| --- closure is `FnMut` because it mutates the variable `*_x2` here
Copy link
Member

Choose a reason for hiding this comment

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

Interesting, I would have not expected this to capture *_x2 :o

compiler/rustc_typeck/src/check/writeback.rs Outdated Show resolved Hide resolved
@arora-aman arora-aman self-assigned this Dec 14, 2020
Copy link
Member

@arora-aman arora-aman left a comment

Choose a reason for hiding this comment

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

One nit

compiler/rustc_typeck/src/check/upvar.rs Show resolved Hide resolved
Copy link
Member

@arora-aman arora-aman left a comment

Choose a reason for hiding this comment

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

Sorry I missed this

compiler/rustc_typeck/src/check/writeback.rs Outdated Show resolved Hide resolved
@roxelo
Copy link
Member Author

roxelo commented Dec 28, 2020

I added more tests and found another bug (it's actually a known bug, so I'll just modify it so it doesn't error out)

---- [ui] ui/closures/2229_closure_analysis/diagnostics/closure-single-variant-diagnostics.rs stdout ----

error: Error: expected failure status (Some(1)) but received status Some(101).
status: exit code: 101
command: "/users/rlmmfruy/rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc" "/users/rlmmfruy/rust/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-single-variant-diagnostics.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zemit-future-incompat-report" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/users/rlmmfruy/rust/build/x86_64-unknown-linux-gnu/test/ui/closures/2229_closure_analysis/diagnostics/closure-single-variant-diagnostics" "-A" "unused" "-Crpath" "-O" "-Cdebuginfo=0" "-Zunstable-options" "-Lnative=/users/rlmmfruy/rust/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/users/rlmmfruy/rust/build/x86_64-unknown-linux-gnu/test/ui/closures/2229_closure_analysis/diagnostics/closure-single-variant-diagnostics/auxiliary"
stdout:
------------------------------------------

------------------------------------------
stderr:
------------------------------------------
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
  --> /users/rlmmfruy/rust/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-single-variant-diagnostics.rs:1:12
   |
LL | #![feature(capture_disjoint_fields)]
   |            ^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(incomplete_features)]` on by default
   = note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information

thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: HirId { owner: DefId(0:8 ~ closure_single_variant_diagnostics[317d]::main), local_id: 9 }', compiler/rustc_mir_build/src/build/expr/as_place.rs:299:69
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::result::unwrap_failed
   3: rustc_mir_build::build::expr::as_place::PlaceBuilder::expect_upvars_resolved
   4: rustc_mir_build::build::expr::as_place::PlaceBuilder::into_place
   5: rustc_mir_build::build::expr::as_place::<impl rustc_mir_build::build::Builder>::as_place
   6: rustc_mir_build::build::matches::<impl rustc_mir_build::build::Builder>::expr_into_pattern
   7: rustc_mir_build::build::scope::<impl rustc_mir_build::build::Builder>::in_opt_scope
   8: rustc_mir_build::build::block::<impl rustc_mir_build::build::Builder>::ast_block_stmts
   9: rustc_mir_build::build::scope::<impl rustc_mir_build::build::Builder>::in_opt_scope
  10: rustc_mir_build::build::expr::into::<impl rustc_mir_build::build::Builder>::into_expr
  11: <rustc_mir_build::thir::ExprRef as rustc_mir_build::build::into::EvalInto>::eval_into
  12: rustc_mir_build::build::scope::<impl rustc_mir_build::build::Builder>::in_scope
  13: rustc_data_structures::stack::ensure_sufficient_stack
  14: rustc_mir_build::build::expr::into::<impl rustc_mir_build::build::Builder>::into_expr
  15: <rustc_mir_build::thir::ExprRef as rustc_mir_build::build::into::EvalInto>::eval_into
  16: rustc_mir_build::build::scope::<impl rustc_mir_build::build::Builder>::in_scope
  17: rustc_data_structures::stack::ensure_sufficient_stack
  18: rustc_mir_build::build::expr::into::<impl rustc_mir_build::build::Builder>::into_expr
  19: <rustc_mir_build::thir::Expr as rustc_mir_build::build::into::EvalInto>::eval_into
  20: rustc_mir_build::build::Builder::args_and_body
  21: rustc_mir_build::build::construct_fn
  22: rustc_infer::infer::InferCtxtBuilder::enter
  23: rustc_mir_build::build::mir_built
  24: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::mir_built>::compute
  25: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  26: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  27: rustc_data_structures::stack::ensure_sufficient_stack
  28: rustc_query_system::query::plumbing::get_query_impl
  29: rustc_mir::transform::check_unsafety::unsafety_check_result
  30: core::ops::function::FnOnce::call_once
  31: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::unsafety_check_result>::compute
  32: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  33: rustc_data_structures::stack::ensure_sufficient_stack
  34: rustc_query_system::query::plumbing::get_query_impl
  35: <rustc_mir::transform::check_unsafety::UnsafetyChecker as rustc_middle::mir::visit::Visitor>::visit_rvalue
  36: <rustc_mir::transform::check_unsafety::UnsafetyChecker as rustc_middle::mir::visit::Visitor>::visit_statement
  37: rustc_middle::mir::visit::Visitor::visit_body
  38: rustc_mir::transform::check_unsafety::unsafety_check_result
  39: core::ops::function::FnOnce::call_once
  40: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::unsafety_check_result>::compute
  41: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  42: rustc_data_structures::stack::ensure_sufficient_stack
  43: rustc_query_system::query::plumbing::get_query_impl
  44: rustc_query_system::query::plumbing::ensure_query_impl
  45: rustc_mir::transform::mir_const
  46: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::mir_const>::compute
  47: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  48: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  49: rustc_data_structures::stack::ensure_sufficient_stack
  50: rustc_query_system::query::plumbing::get_query_impl
  51: rustc_mir::transform::mir_promoted
  52: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::mir_promoted>::compute
  53: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  54: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  55: rustc_data_structures::stack::ensure_sufficient_stack
  56: rustc_query_system::query::plumbing::get_query_impl
  57: rustc_mir::borrow_check::mir_borrowck
  58: core::ops::function::FnOnce::call_once
  59: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::mir_borrowck>::compute
  60: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  61: rustc_data_structures::stack::ensure_sufficient_stack
  62: rustc_query_system::query::plumbing::get_query_impl
  63: rustc_query_system::query::plumbing::ensure_query_impl
  64: rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::par_body_owners
  65: rustc_session::utils::<impl rustc_session::session::Session>::time
  66: rustc_interface::passes::analysis
  67: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  68: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  69: rustc_query_system::dep_graph::graph::DepGraph<K>::with_eval_always_task
  70: rustc_data_structures::stack::ensure_sufficient_stack
  71: rustc_query_system::query::plumbing::get_query_impl
  72: rustc_interface::passes::QueryContext::enter
  73: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  74: rustc_span::with_source_map
  75: rustc_interface::interface::create_compiler_and_run
  76: scoped_tls::ScopedKey<T>::set
  77: rustc_span::with_session_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.51.0-dev running on x86_64-unknown-linux-gnu

note: compiler flags: -Z threads=1 -Z ui-testing -Z deduplicate-diagnostics=no -Z emit-future-incompat-report -Z unstable-options -C prefer-dynamic -C rpath -C debuginfo=0

query stack during panic:
#0 [mir_built] building MIR for `main::{closure#0}`
#1 [unsafety_check_result] unsafety-checking `main::{closure#0}`
#2 [unsafety_check_result] unsafety-checking `main`
#3 [mir_const] processing MIR for `main`
#4 [mir_promoted] processing `main`
#5 [mir_borrowck] borrow-checking `main`
#6 [analysis] running analysis passes on this crate
end of query stack
warning: 1 warning emitted

Will investigate tomorrow

Copy link
Member

@arora-aman arora-aman left a comment

Choose a reason for hiding this comment

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

Can you move the tests to
test/ui/closures/2229_closure_analysis/diagnostics/

And add origin to the naming scheme like closure-origin-<>

compiler/rustc_middle/src/ty/mod.rs Outdated Show resolved Hide resolved
compiler/rustc_middle/src/ty/mod.rs Outdated Show resolved Hide resolved
compiler/rustc_middle/src/ty/mod.rs Outdated Show resolved Hide resolved
compiler/rustc_middle/src/ty/mod.rs Outdated Show resolved Hide resolved
compiler/rustc_typeck/src/check/upvar.rs Show resolved Hide resolved
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
//~| `#[warn(incomplete_features)]` on by default
//~| see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
struct S(String);
Copy link
Member

Choose a reason for hiding this comment

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

can you change this have multiple elements, non copy elements?

fn main() {
let s = S(format!("s"));
let c = || { //~ ERROR expected a closure
let s = s.0;
Copy link
Member

Choose a reason for hiding this comment

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

Then use s.1

Copy link
Member Author

Choose a reason for hiding this comment

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

I have tried it, but it doesn't seem like a valid thing to do

compiler/rustc_middle/src/ty/mod.rs Outdated Show resolved Hide resolved
arora-aman
arora-aman previously approved these changes Dec 29, 2020
compiler/rustc_middle/src/ty/mod.rs Outdated Show resolved Hide resolved
@arora-aman arora-aman dismissed their stale review December 29, 2020 08:56

Didn't mean to approve yet

compiler/rustc_middle/src/ty/mod.rs Outdated Show resolved Hide resolved
compiler/rustc_middle/src/ty/mod.rs Outdated Show resolved Hide resolved

fn main() {
let s = S(format!("s"));
let c = || { //~ ERROR expected a closure
Copy link
Member

Choose a reason for hiding this comment

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

can u turn the error into expected closure that implements Fn

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

ohh, I see what you want now

@roxelo roxelo force-pushed the use-place-instead-of-symbol branch from 784681e to d73cf5f Compare January 2, 2021 19:33
Copy link
Member

@arora-aman arora-aman left a comment

Choose a reason for hiding this comment

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

one nit. LGTM otherwise

compiler/rustc_middle/src/ty/mod.rs Outdated Show resolved Hide resolved
@roxelo roxelo force-pushed the use-place-instead-of-symbol branch from d73cf5f to b498870 Compare January 2, 2021 22:50
@sexxi-bot sexxi-bot merged commit 19f9780 into master Jan 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update TypeckResuts::closure_kind_origin to use Place
3 participants