-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[NFC] Decompose function input types #10264
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
@swift-ci please test |
Build failed |
@swift-ci please test macOS platform |
Build failed |
@swift-ci please test macOS platform |
Build failed |
@swift-ci please test macOS platform |
include/swift/AST/Types.h
Outdated
Identifier Label; | ||
|
||
/// Whether the parameter has a default argument. Not valid for arguments. | ||
bool HasDefaultArgument = false; |
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 commented on this on your other PR that builds on this... HasDefaultArgument
really shouldn't be in the canonicalization. I don't think we can hoist CallArgParam
up to the type system like this.
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.
We may need it for argument matching on overloads.
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 doesn't belong in the type, though, and we don't want it to look like it has meaning there. I think CallArgParam
needs to stay where it is, and we can introduce a AnyFunctionType::Param
(or similar) that only captures what's actually in the type system.
include/swift/AST/Types.h
Outdated
@@ -2295,7 +2323,8 @@ getSILFunctionLanguage(SILFunctionTypeRepresentation rep) { | |||
/// be 'thin', indicating that a function value has no capture context and can be | |||
/// represented at the binary level as a single function pointer. | |||
class AnyFunctionType : public TypeBase { | |||
const Type Input; | |||
const ArrayRef<CallArgParam> Input; |
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.
As noted before, we should use tail allocation to store the parameters and save ourselves the pointer/indirection.
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.
llvm::TrailingObjects
requires this class be final
.
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, you'd need to do the TrailingObjects
thing on the subclasses
Build failed |
654bbe0
to
2085963
Compare
@swift-ci please test |
Build failed |
Build failed |
Build failed |
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 have minor comments, but this is looking great.
include/swift/AST/Types.h
Outdated
@@ -2501,22 +2534,35 @@ END_CAN_TYPE_WRAPPER(AnyFunctionType, Type) | |||
/// | |||
/// For example: | |||
/// let x : (Float, Int) -> Int | |||
class FunctionType : public AnyFunctionType { | |||
class alignas(AnyFunctionType::Param) FunctionType final : |
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.
But... fixing the alignment of FunctionType
doesn't help the trailing objects be properly aligned. You don't need this alignas
change.
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.
Same for GenericFunctionType
?
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.
Right.
include/swift/AST/Types.h
Outdated
private llvm::TrailingObjects<FunctionType, AnyFunctionType::Param> { | ||
friend TrailingObjects; | ||
|
||
unsigned NumParams; |
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 guess this doesn't fit into AnyFunctionTypeBitfields
, eh? ;)
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.
Encode it in a pointer union and you've got a deal.
include/swift/AST/Types.h
Outdated
private llvm::TrailingObjects<GenericFunctionType, AnyFunctionType::Param> { | ||
friend TrailingObjects; | ||
|
||
unsigned NumParams; |
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.
Sink NumParams
down into AnyFunctionType
?
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.
👍
2085963
to
7ebdb27
Compare
Prepares the AST for future work to eliminate `getInput()` and perform function type argument matching in a less ad-hoc manner.
7ebdb27
to
0b5f442
Compare
@swift-ci please smoke test |
⛵️ |
Prepares the AST for future work to eliminate
getInput()
and perform function type argument matching in a less ad-hoc manner.