-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[NFC] Replace uses of find(x) != end() idiom with contains(x) for StringRef and Set-like types #35229
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
[NFC] Replace uses of find(x) != end() idiom with contains(x) for StringRef and Set-like types #35229
Conversation
unittests/runtime/Mutex.cpp
Outdated
} else { | ||
if (trace) | ||
printf("Worker[%d] HIT for key = %d, value = %d.\n", i, key, | ||
value->second); | ||
found = true; // cache hit, no need to grab write lock | ||
} | ||
if (trace) | ||
printf("Worker[%d] HIT for key = %d, value = %d.\n", i, key, | ||
value->second); | ||
found = true; // cache hit, no need to grab write lock |
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 also added the missing else
in this code, but I'm not sure if it is okay to fix it in this PR as well?
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 would put it in a different PR. Different high level thing.
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.
A few thoughts:
- You are not only changing set like things here. In fact, it makes me worried in general about this patch. Instead you are changing some sort like things and in some cases StringRef. Please separate the StringRef changes into a separate commit.
- I found at least 1-2 cases where the patch is changing a single lookup into multiple lookups. Please remove that (I marked it).
Before this goes in I want to look at it again.
65e65fa
to
0af5519
Compare
@@ -233,8 +230,7 @@ static void printModule(SILModule *Mod, bool EmitVerboseSIL) { | |||
std::find(SILPrintOnlyFun.begin(), SILPrintOnlyFun.end(), F.getName())) | |||
F.dump(EmitVerboseSIL); | |||
|
|||
if (!SILPrintOnlyFuns.empty() && | |||
F.getName().find(SILPrintOnlyFuns, 0) != StringRef::npos) |
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.
A note for myself. Whats with the 0? (I am doing a surface level review scan now).
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.
@mininny I looked in StringRef.h. Looks like the 0 is a default argument to find that says start checking at the beginning. (Just answering my own question).
Just please move that last commit to a different PR and I think this is ready to go in. |
@swift-ci test |
Doing a quick test to see if everything works. |
Build failed |
Build failed |
@@ -142,8 +142,8 @@ static bool canonicalizeInputFunction(Function &F, ARCEntryPointBuilder &B, | |||
// Have not encountered a strong retain/release. keep it in the | |||
// unknown retain/release list for now. It might get replaced | |||
// later. | |||
if (NativeRefs.find(ArgVal) == NativeRefs.end()) { | |||
UnknownObjectRetains[ArgVal].push_back(&CI); | |||
if (!NativeRefs.contains(ArgVal)) { |
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.
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.
It seems like the change to llvm::DenseSet
hasn't landed on swift/main
branch so it's causing this issue..? The contains
method exists on llvm-project's apple/stable/20210107
branch; I'm not sure how the CI works but can this be fixed by moving the base branch? :)
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.
Yeah, seems like it hasn't ... I would say that use count
instead for Set
like would just be fine and already an improvement, but since the whole point of the SR is to use contains
I'm not really sure about that, so cc @varungandhi-apple @gottesmm
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.
Hmm, I seem to have made a mistake here. I looked at the git log
and I saw that contains
was added for SmallPtrSet
, so I figured methods for all the Set-like data types were available on swift/main
, since they were merged in succession to LLVM's main branch. However, looks like it's only present for SmallPtrSet
on swift/main
. Sorry about that.
We can wait for a couple of weeks; I'll ping this PR when we have the rebranch so we can run tests and land the change. I don't think cherry-picking changes onto other branches is the right fix here, as that might lead to more merge conflicts.
0af5519
to
09faa98
Compare
LGTM @swift-ci test |
Build failed |
Build failed |
Please revert the DenseSet refactoring
|
@CodaFi I posted this in a thread
Reverting is going to be more work, instead we can wait it out for changes to land on the LLVM side. |
Mishal just posted information on the rebranch in the forums: https://forums.swift.org/t/updating-llvm-project-swift-main-branch/44019. We can land this change once the rebranch is done. |
@mininny can you resolve the merge conflicts? I can run the tests after that. |
I think it's okay for now, but for the future, please prefer to rebase for resolving conflicts instead of merging, so that we have a cleaner history. @swift-ci smoke test |
Oh didn't realize that! Okay, Thanks! :) |
@swift-ci please smoke test |
c215f4d
to
2d8df59
Compare
2d8df59
to
53d1fc4
Compare
@swift-ci smoke test |
@swift-ci smoke test macOS |
This PR replaces usages of
.find(Key) != .end()
idiom with.contains(Key)
.Resolves SR-13950.
@varungandhi-apple Could you please review this? :) 🙏