-
Notifications
You must be signed in to change notification settings - Fork 13k
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
move rvalue checking to MIR #41232
Merged
Merged
move rvalue checking to MIR #41232
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ use std::fmt; | |
use syntax::ast; | ||
use syntax_pos::{Span, DUMMY_SP}; | ||
|
||
use rustc_data_structures::fx::FxHashSet; | ||
use rustc_data_structures::indexed_vec::Idx; | ||
|
||
fn mirbug(tcx: TyCtxt, span: Span, msg: &str) { | ||
|
@@ -87,6 +88,11 @@ impl<'a, 'b, 'gcx, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'gcx, 'tcx> { | |
self.sanitize_type(rvalue, rval_ty); | ||
} | ||
|
||
fn visit_local_decl(&mut self, local_decl: &LocalDecl<'tcx>) { | ||
self.super_local_decl(local_decl); | ||
self.sanitize_type(local_decl, local_decl.ty); | ||
} | ||
|
||
fn visit_mir(&mut self, mir: &Mir<'tcx>) { | ||
self.sanitize_type(&"return type", mir.return_ty); | ||
for local_decl in &mir.local_decls { | ||
|
@@ -317,6 +323,7 @@ pub struct TypeChecker<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { | |
fulfillment_cx: traits::FulfillmentContext<'tcx>, | ||
last_span: Span, | ||
body_id: ast::NodeId, | ||
reported_errors: FxHashSet<(Ty<'tcx>, Span)>, | ||
} | ||
|
||
impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { | ||
|
@@ -326,6 +333,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { | |
fulfillment_cx: traits::FulfillmentContext::new(), | ||
last_span: DUMMY_SP, | ||
body_id: body_id, | ||
reported_errors: FxHashSet(), | ||
} | ||
} | ||
|
||
|
@@ -641,9 +649,39 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { | |
} | ||
} | ||
|
||
fn typeck_mir(&mut self, mir: &Mir<'tcx>) { | ||
fn check_local(&mut self, mir: &Mir<'gcx>, local: Local, local_decl: &LocalDecl<'gcx>) { | ||
match mir.local_kind(local) { | ||
LocalKind::ReturnPointer | LocalKind::Arg => { | ||
// return values of normal functions are required to be | ||
// sized by typeck, but return values of ADT constructors are | ||
// not because we don't include a `Self: Sized` bounds on them. | ||
// | ||
// Unbound parts of arguments were never required to be Sized | ||
// - maybe we should make that a warning. | ||
return | ||
} | ||
LocalKind::Var | LocalKind::Temp => {} | ||
} | ||
|
||
let span = local_decl.source_info.span; | ||
let ty = local_decl.ty; | ||
if !ty.is_sized(self.tcx().global_tcx(), self.infcx.param_env(), span) { | ||
if let None = self.reported_errors.replace((ty, span)) { | ||
span_err!(self.tcx().sess, span, E0161, | ||
"cannot move a value of type {0}: the size of {0} \ | ||
cannot be statically determined", ty); | ||
} | ||
} | ||
} | ||
|
||
fn typeck_mir(&mut self, mir: &Mir<'gcx>) { | ||
self.last_span = mir.span; | ||
debug!("run_on_mir: {:?}", mir.span); | ||
|
||
for (local, local_decl) in mir.local_decls.iter_enumerated() { | ||
self.check_local(mir, local, local_decl); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait, can't there be assignments between, say, two dereferences? Is there any guarantee there would be a |
||
|
||
for block in mir.basic_blocks() { | ||
for stmt in &block.statements { | ||
if stmt.source_info.span != DUMMY_SP { | ||
|
@@ -698,16 +736,18 @@ impl TypeckMir { | |
impl<'tcx> MirPass<'tcx> for TypeckMir { | ||
fn run_pass<'a>(&mut self, tcx: TyCtxt<'a, 'tcx, 'tcx>, | ||
src: MirSource, mir: &mut Mir<'tcx>) { | ||
debug!("run_pass: {}", tcx.node_path_str(src.item_id())); | ||
let item_id = src.item_id(); | ||
let def_id = tcx.hir.local_def_id(item_id); | ||
debug!("run_pass: {}", tcx.item_path_str(def_id)); | ||
|
||
if tcx.sess.err_count() > 0 { | ||
// compiling a broken program can obviously result in a | ||
// broken MIR, so try not to report duplicate errors. | ||
return; | ||
} | ||
let param_env = ty::ParameterEnvironment::for_item(tcx, src.item_id()); | ||
let param_env = ty::ParameterEnvironment::for_item(tcx, item_id); | ||
tcx.infer_ctxt(param_env, Reveal::UserFacing).enter(|infcx| { | ||
let mut checker = TypeChecker::new(&infcx, src.item_id()); | ||
let mut checker = TypeChecker::new(&infcx, item_id); | ||
{ | ||
let mut verifier = TypeVerifier::new(&mut checker, mir); | ||
verifier.visit_mir(mir); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,5 +47,4 @@ pub mod hir_stats; | |
pub mod loops; | ||
pub mod mir_stats; | ||
pub mod no_asm; | ||
pub mod rvalues; | ||
pub mod static_recursion; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
trait Trait {} | ||
|
||
fn get_function<'a>() -> &'a Fn() -> Trait { panic!("") } | ||
|
||
fn main() { | ||
let t : &Trait = &get_function()(); | ||
//~^ ERROR cannot move a value of type Trait + 'static | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
replace
confuses me -insert
wouldn't work?