-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AST] Reinstate "Fix excessive deserialization in GenericSignatureBuilder" #7530
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
[AST] Reinstate "Fix excessive deserialization in GenericSignatureBuilder" #7530
Conversation
@swift-ci please smoke test and merge |
include/swift/AST/Decl.h
Outdated
@@ -2854,8 +2854,9 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext { | |||
/// | |||
/// \param ignoreNewExtensions Whether to avoid loading any new extension. | |||
/// Used by the module loader to break recursion. | |||
ArrayRef<ValueDecl *> lookupDirect(DeclName name, | |||
bool ignoreNewExtensions = false); | |||
SmallVector<ValueDecl *, 4> lookupDirect( |
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 think it makes sense to return a TinyPtrVector here. There are a lot of cases where there's just one element.
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 result of this function is generally stored on the stack, so we're mostly talking saving some stack space (TinyPtrVector
is one pointer vs. seven for the SmallVector
). I'll make the change, though.
e411d44
to
c001337
Compare
This function was returning an ArrayRef pointing into a data structure that is easily mutated via code walking over that ArrayRef, which could cause spooky side effects, particularly during deserialization. Perform a defensive copy to eliminate such side effects.
…der" This reverts commit d3926d1.
c001337
to
464dac7
Compare
@swift-ci please smoke test and merge |
1 similar comment
@swift-ci please smoke test and merge |
In swiftlang#7530, NominalTypeDecl::lookupDirect() started returning TinyPtrVector instead of ArrayRef so that it wouldn’t be returning a pointer into a mutable data structure. Unfortunately, some callees assigned its return value into an ArrayRef; C++ happily converted the TinyPtrVector to an ArrayRef and then treated the TinyPtrVector as out-of-scope, so the ArrayRef would now point to an out-of-scope object. Oops.
In swiftlang#7530, NominalTypeDecl::lookupDirect() started returning TinyPtrVector instead of ArrayRef so that it wouldn’t be returning a pointer into a mutable data structure. Unfortunately, some callees assigned its return value into an ArrayRef; C++ happily converted the TinyPtrVector to an ArrayRef and then treated the TinyPtrVector as out-of-scope, so the ArrayRef would now point to an out-of-scope object. Oops.
Try to reinstate @slavapestov 's change to limit deserialization in
GenericSignatureBuilder
, with a fix to makeNominalTypeDecl::lookupDirect()
defensively copy its result.