Skip to content

[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

Merged

Conversation

DougGregor
Copy link
Member

Try to reinstate @slavapestov 's change to limit deserialization in GenericSignatureBuilder, with a fix to make NominalTypeDecl::lookupDirect() defensively copy its result.

@DougGregor
Copy link
Member Author

@swift-ci please smoke test and merge

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

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.

Copy link
Member Author

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.

@DougGregor DougGregor force-pushed the generic-signature-deserialization branch from e411d44 to c001337 Compare February 16, 2017 18:50
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.
@DougGregor DougGregor force-pushed the generic-signature-deserialization branch from c001337 to 464dac7 Compare February 16, 2017 18:59
@DougGregor
Copy link
Member Author

@swift-ci please smoke test and merge

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please smoke test and merge

@swift-ci swift-ci merged commit 46f4358 into swiftlang:master Feb 16, 2017
@DougGregor DougGregor deleted the generic-signature-deserialization branch February 16, 2017 19:25
beccadax added a commit to beccadax/swift that referenced this pull request Nov 14, 2018
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.
beccadax added a commit to beccadax/swift that referenced this pull request Nov 15, 2018
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.
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