-
Notifications
You must be signed in to change notification settings - Fork 10.5k
SIL: Replace uses of getReferencedFunction() by getReferencedFunction… #25073
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
aschwaighofer
merged 2 commits into
swiftlang:master
from
aschwaighofer:sil_getReferencedFunctionOrNull_getInitialReferencedFunction
May 28, 2019
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1844,9 +1844,26 @@ class ApplyInstBase<Impl, Base, false> : public Base { | |
bool isCalleeDynamicallyReplaceable() const; | ||
|
||
/// Gets the referenced function if the callee is a function_ref instruction. | ||
SILFunction *getReferencedFunction() const { | ||
/// Returns null if the callee is dynamic or a (prev_)dynamic_function_ref | ||
/// instruction. | ||
SILFunction *getReferencedFunctionOrNull() const { | ||
if (auto *FRI = dyn_cast<FunctionRefBaseInst>(getCallee())) | ||
return FRI->getReferencedFunction(); | ||
return FRI->getReferencedFunctionOrNull(); | ||
return nullptr; | ||
} | ||
|
||
/// Return the referenced function if the callee is a function_ref like | ||
/// instruction. | ||
/// | ||
/// WARNING: This not necessarily the function that will be called at runtime. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same spelling issue here. |
||
/// If the callee is a (prev_)dynamic_function_ref the actual function called | ||
/// might be different because it could be dynamically replaced at runtime. | ||
/// | ||
/// If the client of this API wants to look at the content of the returned SIL | ||
/// function it should call getReferencedFunctionOrNull() instead. | ||
SILFunction *getInitiallyReferencedFunction() const { | ||
if (auto *FRI = dyn_cast<FunctionRefBaseInst>(getCallee())) | ||
return FRI->getInitiallyReferencedFunction(); | ||
return nullptr; | ||
} | ||
|
||
|
@@ -2294,8 +2311,27 @@ class FunctionRefBaseInst : public LiteralInst { | |
public: | ||
~FunctionRefBaseInst(); | ||
|
||
/// Return the referenced function. | ||
SILFunction *getReferencedFunction() const { return f; } | ||
/// Return the referenced function if this is a function_ref instruction and | ||
/// therefore a client can rely on the dynamically called function being equal | ||
/// to the returned value and null otherwise. | ||
SILFunction *getReferencedFunctionOrNull() const { | ||
auto kind = getKind(); | ||
if (kind == SILInstructionKind::FunctionRefInst) | ||
return f; | ||
assert(kind == SILInstructionKind::DynamicFunctionRefInst || | ||
kind == SILInstructionKind::PreviousDynamicFunctionRefInst); | ||
return nullptr; | ||
} | ||
|
||
/// Return the initially referenced function. | ||
/// | ||
/// WARNING: This not necessarily the function that will be called at runtime. | ||
/// If the callee is a (prev_)dynamic_function_ref the actual function called | ||
/// might be different because it could be dynamically replaced at runtime. | ||
/// | ||
/// If the client of this API wants to look at the content of the returned SIL | ||
/// function it should call getReferencedFunctionOrNull() instead. | ||
SILFunction *getInitiallyReferencedFunction() const { return f; } | ||
|
||
void dropReferencedFunction(); | ||
|
||
|
@@ -7805,7 +7841,7 @@ SILFunction *ApplyInstBase<Impl, Base, false>::getCalleeFunction() const { | |
// previous_dynamic_function_ref as the target of those functions is not | ||
// statically known. | ||
if (auto *FRI = dyn_cast<FunctionRefInst>(Callee)) | ||
return FRI->getReferencedFunction(); | ||
return FRI->getReferencedFunctionOrNull(); | ||
|
||
if (auto *PAI = dyn_cast<PartialApplyInst>(Callee)) { | ||
Callee = PAI->getCalleeOrigin(); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could you put a newline here before, WARNING.