Skip to content

[NFC] Remove AbstractFunctionDecl::computeType() #27806

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5834,10 +5834,6 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
}

public:
/// Compute the interface type of this function declaration from the
/// parameter types.
void computeType(AnyFunctionType::ExtInfo Info = FunctionType::ExtInfo());

/// Retrieve the source range of the function body.
SourceRange getBodySourceRange() const;

Expand Down
7 changes: 3 additions & 4 deletions lib/AST/Builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ StringRef swift::getBuiltinBaseName(ASTContext &C, StringRef Name,

/// Build a builtin function declaration.
static FuncDecl *
getBuiltinFunction(Identifier Id, ArrayRef<Type> argTypes, Type ResType,
FunctionType::ExtInfo Info = FunctionType::ExtInfo()) {
getBuiltinFunction(Identifier Id, ArrayRef<Type> argTypes, Type ResType) {
auto &Context = ResType->getASTContext();

ModuleDecl *M = Context.TheBuiltinModule;
Expand All @@ -177,7 +176,7 @@ getBuiltinFunction(Identifier Id, ArrayRef<Type> argTypes, Type ResType,
/*GenericParams=*/nullptr,
paramList,
TypeLoc::withoutLoc(ResType), DC);
FD->computeType(Info);
(void)FD->getInterfaceType();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of the new calls to (void)fn->getInterfaceType() should be necessary. Were you not able to remove them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm bad at rebasing, and when I was writing this up this morning I must have built on top of a bad revision. I think these can all go away now.

FD->setImplicit();
FD->setAccess(AccessLevel::Public);
return FD;
Expand Down Expand Up @@ -224,7 +223,7 @@ getBuiltinGenericFunction(Identifier Id,
TypeLoc::withoutLoc(ResType), DC);

func->setGenericSignature(Sig);
func->computeType();
(void)func->getInterfaceType();
func->setImplicit();
func->setAccess(AccessLevel::Public);

Expand Down
51 changes: 1 addition & 50 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3921,7 +3921,7 @@ GetDestructorRequest::evaluate(Evaluator &evaluator, ClassDecl *CD) const {
CD->recordObjCMethod(DD, DD->getObjCSelector());

// Assign DD the interface type (Self) -> () -> ()
DD->computeType();
(void)DD->getInterfaceType();

return DD;
}
Expand Down Expand Up @@ -6628,55 +6628,6 @@ Identifier OpaqueTypeDecl::getOpaqueReturnTypeIdentifier() const {
return OpaqueReturnTypeIdentifier;
}

void AbstractFunctionDecl::computeType(AnyFunctionType::ExtInfo info) {
auto sig = getGenericSignature();
bool hasSelf = hasImplicitSelfDecl();

// Result
Type resultTy;
if (auto fn = dyn_cast<FuncDecl>(this)) {
resultTy = fn->getResultInterfaceType();
} else if (auto ctor = dyn_cast<ConstructorDecl>(this)) {
resultTy = ctor->getResultInterfaceType();
} else {
assert(isa<DestructorDecl>(this));
resultTy = TupleType::getEmpty(getASTContext());
}

// (Args...) -> Result
Type funcTy;

{
SmallVector<AnyFunctionType::Param, 4> argTy;
getParameters()->getParams(argTy);

// 'throws' only applies to the innermost function.
info = info.withThrows(hasThrows());
// Defer bodies must not escape.
if (auto fd = dyn_cast<FuncDecl>(this))
info = info.withNoEscape(fd->isDeferBody());

if (sig && !hasSelf) {
funcTy = GenericFunctionType::get(sig, argTy, resultTy, info);
} else {
funcTy = FunctionType::get(argTy, resultTy, info);
}
}

// (Self) -> (Args...) -> Result
if (hasSelf) {
// Substitute in our own 'self' parameter.
auto selfParam = computeSelfParam(this);
if (sig)
funcTy = GenericFunctionType::get(sig, {selfParam}, funcTy);
else
funcTy = FunctionType::get({selfParam}, funcTy);
}

// Record the interface type.
setInterfaceType(funcTy);
}

bool AbstractFunctionDecl::hasInlinableBodyText() const {
switch (getBodyKind()) {
case BodyKind::Deserialized:
Expand Down
30 changes: 15 additions & 15 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ makeEnumRawValueConstructor(ClangImporter::Implementation &Impl,
ctorDecl->setImplicit();
ctorDecl->setAccess(AccessLevel::Public);

ctorDecl->computeType();
(void)ctorDecl->getInterfaceType();
ctorDecl->setBodySynthesizer(synthesizeEnumRawValueConstructorBody, enumDecl);
return ctorDecl;
}
Expand Down Expand Up @@ -617,7 +617,7 @@ static void makeEnumRawValueGetter(ClangImporter::Implementation &Impl,
getterDecl->setIsDynamic(false);
getterDecl->setIsTransparent(false);

getterDecl->computeType();
(void)getterDecl->getInterfaceType();

getterDecl->setAccess(AccessLevel::Public);
getterDecl->setBodySynthesizer(synthesizeEnumRawValueGetterBody, enumDecl);
Expand Down Expand Up @@ -698,7 +698,7 @@ static AccessorDecl *makeStructRawValueGetter(
getterDecl->setIsDynamic(false);
getterDecl->setIsTransparent(false);

getterDecl->computeType();
(void)getterDecl->getInterfaceType();

getterDecl->setAccess(AccessLevel::Public);
getterDecl->setBodySynthesizer(synthesizeStructRawValueGetterBody, storedVar);
Expand Down Expand Up @@ -729,7 +729,7 @@ static AccessorDecl *makeFieldGetterDecl(ClangImporter::Implementation &Impl,
getterDecl->setIsObjC(false);
getterDecl->setIsDynamic(false);

getterDecl->computeType();
(void)getterDecl->getInterfaceType();

return getterDecl;
}
Expand Down Expand Up @@ -765,7 +765,7 @@ static AccessorDecl *makeFieldSetterDecl(ClangImporter::Implementation &Impl,
setterDecl->setSelfAccessKind(SelfAccessKind::Mutating);
setterDecl->setAccess(AccessLevel::Public);

setterDecl->computeType();
(void)setterDecl->getInterfaceType();

return setterDecl;
}
Expand Down Expand Up @@ -1309,7 +1309,7 @@ createDefaultConstructor(ClangImporter::Implementation &Impl,
/*GenericParams=*/nullptr, structDecl);

// Set the constructor's type.
constructor->computeType();
(void)constructor->getInterfaceType();

constructor->setAccess(AccessLevel::Public);

Expand Down Expand Up @@ -1438,7 +1438,7 @@ createValueConstructor(ClangImporter::Implementation &Impl,
/*GenericParams=*/nullptr, structDecl);

// Set the constructor's type.
constructor->computeType();
(void)constructor->getInterfaceType();

constructor->setAccess(AccessLevel::Public);

Expand Down Expand Up @@ -1714,7 +1714,7 @@ buildSubscriptGetterDecl(ClangImporter::Implementation &Impl,
TypeLoc::withoutLoc(elementTy), dc,
getter->getClangNode());

thunk->computeType();
(void)thunk->getInterfaceType();

thunk->setAccess(getOverridableAccessLevel(dc));

Expand Down Expand Up @@ -1767,7 +1767,7 @@ buildSubscriptSetterDecl(ClangImporter::Implementation &Impl,
valueIndicesPL,
TypeLoc::withoutLoc(TupleType::getEmpty(C)), dc,
setter->getClangNode());
thunk->computeType();
(void)thunk->getInterfaceType();

thunk->setAccess(getOverridableAccessLevel(dc));

Expand Down Expand Up @@ -1952,7 +1952,7 @@ static bool addErrorDomain(NominalTypeDecl *swiftDecl,
/*GenericParams=*/nullptr,
params,
TypeLoc::withoutLoc(stringTy), swiftDecl);
getterDecl->computeType();
(void)getterDecl->getInterfaceType();
getterDecl->setIsObjC(false);
getterDecl->setIsDynamic(false);
getterDecl->setIsTransparent(false);
Expand Down Expand Up @@ -3736,7 +3736,7 @@ namespace {

result->setIsObjC(false);
result->setIsDynamic(false);
result->computeType();
(void)result->getInterfaceType();

Impl.recordImplicitUnwrapForDecl(result,
importedType.isImplicitlyUnwrapped());
Expand Down Expand Up @@ -4320,7 +4320,7 @@ namespace {
result->setImplicit();

// Compute the interface type.
result->computeType();
(void)result->getInterfaceType();

Impl.recordImplicitUnwrapForDecl(result, isIUO);

Expand Down Expand Up @@ -5792,7 +5792,7 @@ Decl *SwiftDeclConverter::importGlobalAsInitializer(
result->setImportAsStaticMember();

// Set the constructor's type.
result->computeType();
(void)result->getInterfaceType();
Impl.recordImplicitUnwrapForDecl(result,
importedType.isImplicitlyUnwrapped());
result->setOverriddenDecls({ });
Expand Down Expand Up @@ -6300,7 +6300,7 @@ ConstructorDecl *SwiftDeclConverter::importConstructor(
addObjCAttribute(result, selector);

// Calculate the function type of the result.
result->computeType();
(void)result->getInterfaceType();

Impl.recordImplicitUnwrapForDecl(result,
importedType.isImplicitlyUnwrapped());
Expand Down Expand Up @@ -8342,7 +8342,7 @@ ClangImporter::Implementation::createConstant(Identifier name, DeclContext *dc,
params,
TypeLoc::withoutLoc(type), dc);
func->setStatic(isStatic);
func->computeType();
(void)func->getInterfaceType();
func->setAccess(getOverridableAccessLevel(dc));
func->setIsObjC(false);
func->setIsDynamic(false);
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/CodeSynthesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ createDesignatedInitOverride(ClassDecl *classDecl,

// Set the interface type of the initializer.
ctor->setGenericSignature(genericSig);
ctor->computeType();
(void)ctor->getInterfaceType();

ctor->setImplicitlyUnwrappedOptional(
superclassCtor->isImplicitlyUnwrappedOptional());
Expand Down
4 changes: 2 additions & 2 deletions lib/Sema/DerivedConformanceCodable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ static FuncDecl *deriveEncodable_encode(DerivedConformance &derived) {
encodeDecl->getAttrs().add(attr);
}

encodeDecl->computeType(FunctionType::ExtInfo().withThrows());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, these aren't correct. The throws bit goes on the inner function type.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to store the throws bit somewhere now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The throwing bit gets applied to the ext info based on whether the throwing bit is set in the function decl. Both the changed places in the Codable conformance synthesis stuff are already setting that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok.

(void)encodeDecl->getInterfaceType();

encodeDecl->copyFormalAccessFrom(derived.Nominal,
/*sourceIsParentContext*/ true);
Expand Down Expand Up @@ -1030,7 +1030,7 @@ static ValueDecl *deriveDecodable_init(DerivedConformance &derived) {
initDecl->getAttrs().add(reqAttr);
}

initDecl->computeType(AnyFunctionType::ExtInfo().withThrows());
(void)initDecl->getInterfaceType();

initDecl->copyFormalAccessFrom(derived.Nominal,
/*sourceIsParentContext*/ true);
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/DerivedConformanceCodingKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static ValueDecl *deriveInitDecl(DerivedConformance &derived, Type paramType,
synthesizer(initDecl);

// Compute the interface type of the initializer.
initDecl->computeType();
(void)initDecl->getInterfaceType();

initDecl->setAccess(derived.Nominal->getFormalAccess());

Expand Down
6 changes: 3 additions & 3 deletions lib/Sema/DerivedConformanceEquatableHashable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ deriveEquatable_eq(
eqDecl->setBodySynthesizer(bodySynthesizer);

// Compute the interface type.
eqDecl->computeType();
(void)eqDecl->getInterfaceType();

eqDecl->copyFormalAccessFrom(derived.Nominal, /*sourceIsParentContext*/ true);

Expand Down Expand Up @@ -892,7 +892,7 @@ deriveHashable_hashInto(
hashDecl->setImplicit();
hashDecl->setBodySynthesizer(bodySynthesizer);

hashDecl->computeType();
(void)hashDecl->getInterfaceType();
hashDecl->copyFormalAccessFrom(derived.Nominal);

C.addSynthesizedDecl(hashDecl);
Expand Down Expand Up @@ -1241,7 +1241,7 @@ static ValueDecl *deriveHashable_hashValue(DerivedConformance &derived) {
getterDecl->setIsTransparent(false);

// Compute the interface type of hashValue().
getterDecl->computeType();
(void)getterDecl->getInterfaceType();

getterDecl->copyFormalAccessFrom(derived.Nominal,
/*sourceIsParentContext*/ true);
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/DerivedConformanceRawRepresentable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ deriveRawRepresentable_init(DerivedConformance &derived) {
initDecl->setBodySynthesizer(&deriveBodyRawRepresentable_init);

// Compute the interface type of the initializer.
initDecl->computeType();
(void)initDecl->getInterfaceType();

initDecl->copyFormalAccessFrom(enumDecl, /*sourceIsParentContext*/true);

Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/DerivedConformances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ DerivedConformance::declareDerivedPropertyGetter(VarDecl *property,
getterDecl->setIsTransparent(false);

// Compute the interface type of the getter.
getterDecl->computeType();
(void)getterDecl->getInterfaceType();

getterDecl->copyFormalAccessFrom(property);

Expand Down
8 changes: 4 additions & 4 deletions lib/Serialization/Deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2564,7 +2564,7 @@ class swift::DeclDeserializer {
}

ctor->setImplicitlyUnwrappedOptional(isIUO);
ctor->computeType();
(void)ctor->getInterfaceType();

return ctor;
}
Expand Down Expand Up @@ -3036,8 +3036,8 @@ class swift::DeclDeserializer {
cast<OpaqueTypeDecl>(MF.getDecl(opaqueReturnTypeID)));
}

// Set the interface type.
fn->computeType();
// Compute the interface type.
(void)fn->getInterfaceType();

return fn;
}
Expand Down Expand Up @@ -3820,7 +3820,7 @@ class swift::DeclDeserializer {

dtor->setAccess(std::max(cast<ClassDecl>(DC)->getFormalAccess(),
AccessLevel::Internal));
dtor->computeType();
(void)dtor->getInterfaceType();

if (isImplicit)
dtor->setImplicit();
Expand Down