-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[NFC] Introduce isType and getDeclType #27195
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
Conversation
For consistency, shouldn't these be called |
They can be, but there was already a |
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 wasn't sure at first but looking through the diff shows that (a) an awful lot of code has gotten cleaner, and (b) we were already writing helpers to do basically this anyway. I do have comments but the general approach seems reasonable.
Would make sense or be useful to add something like this isStdlibType here too? |
It might make sense, maybe not in this patch though. |
9c1a5cd
to
cb4bcd7
Compare
Will fix conflict soon. |
4ca62f1
to
02111d3
Compare
0569522
to
1fc2b5a
Compare
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.
Last comment, I think!
@jrose-apple alright, should be good to go! |
@swift-ci Please test |
@swift-ci Please test source compatibility |
Build failed |
Build failed |
Are the failures related? |
Looks like it:
Maybe something around the pointer conversions is being too strict? |
We got this partially done in the linked PR. Do you have the time to rebase this and push on with the rest? |
@CodaFi I can update this weekend if that's fine. |
Accidentally forgot a negation address review notes Address more of Jordan's feedback
@CodaFi sorry this is a little later than last weekend, but I've rebased and fixed the issue upthread. Please take a look! I'll do another patch after this lands to find other places that have added more of the old way and update those. |
\ | ||
Type ASTContext::get##NAME##Type() const { \ | ||
if (!get##NAME##Decl()) \ | ||
return Type(); \ |
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 is the one thing I'm worried about. Clients of these accessors are historically terrible at handling the case where the lookup fails. That's why some of the TypeChecker entrypoints try to detect this, emit a diagnostic, and map the null type to an ErrorType
. There shouldn't be any clients of this function before Sema, so maybe we should just look into doing that everywhere.
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.
Slava pointed out in a previous commit that I did that perhaps if these accessors fail to just fail loudly because other pipelines of the compiler aren't great at handling whether or not they failed. Would that ease your concern, or should we still diagnose and provide an error type still?
@swift-ci test |
Build failed |
Build failed |
@CodaFi I've fixed the test issues related to function builders! |
@swift-ci test |
Build failed |
Build failed |
Ok, I’m going to take another look at the failing tests and resolve them. |
@@ -303,12 +303,12 @@ ClangTypeConverter::reverseBuiltinTypeMapping(IRGenModule &IGM, | |||
// Handle Int and UInt specially. On Apple platforms, these correspond to | |||
// the NSInteger and NSUInteger typedefs, so map them back to those typedefs | |||
// if they're available, to ensure we get consistent ObjC @encode strings. | |||
if (swiftType->getAnyNominal() == IGM.Context.getIntDecl()) { | |||
if (swiftType->isInt()) { |
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.
For changes in this file, please also update the corresponding code in ClangTypeConverter.cpp
, so that they don't get out of sync. 🙂 See my comment here in case you're wondering why there is this duplication.
I've noticed that there are a lot of cases where we dance around types by grabbing their nominal type and comparing that to some stdlib decl. Let's clean this up a little bit and introduce
isType
so that instead of dancing around this:it becomes:
Note: this is only applied to those stdlib types defined in
KnownStdlibTypes
.I've also introduced
getDeclType
which is shorthand for e.g.C.getBoolDecl()->getDeclaredInterfaceType()
==C.getBoolType()
.@slavapestov @jrose-apple (Sorry if this is a lot to review!)