Skip to content

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

Merged
merged 1 commit into from
Feb 3, 2024

Conversation

augusto2112
Copy link
Contributor

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).

@augusto2112
Copy link
Contributor Author

@swift-ci smoke test

@augusto2112
Copy link
Contributor Author

@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();
Copy link
Contributor

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.

Copy link
Contributor Author

@augusto2112 augusto2112 Feb 2, 2024

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

Copy link
Contributor Author

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...

Copy link
Contributor

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.

Copy link
Contributor Author

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

@augusto2112 augusto2112 force-pushed the instance-start-typeref branch from 698625f to ea0f2c4 Compare February 2, 2024 18:58
@augusto2112
Copy link
Contributor Author

@swift-ci smoke test

@augusto2112 augusto2112 force-pushed the instance-start-typeref branch from ea0f2c4 to 98849e9 Compare February 2, 2024 19:10
@augusto2112
Copy link
Contributor Author

@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).
@augusto2112 augusto2112 force-pushed the instance-start-typeref branch from 98849e9 to 18a80f8 Compare February 2, 2024 23:39
@augusto2112
Copy link
Contributor Author

@swift-ci smoke test

@augusto2112 augusto2112 enabled auto-merge February 2, 2024 23:39
@augusto2112 augusto2112 merged commit e2d516f into swiftlang:main Feb 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants