-
Notifications
You must be signed in to change notification settings - Fork 10.5k
More progress on uncurry level removal #12785
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -227,29 +227,6 @@ static bool hasLoweredLocalCaptures(AnyFunctionRef AFR, | |
return false; | ||
} | ||
|
||
static unsigned getFuncNaturalUncurryLevel(AnyFunctionRef AFR) { | ||
assert(AFR.getParameterLists().size() >= 1 && "no arguments for func?!"); | ||
return AFR.getParameterLists().size() - 1; | ||
} | ||
|
||
unsigned swift::getNaturalUncurryLevel(ValueDecl *vd) { | ||
if (auto *func = dyn_cast<FuncDecl>(vd)) { | ||
return getFuncNaturalUncurryLevel(func); | ||
} else if (isa<ConstructorDecl>(vd)) { | ||
return 1; | ||
} else if (auto *ed = dyn_cast<EnumElementDecl>(vd)) { | ||
return ed->hasAssociatedValues() ? 1 : 0; | ||
} else if (isa<DestructorDecl>(vd)) { | ||
return 0; | ||
} else if (isa<ClassDecl>(vd)) { | ||
return 1; | ||
} else if (isa<VarDecl>(vd)) { | ||
return 0; | ||
} else { | ||
llvm_unreachable("Unhandled ValueDecl for SILDeclRef"); | ||
} | ||
} | ||
|
||
SILDeclRef::SILDeclRef(ValueDecl *vd, SILDeclRef::Kind kind, | ||
ResilienceExpansion expansion, | ||
bool isCurried, bool isForeign) | ||
|
@@ -888,12 +865,23 @@ SubclassScope SILDeclRef::getSubclassScope() const { | |
llvm_unreachable("Unhandled access level in switch."); | ||
} | ||
|
||
unsigned SILDeclRef::getUncurryLevel() const { | ||
if (isCurried) | ||
return 0; | ||
if (!hasDecl()) | ||
return getFuncNaturalUncurryLevel(*getAnyFunctionRef()); | ||
if (kind == Kind::DefaultArgGenerator) | ||
return 0; | ||
return getNaturalUncurryLevel(getDecl()); | ||
unsigned SILDeclRef::getParameterListCount() const { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add more documentation here and use early-exits instead of else-if return? What I want is for each case to say /why/ it has X amounts of parameters. For instance, why does ClassDecl have 2 parameters? It would also be nice to have a bigger comment explaining this methods use/importance in the larger world of SIL. |
||
if (isCurried || !hasDecl() || kind == Kind::DefaultArgGenerator) | ||
return 1; | ||
|
||
auto *vd = getDecl(); | ||
|
||
if (auto *func = dyn_cast<AbstractFunctionDecl>(vd)) { | ||
return func->getParameterLists().size(); | ||
} else if (auto *ed = dyn_cast<EnumElementDecl>(vd)) { | ||
return ed->hasAssociatedValues() ? 2 : 1; | ||
} else if (isa<DestructorDecl>(vd)) { | ||
return 1; | ||
} else if (isa<ClassDecl>(vd)) { | ||
return 2; | ||
} else if (isa<VarDecl>(vd)) { | ||
return 1; | ||
} else { | ||
llvm_unreachable("Unhandled ValueDecl for SILDeclRef"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1777,7 +1777,7 @@ static bool isImporterGeneratedAccessor(const clang::Decl *clangDecl, | |
return false; | ||
|
||
// Must be a type member. | ||
if (constant.getUncurryLevel() != 1) | ||
if (constant.getParameterListCount() != 2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a comment here why you are checking against 2? Couldn't this be a method on SILDeclRef with a nice comment that explains what is happening here? |
||
return false; | ||
|
||
// Must be imported from a function. | ||
|
@@ -2486,7 +2486,7 @@ getAbstractionPatternForConstant(ASTContext &ctx, SILDeclRef constant, | |
TypeConverter::LoweredFormalTypes | ||
TypeConverter::getLoweredFormalTypes(SILDeclRef constant, | ||
CanAnyFunctionType fnType) { | ||
unsigned uncurryLevel = constant.getUncurryLevel(); | ||
unsigned uncurryLevel = constant.getParameterListCount() - 1; | ||
auto extInfo = fnType->getExtInfo(); | ||
|
||
// Form an abstraction pattern for bridging purposes. | ||
|
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.
Instead of using a constant - 1 here, can you turn this into a method on Result with a descriptive name/comment.