-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Fix nested generic typerefs applying generic params at the wrong level #59262
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
Fix nested generic typerefs applying generic params at the wrong level #59262
Conversation
@swift-ci smoke test |
if (auto parentDescriptor = readParentContextDescriptor(descriptor)) | ||
if (parentDescriptor->isResolved()) | ||
if (auto resolvedParent = parentDescriptor->getResolved()) | ||
parent = readNominalTypeFromDescriptor(metadata, resolvedParent); |
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 sure if this is ok, I'm passing the metadata of the current descriptor, not the parent.
e95c3b3
to
868feb7
Compare
@swift-ci smoke test |
868feb7
to
50a9f04
Compare
@swift-ci smoke test |
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.
One minor request, LGTM.
include/swift/Reflection/TypeRef.h
Outdated
if (Parent) | ||
GenericParams.erase(GenericParams.begin(), | ||
GenericParams.begin() + | ||
GetNumberOfGenericParametersInHierarchy(Parent)); |
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.
Can you add a bounds check here to fail gracefully if GetNumberOfGenericParametersInHierarchy(Parent) > GenericParams.size()
? We sometimes get weird values due to corrupt or misidentified data in the target process.
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.
Nice!
include/swift/Reflection/TypeRef.h
Outdated
@@ -283,6 +283,24 @@ class NominalTypeRef final : public TypeRef, public NominalTypeTrait { | |||
class BoundGenericTypeRef final : public TypeRef, public NominalTypeTrait { | |||
std::vector<const TypeRef *> GenericParams; | |||
|
|||
static uint64_t |
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.
Doxygen comment?
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.
(What's not obvious from the name is that this counts the generic parameters in the parent only.)
50a9f04
to
acae3d2
Compare
@swift-ci smoke test |
/// single flat array. | ||
template <typename T = BuilderType, | ||
std::enable_if_t<std::is_same<T, reflection::TypeRefBuilder>::value, | ||
bool> = 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.
Instead of hardcoding TypeRefBuilder
here, it might be cleaner to look for a new trait on BuilderType
, so we can do enable_if_t<BuilderType::needsToPrecomputeParentGenericContextShapes>
or something like that.
1bbc169
to
07eaa56
Compare
@swift-ci test |
@jckarter updated |
@swift-ci smoke test |
@@ -64,6 +64,8 @@ class ASTBuilder { | |||
using BuiltRequirement = swift::Requirement; | |||
using BuiltSubstitutionMap = swift::SubstitutionMap; | |||
|
|||
static constexpr bool needsToPrecomputeParentGenericContextShapes = false; |
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.
Should we Doxygen-document what this parameter means?
auto node = buildContextMangling(descriptor, dem); | ||
if (!node || node->getKind() != Node::Kind::Type) | ||
return BuiltTypeDecl(); | ||
std::vector<size_t> paramsPerLevel; |
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.
llvm::SmallVector<size_t, 4>
?
return BuiltTypeDecl(); | ||
std::vector<size_t> paramsPerLevel; | ||
size_t runningCount = 0; | ||
std::function<void(ContextDescriptorRef current, size_t &)> countLevels = |
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.
Comment what the lambda does?
@swift-ci smoke test |
Generic params of typerefs are supposed to be "attached" on the level they belong, not as a flat list, unlike other parts of the system. Fix the application of bound generic params by checking how many were already applied in the hierarchy and ignoring those already attached.
07eaa56
to
6a82edd
Compare
@swift-ci smoke test |
Seems like this is failing for some other reason:
|
@swift-ci smoke test |
Generic params of typerefs are supposed to be "attached" on the level
they belong, not as a flat list, unlike other parts of the system. Fix
the application of bound generic params by checking how many were
already applied in the hierarchy and ignoring those already attached.