Skip to content

[Reflection] Hoist computation of error existentials to the reader. #18242

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
Jul 26, 2018

Conversation

dcci
Copy link
Member

@dcci dcci commented Jul 26, 2018

rdar://problem/41546568

Needs to be rebased on top of master once the depending patch goes in.
All the logic is in the second commit: fd0f5f1

@dcci dcci requested review from jckarter and rjmccall July 26, 2018 01:10
@slavapestov
Copy link
Contributor

It's quite possible that it is wrong, because AFAIK, CoreSymbolication never made use of the functionality for projecting existential payloads.

// Round up to alignment, and we have the start address of the
// instance payload.
auto Alignment = VWT->getAlignment();
InstanceAddress += Alignment - InstanceAddress % Alignment;
Copy link
Member Author

Choose a reason for hiding this comment

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

This actually was the computation I was referring to as wrong, but well, the same argument applies.

Copy link
Contributor

@rjmccall rjmccall Jul 26, 2018

Choose a reason for hiding this comment

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

If we had a type for this, we could make the rounding-up operation be a method on it! Just saying. :)

Incidentally, the type we use for this in the runtime is SwiftError in ErrorObject.h, and you can see the offset computation it does in getValue().

@dcci dcci requested a review from slavapestov July 26, 2018 01:28
Copy link
Contributor

@rjmccall rjmccall left a comment

Choose a reason for hiding this comment

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

Functionality looks good except for that alignment computation.

} else {
// Otherwise, we can check to see if this is a class metadata with the
// kind value's least significant bit set, which indicates a pure
// Swift class.
Copy link
Contributor

Choose a reason for hiding this comment

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

Wait, does this happen? And if so, when? Is it just when ObjCInterop is disabled, because I feel like that's something that we ought to be able to check for (and arguably ought to be part of the Runtime template argument).

Copy link
Member Author

Choose a reason for hiding this comment

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

This doesn't seem to ever happen (I tried to put an assertion and the tests still pass). I might consider removing this but I want to try a little harder to see whether I can exercise this.



/// Given a pointer to the metadata, attempt to read the value
/// witness table.
Copy link
Contributor

Choose a reason for hiding this comment

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

You should probably mention here in this comment that it's not safe to access any non-mandatory members of the VWT, like extra inhabitants or enum members.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure.


// Read the value witness table.
auto VWT =
readValueWitnessTable(cast<StoredPointer>(*InstanceMetadataAddress));
Copy link
Contributor

Choose a reason for hiding this comment

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

...I'm confused that cast<> works with StoredPointer as its argument.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm surprised this works too, but given it's unnecessary, I'll remove it anyway.

// and userInfo.
StoredPointer InstanceMetadataAddressAddress =
ExistentialAddress.getAddressData() +
(isObjC ? 5 : 2) * sizeof(StoredPointer);
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. It'd be nice to just have a type for this structure.

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed. Will try to introduce one.

// Round up to alignment, and we have the start address of the
// instance payload.
auto Alignment = VWT->getAlignment();
InstanceAddress += Alignment - InstanceAddress % Alignment;
Copy link
Contributor

@rjmccall rjmccall Jul 26, 2018

Choose a reason for hiding this comment

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

If we had a type for this, we could make the rounding-up operation be a method on it! Just saying. :)

Incidentally, the type we use for this in the runtime is SwiftError in ErrorObject.h, and you can see the offset computation it does in getValue().

TargetOpaqueExistentialContainer<Runtime> Container;
if (!Reader->readBytes(RemoteAddress(ExistentialAddress),
(uint8_t *)&Container, sizeof(Container)))
return llvm::None;
Copy link
Contributor

Choose a reason for hiding this comment

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

Incidentally, is llvm::None really not in scope here? I thought we had a common header imported everywhere that usinged them into namespace swift.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll try removing the full namespace qualification and see if it sticks together.

return llvm::None;

auto AlignmentMask = VWT->getAlignmentMask();
auto Offset = (sizeof(HeapObject) + AlignmentMask) & ~AlignmentMask;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the right computation; you can just extract it out as a utility if you need to. (But it would also make sense to have a TargetBoxedValue struct with some sort of getDataOffsetFromAlignmentMask static method on it.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Going to do that (as well as introducing a type for the Error in a follow-up).

@dcci dcci force-pushed the reflexisterrors branch from fd0f5f1 to 1fa1c0a Compare July 26, 2018 17:22
@dcci
Copy link
Member Author

dcci commented Jul 26, 2018

@swift-ci test and merge

@dcci dcci force-pushed the reflexisterrors branch from 1fa1c0a to 5dc4156 Compare July 26, 2018 17:23
@dcci
Copy link
Member Author

dcci commented Jul 26, 2018

@swift-ci test and merge

2 similar comments
@dcci
Copy link
Member Author

dcci commented Jul 26, 2018

@swift-ci test and merge

@dcci
Copy link
Member Author

dcci commented Jul 26, 2018

@swift-ci test and merge

@swift-ci swift-ci merged commit d36ae32 into swiftlang:master Jul 26, 2018
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.

4 participants