@@ -353,9 +353,8 @@ pub struct TargetOptions {
353
353
// will 'just work'.
354
354
pub obj_is_bitcode : bool ,
355
355
356
- /// Maximum integer size in bits that this target can perform atomic
357
- /// operations on.
358
- pub max_atomic_width : u64 ,
356
+ /// Don't use this field; instead use the `.max_atomic_width()` method.
357
+ pub max_atomic_width : Option < u64 > ,
359
358
360
359
/// Panic strategy: "unwind" or "abort"
361
360
pub panic_strategy : PanicStrategy ,
@@ -407,10 +406,7 @@ impl Default for TargetOptions {
407
406
allow_asm : true ,
408
407
has_elf_tls : false ,
409
408
obj_is_bitcode : false ,
410
- // NOTE 0 is *not* the real default value of max_atomic_width. The default value is
411
- // actually the pointer_width of the target. This default is injected in the
412
- // Target::from_json function.
413
- max_atomic_width : 0 ,
409
+ max_atomic_width : None ,
414
410
panic_strategy : PanicStrategy :: Unwind ,
415
411
}
416
412
}
@@ -431,6 +427,12 @@ impl Target {
431
427
}
432
428
}
433
429
430
+ /// Maximum integer size in bits that this target can perform atomic
431
+ /// operations on.
432
+ pub fn max_atomic_width ( & self ) -> u64 {
433
+ self . options . max_atomic_width . unwrap_or ( self . target_pointer_width . parse ( ) . unwrap ( ) )
434
+ }
435
+
434
436
/// Load a target descriptor from a JSON object.
435
437
pub fn from_json ( obj : Json ) -> TargetResult {
436
438
// While ugly, this code must remain this way to retain
@@ -469,9 +471,6 @@ impl Target {
469
471
options : Default :: default ( ) ,
470
472
} ;
471
473
472
- // Default max-atomic-width to target-pointer-width
473
- base. options . max_atomic_width = base. target_pointer_width . parse ( ) . unwrap ( ) ;
474
-
475
474
macro_rules! key {
476
475
( $key_name: ident) => ( {
477
476
let name = ( stringify!( $key_name) ) . replace( "_" , "-" ) ;
@@ -484,11 +483,11 @@ impl Target {
484
483
. map( |o| o. as_boolean( )
485
484
. map( |s| base. options. $key_name = s) ) ;
486
485
} ) ;
487
- ( $key_name: ident, u64 ) => ( {
486
+ ( $key_name: ident, Option < u64 > ) => ( {
488
487
let name = ( stringify!( $key_name) ) . replace( "_" , "-" ) ;
489
488
obj. find( & name[ ..] )
490
489
. map( |o| o. as_u64( )
491
- . map( |s| base. options. $key_name = s ) ) ;
490
+ . map( |s| base. options. $key_name = Some ( s ) ) ) ;
492
491
} ) ;
493
492
( $key_name: ident, PanicStrategy ) => ( {
494
493
let name = ( stringify!( $key_name) ) . replace( "_" , "-" ) ;
@@ -562,7 +561,7 @@ impl Target {
562
561
key ! ( exe_allocation_crate) ;
563
562
key ! ( has_elf_tls, bool ) ;
564
563
key ! ( obj_is_bitcode, bool ) ;
565
- key ! ( max_atomic_width, u64 ) ;
564
+ key ! ( max_atomic_width, Option < u64 > ) ;
566
565
try!( key ! ( panic_strategy, PanicStrategy ) ) ;
567
566
568
567
Ok ( base)
@@ -708,10 +707,6 @@ impl ToJson for Target {
708
707
target_option_val ! ( max_atomic_width) ;
709
708
target_option_val ! ( panic_strategy) ;
710
709
711
- if self . options . max_atomic_width . to_string ( ) != self . target_pointer_width {
712
- d. insert ( "max-atomic-width" . to_string ( ) , self . options . max_atomic_width . to_json ( ) ) ;
713
- }
714
-
715
710
Json :: Object ( d)
716
711
}
717
712
}
0 commit comments