- 
                Notifications
    
You must be signed in to change notification settings  - Fork 10.6k
 
Add a flag to track null termination of Strings #80075
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| 
           @swift-ci please smoke test  | 
    
97f44db    to
    af21302      
    Compare
  
    | 
           @swift-ci please smoke test  | 
    
af21302    to
    a8f85e6      
    Compare
  
    | 
           @swift-ci please smoke test  | 
    
a8f85e6    to
    76d48b9      
    Compare
  
    | 
           @swift-ci please smoke test  | 
    
| 
           @swift-ci please Apple Silicon benchmark  | 
    
| @_alwaysEmitIntoClient | ||
| @inline(__always) // Swift 6.1 | ||
| internal var isKnownNullTerminated: Bool { | ||
| if isSmall { return true } | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this work when the small count is 15? Need to be slightly careful with this if it's dependent on the spill-for-contiguous-access path zeroing that byte, because I don't think we get to use that path when producing a Span/UTF8Span. (@glessard, @milseman?)
(I.e. I think this probably works today, but if I'm right in my suspicion, we'd need to make sure no one tries to use this for a Span fast-path directly)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is mirroring what the existing isFastZeroTerminated accessor does already, but I'm open to discussion if that's the right thing.
I spoke to @glessard about UTF8Span already and he says it doesn't rely on termination anyway, which is… awkward in general, but convenient here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that we have already handled isSmall where this flag is used, I think I would simply not handle it here and make the definition just be _countAndFlags.isNullTerminated to dodge the question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the small count is 15 (or whatever the longest small string is for a particular runtime,) then we are pedantically not null-terminated. I think the point is to know whether we could pass an in-place address and rely on a null being in the right place? In that case I would say if isSmall { return count < _SmallString.capacity }.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good
…-want-to-live-forever' into come-with-me-if-you-want-to-live-forever
| 
           @swift-ci please smoke test  | 
    
| 
           @swift-ci please Apple Silicon benchmark  | 
    
…o for smol strings
| 
           Huh. I feel like this one isn't me?  | 
    
| 
           That is not you.  | 
    
| 
           @swift-ci please smoke test  | 
    
| 
           @swift-ci please Apple Silicon benchmark  | 
    
| 
           @swift-ci please test  | 
    
| 
               | 
          ||
| SWIFT_RUNTIME_STDLIB_API | ||
| const __swift_uint8_t * _Nullable | ||
| _swift_stdlib_NSStringUTF8StringTrampoline(id _Nonnull obj); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My kingdom for a way to force swiftc to generate an objc_msgSend_super call so I don't have to do this ridiculous hoop jumping
| 
           @swift-ci please test  | 
    
| 
           @swift-ci please Apple Silicon benchmark  | 
    
| 
           @swift-ci please test  | 
    
| 
           @swift-ci please Apple Silicon benchmark  | 
    
…rings that can provide a fast UTF8 pointer
| 
           @swift-ci please test  | 
    
| final internal func _utf8String() -> UnsafePointer<UInt8>? { | ||
| if asString._guts._object.isFastZeroTerminated { | ||
| return unsafe start | ||
| return start | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not entirely clear on why this doesn't need an unsafe, but it was warning about it
| 
           @swift-ci please test  | 
    
| 
           @swift-ci please Apple Silicon benchmark  | 
    
| 
           More unrelated failures  | 
    
| 
           Found a problem that I'm not quite sure how to solve: 
 The good news is that  Another alternative would be to only ever make non-terminated allocated shared strings, which would cost a malloc for the shell object on creation, but avoid this issue completely.  | 
    
Fixes rdar://148134880
Not tracking termination has several issues: