11//! Functionality for statements, operands, places, and things that appear in them.
22
3+ use std:: ops;
4+
35use tracing:: { debug, instrument} ;
46
57use super :: interpret:: GlobalAlloc ;
@@ -15,17 +17,34 @@ use crate::ty::CoroutineArgsExt;
1517pub struct Statement < ' tcx > {
1618 pub source_info : SourceInfo ,
1719 pub kind : StatementKind < ' tcx > ,
20+ /// Some debuginfos appearing before the primary statement.
21+ pub debuginfos : StmtDebugInfos < ' tcx > ,
1822}
1923
2024impl < ' tcx > Statement < ' tcx > {
2125 /// Changes a statement to a nop. This is both faster than deleting instructions and avoids
2226 /// invalidating statement indices in `Location`s.
23- pub fn make_nop ( & mut self ) {
24- self . kind = StatementKind :: Nop
27+ pub fn make_nop ( & mut self , drop_debuginfo : bool ) {
28+ if matches ! ( self . kind, StatementKind :: Nop ) {
29+ return ;
30+ }
31+ let replaced_stmt = std:: mem:: replace ( & mut self . kind , StatementKind :: Nop ) ;
32+ if !drop_debuginfo {
33+ match replaced_stmt {
34+ StatementKind :: Assign ( box ( place, Rvalue :: Ref ( _, _, ref_place) ) )
35+ if let Some ( local) = place. as_local ( ) =>
36+ {
37+ self . debuginfos . push ( StmtDebugInfo :: AssignRef ( local, ref_place) ) ;
38+ }
39+ _ => {
40+ bug ! ( "debuginfo is not yet supported." )
41+ }
42+ }
43+ }
2544 }
2645
2746 pub fn new ( source_info : SourceInfo , kind : StatementKind < ' tcx > ) -> Self {
28- Statement { source_info, kind }
47+ Statement { source_info, kind, debuginfos : StmtDebugInfos :: default ( ) }
2948 }
3049}
3150
@@ -63,6 +82,17 @@ impl<'tcx> StatementKind<'tcx> {
6382 _ => None ,
6483 }
6584 }
85+
86+ pub fn as_debuginfo ( & self ) -> Option < StmtDebugInfo < ' tcx > > {
87+ match self {
88+ StatementKind :: Assign ( box ( place, Rvalue :: Ref ( _, _, ref_place) ) )
89+ if let Some ( local) = place. as_local ( ) =>
90+ {
91+ Some ( StmtDebugInfo :: AssignRef ( local, * ref_place) )
92+ }
93+ _ => None ,
94+ }
95+ }
6696}
6797
6898///////////////////////////////////////////////////////////////////////////
@@ -967,3 +997,70 @@ impl RawPtrKind {
967997 }
968998 }
969999}
1000+
1001+ #[ derive( Default , Debug , Clone , TyEncodable , TyDecodable , HashStable , TypeFoldable , TypeVisitable ) ]
1002+ pub struct StmtDebugInfos < ' tcx > ( Vec < StmtDebugInfo < ' tcx > > ) ;
1003+
1004+ impl < ' tcx > StmtDebugInfos < ' tcx > {
1005+ pub fn push ( & mut self , debuginfo : StmtDebugInfo < ' tcx > ) {
1006+ self . 0 . push ( debuginfo) ;
1007+ }
1008+
1009+ pub fn drop_debuginfo ( & mut self ) {
1010+ self . 0 . clear ( ) ;
1011+ }
1012+
1013+ pub fn is_empty ( & self ) -> bool {
1014+ self . 0 . is_empty ( )
1015+ }
1016+
1017+ pub fn prepend ( & mut self , debuginfos : & mut Self ) {
1018+ if debuginfos. is_empty ( ) {
1019+ return ;
1020+ } ;
1021+ debuginfos. 0 . append ( self ) ;
1022+ std:: mem:: swap ( debuginfos, self ) ;
1023+ }
1024+
1025+ pub fn append ( & mut self , debuginfos : & mut Self ) {
1026+ if debuginfos. is_empty ( ) {
1027+ return ;
1028+ } ;
1029+ self . 0 . append ( debuginfos) ;
1030+ }
1031+
1032+ pub fn extend ( & mut self , debuginfos : & Self ) {
1033+ if debuginfos. is_empty ( ) {
1034+ return ;
1035+ } ;
1036+ self . 0 . extend_from_slice ( debuginfos) ;
1037+ }
1038+
1039+ pub fn retain < F > ( & mut self , f : F )
1040+ where
1041+ F : FnMut ( & StmtDebugInfo < ' tcx > ) -> bool ,
1042+ {
1043+ self . 0 . retain ( f) ;
1044+ }
1045+ }
1046+
1047+ impl < ' tcx > ops:: Deref for StmtDebugInfos < ' tcx > {
1048+ type Target = Vec < StmtDebugInfo < ' tcx > > ;
1049+
1050+ #[ inline]
1051+ fn deref ( & self ) -> & Vec < StmtDebugInfo < ' tcx > > {
1052+ & self . 0
1053+ }
1054+ }
1055+
1056+ impl < ' tcx > ops:: DerefMut for StmtDebugInfos < ' tcx > {
1057+ #[ inline]
1058+ fn deref_mut ( & mut self ) -> & mut Vec < StmtDebugInfo < ' tcx > > {
1059+ & mut self . 0
1060+ }
1061+ }
1062+
1063+ #[ derive( Clone , TyEncodable , TyDecodable , HashStable , TypeFoldable , TypeVisitable ) ]
1064+ pub enum StmtDebugInfo < ' tcx > {
1065+ AssignRef ( Local , Place < ' tcx > ) ,
1066+ }
0 commit comments