-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[sil] Add an implicit operator bool conversion to SILDebugLocation. #33161
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
[sil] Add an implicit operator bool conversion to SILDebugLocation. #33161
Conversation
The reason to do this is that one can now do: ``` if (auto debugLoc = i.getDebugLocation()) { // do something with debug loc. } ``` I also cleaned up the style a little bit by renaming the internal ivars to be camelCase.
@swift-ci smoke test |
@@ -755,17 +755,18 @@ class SILDebugScope; | |||
|
|||
/// A SILLocation paired with a SILDebugScope. | |||
class SILDebugLocation { | |||
const SILDebugScope *Scope = nullptr; | |||
SILLocation Location; | |||
const SILDebugScope *debugScope; |
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 original code used the LLVM naming convention. Do we now have a Swift naming convention that's different from the LLVM one?
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.
Yes. Swift does camelCase for variables. We are slowly changing over time.
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.
And LLVM is changing more to that style as well
: Scope(DS), Location(Loc) {} | ||
SILLocation getLocation() const { return Location; } | ||
const SILDebugScope *getScope() const { return Scope; } | ||
: debugScope(nullptr), |
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 prefer the = nullptr spelling, since it makes it harder to forget to initialize the member when adding a new constructor.
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.
Ok. To me it just looked redundant. I am fine fixing it in a follow on commit.
: debugScope(debugScope), location(location) {} | ||
SILLocation getLocation() const { return location; } | ||
const SILDebugScope *getScope() const { return debugScope; } | ||
operator bool() const { return bool(location) && debugScope; } |
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.
This part LGTM.
Are there any legitimate cases where we would have an invalid location on an instruction when we're not inside of SILGen or SILParser? |
@adrian-prantl It can happen at any time and code (like what I am writing now) should be able to be conservative, unless there is a verification check that I can depend on this always being there. |
The reason to do this is that one can now do:
I also cleaned up the style a little bit by renaming the internal ivars to be
camelCase.