This is an archive of the discontinued LLVM Phabricator instance.

[NFC] Rename AttributeList::has/getAttribute() -> has/getAttributeImpl()
AbandonedPublic

Authored by aeubanks on Aug 12 2021, 10:17 PM.

Details

Summary

AttributeList::get/hasAttribute() are confusing because they use indexes
where (unsigned)-1 represents the function, 0 represents the return
value, and 1+ represents parameters. I've been bitten by this multiple
times, assuming that the index only corresponds to parameters.

Adding Impl at the end of the name encourages users to use the less
confusing {get,has}{Fn,Ret,Param}Attribute().

Some places require a larger cleanup, so keep those using
get/hasAttribute() for now. Also, the C API uses these so we can't
really get rid of them/make them private.

This doesn't touch the methods that modify attributes. I'll clean those
up in the future.

Diff Detail

Event Timeline

aeubanks created this revision.Aug 12 2021, 10:17 PM
aeubanks published this revision for review.Aug 12 2021, 10:25 PM
aeubanks added reviewers: rnk, efriedma.
Herald added a reviewer: sstefan1. · View Herald Transcript
Herald added a reviewer: baziotis. · View Herald Transcript
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
rnk added a comment.Aug 13 2021, 9:30 AM

There's a related change here: https://reviews.llvm.org/D105485

Honestly, I like this approach better. Adding a strongly-typed integer wrapper is a pretty heavyweight solution for a problem that seems solvable with better named methods.

As a practical matter, consider splitting this up to reduce churn in case anything gets reverted. Most of the getAttribute -> getParamAttr calls can be migrated ahead of time as NFC commits to improve readability. The most risk-averse version of this change is to leave behind the getAttribute entry points as aliases to getAttributeImpl, and then remove them in a final commit.

aeubanks updated this revision to Diff 366380.Aug 13 2021, 5:08 PM

rebase past cleanups

aeubanks edited the summary of this revision. (Show Details)Aug 13 2021, 5:09 PM
aeubanks removed reviewers: jdoerfert, sstefan1, baziotis.
aeubanks updated this revision to Diff 366381.Aug 13 2021, 5:15 PM

one more place

aeubanks abandoned this revision.Sep 1 2021, 11:33 AM