@@ -12,14 +12,13 @@ use super::stubs::{HashMapStub, VecStub};
1212use crate :: utils:: { instance_name_is, instance_name_starts_with} ;
1313use crate :: GotocCtx ;
1414use cbmc:: goto_program:: { BuiltinFn , Expr , Location , Stmt , Symbol , Type } ;
15- use rustc_hir:: definitions:: DefPathDataName ;
1615use rustc_middle:: mir:: { BasicBlock , Place } ;
1716use rustc_middle:: ty:: layout:: LayoutOf ;
1817use rustc_middle:: ty:: print:: with_no_trimmed_paths;
1918use rustc_middle:: ty:: { self , Instance , InstanceDef , Ty , TyCtxt } ;
2019use rustc_span:: Span ;
2120use std:: rc:: Rc ;
22- use tracing:: debug;
21+ use tracing:: { debug, warn } ;
2322
2423pub trait GotocTypeHook < ' tcx > {
2524 fn hook_applies ( & self , tcx : TyCtxt < ' tcx > , ty : Ty < ' tcx > ) -> bool ;
@@ -66,19 +65,29 @@ fn output_of_instance_is_never<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>
6665 }
6766}
6867
68+ fn matches_function ( tcx : TyCtxt < ' tcx > , instance : Instance < ' tcx > , attr_name : & str ) -> bool {
69+ let attr_sym = rustc_span:: symbol:: Symbol :: intern ( attr_name) ;
70+ if let Some ( attr_id) = tcx. all_diagnostic_items ( ( ) ) . name_to_id . get ( & attr_sym) {
71+ if instance. def . def_id ( ) == * attr_id {
72+ debug ! ( "matched: {:?} {:?}" , attr_id, attr_sym) ;
73+ return true ;
74+ }
75+ }
76+ false
77+ }
78+
6979struct ExpectFail ;
7080impl < ' tcx > GotocHook < ' tcx > for ExpectFail {
7181 fn hook_applies ( & self , tcx : TyCtxt < ' tcx > , instance : Instance < ' tcx > ) -> bool {
72- let def_path = tcx. def_path ( instance. def . def_id ( ) ) ;
73- if let Some ( data) = def_path. data . last ( ) {
74- match data. data . name ( ) {
75- DefPathDataName :: Named ( name) => {
76- return name. to_string ( ) . starts_with ( "__VERIFIER_expect_fail" ) ;
77- }
78- DefPathDataName :: Anon { .. } => ( ) ,
79- }
82+ // Deprecate old __VERIFIER notation that doesn't respect rust naming conventions.
83+ // Complete removal is tracked here: https://github.com/model-checking/rmc/issues/599
84+ if instance_name_starts_with ( tcx, instance, "__VERIFIER_expect_fail" ) {
85+ warn ! (
86+ "The function __VERIFIER_expect_fail is deprecated. Use rmc::expect_fail instead"
87+ ) ;
88+ return true ;
8089 }
81- false
90+ matches_function ( tcx , instance , "RmcExpectFail" )
8291 }
8392
8493 fn handle (
@@ -109,16 +118,13 @@ impl<'tcx> GotocHook<'tcx> for ExpectFail {
109118struct Assume ;
110119impl < ' tcx > GotocHook < ' tcx > for Assume {
111120 fn hook_applies ( & self , tcx : TyCtxt < ' tcx > , instance : Instance < ' tcx > ) -> bool {
112- let def_path = tcx. def_path ( instance. def . def_id ( ) ) ;
113- if let Some ( data) = def_path. data . last ( ) {
114- match data. data . name ( ) {
115- DefPathDataName :: Named ( name) => {
116- return name. to_string ( ) . starts_with ( "__VERIFIER_assume" ) ;
117- }
118- DefPathDataName :: Anon { .. } => ( ) ,
119- }
121+ // Deprecate old __VERIFIER notation that doesn't respect rust naming conventions.
122+ // Complete removal is tracked here: https://github.com/model-checking/rmc/issues/599
123+ if instance_name_starts_with ( tcx, instance, "__VERIFIER_assume" ) {
124+ warn ! ( "The function __VERIFIER_assume is deprecated. Use rmc::assume instead" ) ;
125+ return true ;
120126 }
121- false
127+ matches_function ( tcx , instance , "RmcAssume" )
122128 }
123129
124130 fn handle (
@@ -149,7 +155,13 @@ struct Nondet;
149155
150156impl < ' tcx > GotocHook < ' tcx > for Nondet {
151157 fn hook_applies ( & self , tcx : TyCtxt < ' tcx > , instance : Instance < ' tcx > ) -> bool {
152- instance_name_starts_with ( tcx, instance, "__nondet" )
158+ // Deprecate old __nondet since it doesn't match rust naming conventions.
159+ // Complete removal is tracked here: https://github.com/model-checking/rmc/issues/599
160+ if instance_name_starts_with ( tcx, instance, "__nondet" ) {
161+ warn ! ( "The function __nondet is deprecated. Use rmc::nondet instead" ) ;
162+ return true ;
163+ }
164+ matches_function ( tcx, instance, "RmcNonDet" )
153165 }
154166
155167 fn handle (
0 commit comments