mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
conversions that reverse an implicit conversion done to align foreign declarations with their imported types. For example, consider an Objective-C method that returns an NSString*: - (nonnull NSString*) foo; This will be imported into Swift as a method returning a String: func foo() -> String A call to this method will implicitly convert the result to String behind the scenes. If the user then casts the result back to NSString*, that would normally be compiled as an additional conversion. The compiler cannot simply eliminate the conversion because that is not necessarily semantically equivalent. This peephole recognizes as-casts that immediately reverse a bridging conversion as a special case and gives them special power to eliminate both conversions. For example, 'foo() as NSString' will simply return the original return value. In addition to call results, this also applies to call arguments, property accesses, and subscript accesses.
18 lines
621 B
Objective-C
18 lines
621 B
Objective-C
#include "Foundation.h"
|
|
|
|
@interface NullableSubscript : NSObject
|
|
- (nullable NSString*) objectForKeyedSubscript: (nonnull id) key;
|
|
- (void) setObject: (nullable NSString*) obj forKeyedSubscript: (nonnull id) key;
|
|
@end
|
|
|
|
@interface NullproneSubscript : NSObject
|
|
- (null_unspecified NSString*) objectForKeyedSubscript: (nonnull id) key;
|
|
- (void) setObject: (null_unspecified NSString*) obj forKeyedSubscript: (nonnull id) key;
|
|
@end
|
|
|
|
@interface NonnullSubscript : NSObject
|
|
- (nonnull NSString*) objectForKeyedSubscript: (nonnull id) key;
|
|
- (void) setObject: (nonnull NSString*) obj forKeyedSubscript: (nonnull id) key;
|
|
@end
|
|
|