@@ -15,12 +15,14 @@ pub mod gdb;
15
15
mod utils;
16
16
mod create;
17
17
mod namespace;
18
+ mod types;
18
19
19
20
use self :: utils:: { debug_context, DIB , span_start, bytes_to_bits, size_and_align_of,
20
21
assert_type_for_node_id, get_namespace_and_span_for_item, fn_should_be_ignored,
21
22
contains_nodebug_attribute, create_scope_map} ;
22
23
use self :: create:: { declare_local, create_DIArray, is_node_local_to_unit} ;
23
- use self :: namespace:: { namespace_for_item, NamespaceTreeNode , crate_root_namespace} ;
24
+ use self :: namespace:: { namespace_for_item, NamespaceTreeNode } ;
25
+ use self :: types:: { compute_debuginfo_type_name, push_debuginfo_type_name} ;
24
26
25
27
use self :: VariableAccess :: * ;
26
28
use self :: VariableKind :: * ;
@@ -2898,215 +2900,3 @@ fn set_debug_location(cx: &CrateContext, debug_location: InternalDebugLocation)
2898
2900
2899
2901
debug_context ( cx) . current_debug_location . set ( debug_location) ;
2900
2902
}
2901
-
2902
- //=-----------------------------------------------------------------------------
2903
- // Type Names for Debug Info
2904
- //=-----------------------------------------------------------------------------
2905
-
2906
- // Compute the name of the type as it should be stored in debuginfo. Does not do
2907
- // any caching, i.e. calling the function twice with the same type will also do
2908
- // the work twice. The `qualified` parameter only affects the first level of the
2909
- // type name, further levels (i.e. type parameters) are always fully qualified.
2910
- fn compute_debuginfo_type_name < ' a , ' tcx > ( cx : & CrateContext < ' a , ' tcx > ,
2911
- t : Ty < ' tcx > ,
2912
- qualified : bool )
2913
- -> String {
2914
- let mut result = String :: with_capacity ( 64 ) ;
2915
- push_debuginfo_type_name ( cx, t, qualified, & mut result) ;
2916
- result
2917
- }
2918
-
2919
- // Pushes the name of the type as it should be stored in debuginfo on the
2920
- // `output` String. See also compute_debuginfo_type_name().
2921
- fn push_debuginfo_type_name < ' a , ' tcx > ( cx : & CrateContext < ' a , ' tcx > ,
2922
- t : Ty < ' tcx > ,
2923
- qualified : bool ,
2924
- output : & mut String ) {
2925
- match t. sty {
2926
- ty:: ty_bool => output. push_str ( "bool" ) ,
2927
- ty:: ty_char => output. push_str ( "char" ) ,
2928
- ty:: ty_str => output. push_str ( "str" ) ,
2929
- ty:: ty_int( ast:: TyIs ) => output. push_str ( "isize" ) ,
2930
- ty:: ty_int( ast:: TyI8 ) => output. push_str ( "i8" ) ,
2931
- ty:: ty_int( ast:: TyI16 ) => output. push_str ( "i16" ) ,
2932
- ty:: ty_int( ast:: TyI32 ) => output. push_str ( "i32" ) ,
2933
- ty:: ty_int( ast:: TyI64 ) => output. push_str ( "i64" ) ,
2934
- ty:: ty_uint( ast:: TyUs ) => output. push_str ( "usize" ) ,
2935
- ty:: ty_uint( ast:: TyU8 ) => output. push_str ( "u8" ) ,
2936
- ty:: ty_uint( ast:: TyU16 ) => output. push_str ( "u16" ) ,
2937
- ty:: ty_uint( ast:: TyU32 ) => output. push_str ( "u32" ) ,
2938
- ty:: ty_uint( ast:: TyU64 ) => output. push_str ( "u64" ) ,
2939
- ty:: ty_float( ast:: TyF32 ) => output. push_str ( "f32" ) ,
2940
- ty:: ty_float( ast:: TyF64 ) => output. push_str ( "f64" ) ,
2941
- ty:: ty_struct( def_id, substs) |
2942
- ty:: ty_enum( def_id, substs) => {
2943
- push_item_name ( cx, def_id, qualified, output) ;
2944
- push_type_params ( cx, substs, output) ;
2945
- } ,
2946
- ty:: ty_tup( ref component_types) => {
2947
- output. push ( '(' ) ;
2948
- for & component_type in component_types {
2949
- push_debuginfo_type_name ( cx, component_type, true , output) ;
2950
- output. push_str ( ", " ) ;
2951
- }
2952
- if !component_types. is_empty ( ) {
2953
- output. pop ( ) ;
2954
- output. pop ( ) ;
2955
- }
2956
- output. push ( ')' ) ;
2957
- } ,
2958
- ty:: ty_uniq( inner_type) => {
2959
- output. push_str ( "Box<" ) ;
2960
- push_debuginfo_type_name ( cx, inner_type, true , output) ;
2961
- output. push ( '>' ) ;
2962
- } ,
2963
- ty:: ty_ptr( ty:: mt { ty : inner_type, mutbl } ) => {
2964
- output. push ( '*' ) ;
2965
- match mutbl {
2966
- ast:: MutImmutable => output. push_str ( "const " ) ,
2967
- ast:: MutMutable => output. push_str ( "mut " ) ,
2968
- }
2969
-
2970
- push_debuginfo_type_name ( cx, inner_type, true , output) ;
2971
- } ,
2972
- ty:: ty_rptr( _, ty:: mt { ty : inner_type, mutbl } ) => {
2973
- output. push ( '&' ) ;
2974
- if mutbl == ast:: MutMutable {
2975
- output. push_str ( "mut " ) ;
2976
- }
2977
-
2978
- push_debuginfo_type_name ( cx, inner_type, true , output) ;
2979
- } ,
2980
- ty:: ty_vec( inner_type, optional_length) => {
2981
- output. push ( '[' ) ;
2982
- push_debuginfo_type_name ( cx, inner_type, true , output) ;
2983
-
2984
- match optional_length {
2985
- Some ( len) => {
2986
- output. push_str ( & format ! ( "; {}" , len) ) ;
2987
- }
2988
- None => { /* nothing to do */ }
2989
- } ;
2990
-
2991
- output. push ( ']' ) ;
2992
- } ,
2993
- ty:: ty_trait( ref trait_data) => {
2994
- let principal = ty:: erase_late_bound_regions ( cx. tcx ( ) , & trait_data. principal ) ;
2995
- push_item_name ( cx, principal. def_id , false , output) ;
2996
- push_type_params ( cx, principal. substs , output) ;
2997
- } ,
2998
- ty:: ty_bare_fn( _, & ty:: BareFnTy { unsafety, abi, ref sig } ) => {
2999
- if unsafety == ast:: Unsafety :: Unsafe {
3000
- output. push_str ( "unsafe " ) ;
3001
- }
3002
-
3003
- if abi != :: syntax:: abi:: Rust {
3004
- output. push_str ( "extern \" " ) ;
3005
- output. push_str ( abi. name ( ) ) ;
3006
- output. push_str ( "\" " ) ;
3007
- }
3008
-
3009
- output. push_str ( "fn(" ) ;
3010
-
3011
- let sig = ty:: erase_late_bound_regions ( cx. tcx ( ) , sig) ;
3012
- if !sig. inputs . is_empty ( ) {
3013
- for & parameter_type in & sig. inputs {
3014
- push_debuginfo_type_name ( cx, parameter_type, true , output) ;
3015
- output. push_str ( ", " ) ;
3016
- }
3017
- output. pop ( ) ;
3018
- output. pop ( ) ;
3019
- }
3020
-
3021
- if sig. variadic {
3022
- if !sig. inputs . is_empty ( ) {
3023
- output. push_str ( ", ..." ) ;
3024
- } else {
3025
- output. push_str ( "..." ) ;
3026
- }
3027
- }
3028
-
3029
- output. push ( ')' ) ;
3030
-
3031
- match sig. output {
3032
- ty:: FnConverging ( result_type) if ty:: type_is_nil ( result_type) => { }
3033
- ty:: FnConverging ( result_type) => {
3034
- output. push_str ( " -> " ) ;
3035
- push_debuginfo_type_name ( cx, result_type, true , output) ;
3036
- }
3037
- ty:: FnDiverging => {
3038
- output. push_str ( " -> !" ) ;
3039
- }
3040
- }
3041
- } ,
3042
- ty:: ty_closure( ..) => {
3043
- output. push_str ( "closure" ) ;
3044
- }
3045
- ty:: ty_err |
3046
- ty:: ty_infer( _) |
3047
- ty:: ty_projection( ..) |
3048
- ty:: ty_param( _) => {
3049
- cx. sess ( ) . bug ( & format ! ( "debuginfo: Trying to create type name for \
3050
- unexpected type: {}", ppaux:: ty_to_string( cx. tcx( ) , t) ) ) ;
3051
- }
3052
- }
3053
-
3054
- fn push_item_name ( cx : & CrateContext ,
3055
- def_id : ast:: DefId ,
3056
- qualified : bool ,
3057
- output : & mut String ) {
3058
- ty:: with_path ( cx. tcx ( ) , def_id, |path| {
3059
- if qualified {
3060
- if def_id. krate == ast:: LOCAL_CRATE {
3061
- output. push_str ( crate_root_namespace ( cx) ) ;
3062
- output. push_str ( "::" ) ;
3063
- }
3064
-
3065
- let mut path_element_count = 0 ;
3066
- for path_element in path {
3067
- let name = token:: get_name ( path_element. name ( ) ) ;
3068
- output. push_str ( & name) ;
3069
- output. push_str ( "::" ) ;
3070
- path_element_count += 1 ;
3071
- }
3072
-
3073
- if path_element_count == 0 {
3074
- cx. sess ( ) . bug ( "debuginfo: Encountered empty item path!" ) ;
3075
- }
3076
-
3077
- output. pop ( ) ;
3078
- output. pop ( ) ;
3079
- } else {
3080
- let name = token:: get_name ( path. last ( )
3081
- . expect ( "debuginfo: Empty item path?" )
3082
- . name ( ) ) ;
3083
- output. push_str ( & name) ;
3084
- }
3085
- } ) ;
3086
- }
3087
-
3088
- // Pushes the type parameters in the given `Substs` to the output string.
3089
- // This ignores region parameters, since they can't reliably be
3090
- // reconstructed for items from non-local crates. For local crates, this
3091
- // would be possible but with inlining and LTO we have to use the least
3092
- // common denominator - otherwise we would run into conflicts.
3093
- fn push_type_params < ' a , ' tcx > ( cx : & CrateContext < ' a , ' tcx > ,
3094
- substs : & subst:: Substs < ' tcx > ,
3095
- output : & mut String ) {
3096
- if substs. types . is_empty ( ) {
3097
- return ;
3098
- }
3099
-
3100
- output. push ( '<' ) ;
3101
-
3102
- for & type_parameter in substs. types . iter ( ) {
3103
- push_debuginfo_type_name ( cx, type_parameter, true , output) ;
3104
- output. push_str ( ", " ) ;
3105
- }
3106
-
3107
- output. pop ( ) ;
3108
- output. pop ( ) ;
3109
-
3110
- output. push ( '>' ) ;
3111
- }
3112
- }
0 commit comments