-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Implement ReflectionContext::readInstanceStartFromTypeRef #71328
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
Conversation
@swift-ci smoke test |
21ec1cd
to
698625f
Compare
@swift-ci smoke test |
return llvm::None; | ||
|
||
// The start of the subclass's fields is right after the super class's ones. | ||
size_t start = superTI->getSize(); |
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 might need to account for padding. For example:
class Sup {
var n: Int8
}
class Sub {
var s: String
}
This might give you 17 (on 64-bit) but Sub's field starts at 24. Or for a more painful case:
class Sup {
var n: Int
}
class Sub {
var m: SIMD4<Double>
}
This will give you 24 but m is 16-byte aligned and starts at 32.
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.
Hmm, I tested out your examples and you're right Mike, but it looks like the where I'm using this expects the size of the superclass (except if there's no superclass, then it expects the start of the fields offset), and accounts for padding correctly, so I'll update the function name and comment to reflect this better.
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!
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.
I ended up with readSizeOfFieldsNotBelongingToInstanceFromTypeRef
although I'm not in love with the name. It's kind of hard to describe "the size of the superclass if there is one or the start of this instance's fields if there isn't" in a concise function name...
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.
The name is tough here. How about readUnalignedFieldStartOffsetFromTypeRef
? The "unaligned" tells the caller that it's not necessarily correct, depending on the alignment of the first field.
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.
Yeah I think that's better
698625f
to
ea0f2c4
Compare
@swift-ci smoke test |
ea0f2c4
to
98849e9
Compare
@swift-ci smoke test |
Implement computeUnalignedFieldStartOffset as an alternative way to finding out the start of the fields that belong to the instance when reading the field's start from binary is not possible (for example, embedded Swift doesn't emit any reflection metadata on the binary).
98849e9
to
18a80f8
Compare
@swift-ci smoke test |
Implement ReflectionContext::readInstanceStartFromTypeRef as an alternative way to finding out the start of an instance's field when reading the field's start from binary is not possible (for example, embedded Swift doesn't emit any reflection metadata on the binary).