mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Sema: Use AbstractFunctionDecl::computeType()
This commit is contained in:
@@ -704,20 +704,9 @@ static FuncDecl *deriveEncodable_encode(DerivedConformance &derived) {
|
|||||||
// output: ()
|
// output: ()
|
||||||
// Create from the inside out:
|
// Create from the inside out:
|
||||||
|
|
||||||
// (to: Encoder)
|
|
||||||
auto encoderType = C.getEncoderDecl()->getDeclaredInterfaceType();
|
auto encoderType = C.getEncoderDecl()->getDeclaredInterfaceType();
|
||||||
auto inputTypeElt = TupleTypeElt(encoderType, C.Id_to);
|
|
||||||
auto inputType = TupleType::get(ArrayRef<TupleTypeElt>(inputTypeElt), C);
|
|
||||||
|
|
||||||
// throws
|
|
||||||
auto extInfo = FunctionType::ExtInfo(FunctionTypeRepresentation::Swift,
|
|
||||||
/*Throws=*/true);
|
|
||||||
// ()
|
|
||||||
auto returnType = TupleType::getEmpty(C);
|
auto returnType = TupleType::getEmpty(C);
|
||||||
|
|
||||||
// (to: Encoder) throws -> ()
|
|
||||||
auto innerType = FunctionType::get(inputType, returnType, extInfo);
|
|
||||||
|
|
||||||
// Params: (self [implicit], Encoder)
|
// Params: (self [implicit], Encoder)
|
||||||
auto *selfDecl = ParamDecl::createSelf(SourceLoc(), conformanceDC);
|
auto *selfDecl = ParamDecl::createSelf(SourceLoc(), conformanceDC);
|
||||||
auto *encoderParam = new (C)
|
auto *encoderParam = new (C)
|
||||||
@@ -745,21 +734,10 @@ static FuncDecl *deriveEncodable_encode(DerivedConformance &derived) {
|
|||||||
encodeDecl->getAttrs().add(attr);
|
encodeDecl->getAttrs().add(attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Evaluate the type of Self in (Self) -> (Encoder) throws -> ().
|
if (auto env = conformanceDC->getGenericEnvironmentOfContext())
|
||||||
Type selfType = conformanceDC->getDeclaredInterfaceType();
|
encodeDecl->setGenericEnvironment(env);
|
||||||
Type interfaceType;
|
encodeDecl->computeType(FunctionType::ExtInfo().withThrows());
|
||||||
if (auto sig = conformanceDC->getGenericSignatureOfContext()) {
|
|
||||||
// Evaluate the below, but in a generic environment (if Self is generic).
|
|
||||||
encodeDecl->setGenericEnvironment(
|
|
||||||
conformanceDC->getGenericEnvironmentOfContext());
|
|
||||||
interfaceType = GenericFunctionType::get(sig, selfType, innerType,
|
|
||||||
FunctionType::ExtInfo());
|
|
||||||
} else {
|
|
||||||
// (Self) -> innerType == (Encoder) throws -> ()
|
|
||||||
interfaceType = FunctionType::get(selfType, innerType);
|
|
||||||
}
|
|
||||||
|
|
||||||
encodeDecl->setInterfaceType(interfaceType);
|
|
||||||
encodeDecl->setValidationToChecked();
|
encodeDecl->setValidationToChecked();
|
||||||
encodeDecl->copyFormalAccessFrom(derived.Nominal,
|
encodeDecl->copyFormalAccessFrom(derived.Nominal,
|
||||||
/*sourceIsParentContext*/ true);
|
/*sourceIsParentContext*/ true);
|
||||||
@@ -1030,26 +1008,13 @@ static ValueDecl *deriveDecodable_init(DerivedConformance &derived) {
|
|||||||
// output: Self
|
// output: Self
|
||||||
// Compute from the inside out:
|
// Compute from the inside out:
|
||||||
|
|
||||||
// (from: Decoder)
|
|
||||||
auto decoderType = C.getDecoderDecl()->getDeclaredInterfaceType();
|
|
||||||
auto inputTypeElt = TupleTypeElt(decoderType, C.Id_from);
|
|
||||||
auto inputType = TupleType::get(ArrayRef<TupleTypeElt>(inputTypeElt), C);
|
|
||||||
|
|
||||||
// throws
|
|
||||||
auto extInfo = FunctionType::ExtInfo(FunctionTypeRepresentation::Swift,
|
|
||||||
/*Throws=*/true);
|
|
||||||
|
|
||||||
// (Self)
|
|
||||||
auto returnType = derived.Nominal->getDeclaredInterfaceType();
|
|
||||||
|
|
||||||
// (from: Decoder) throws -> (Self)
|
|
||||||
Type innerType = FunctionType::get(inputType, returnType, extInfo);
|
|
||||||
|
|
||||||
// Params: (self [implicit], Decoder)
|
// Params: (self [implicit], Decoder)
|
||||||
// self should be inout if the type is a value type; not inout otherwise.
|
// self should be inout if the type is a value type; not inout otherwise.
|
||||||
auto *selfDecl = ParamDecl::createSelf(SourceLoc(), conformanceDC,
|
auto *selfDecl = ParamDecl::createSelf(SourceLoc(), conformanceDC,
|
||||||
/*isStatic=*/false,
|
/*isStatic=*/false,
|
||||||
/*isInOut=*/!classDecl);
|
/*isInOut=*/!classDecl);
|
||||||
|
|
||||||
|
auto decoderType = C.getDecoderDecl()->getDeclaredInterfaceType();
|
||||||
auto *decoderParamDecl = new (C) ParamDecl(
|
auto *decoderParamDecl = new (C) ParamDecl(
|
||||||
VarDecl::Specifier::Default, SourceLoc(), SourceLoc(), C.Id_from,
|
VarDecl::Specifier::Default, SourceLoc(), SourceLoc(), C.Id_from,
|
||||||
SourceLoc(), C.Id_decoder, decoderType, conformanceDC);
|
SourceLoc(), C.Id_decoder, decoderType, conformanceDC);
|
||||||
@@ -1075,29 +1040,11 @@ static ValueDecl *deriveDecodable_init(DerivedConformance &derived) {
|
|||||||
initDecl->getAttrs().add(reqAttr);
|
initDecl->getAttrs().add(reqAttr);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto selfParam = computeSelfParam(initDecl);
|
if (auto env = conformanceDC->getGenericEnvironmentOfContext())
|
||||||
auto initSelfParam = computeSelfParam(initDecl, /*init=*/true);
|
initDecl->setGenericEnvironment(env);
|
||||||
Type interfaceType;
|
initDecl->computeType(AnyFunctionType::ExtInfo().withThrows());
|
||||||
Type initializerType;
|
|
||||||
if (auto sig = conformanceDC->getGenericSignatureOfContext()) {
|
|
||||||
// Evaluate the below, but in a generic environment (if Self is generic).
|
|
||||||
initDecl->setGenericEnvironment(
|
|
||||||
conformanceDC->getGenericEnvironmentOfContext());
|
|
||||||
interfaceType = GenericFunctionType::get(sig, {selfParam}, innerType,
|
|
||||||
FunctionType::ExtInfo());
|
|
||||||
initializerType = GenericFunctionType::get(sig, {initSelfParam}, innerType,
|
|
||||||
FunctionType::ExtInfo());
|
|
||||||
} else {
|
|
||||||
// (Self) -> (Decoder) throws -> (Self)
|
|
||||||
interfaceType = FunctionType::get({selfParam}, innerType,
|
|
||||||
FunctionType::ExtInfo());
|
|
||||||
initializerType = FunctionType::get({initSelfParam}, innerType,
|
|
||||||
FunctionType::ExtInfo());
|
|
||||||
}
|
|
||||||
|
|
||||||
initDecl->setInterfaceType(interfaceType);
|
|
||||||
initDecl->setValidationToChecked();
|
initDecl->setValidationToChecked();
|
||||||
initDecl->setInitializerInterfaceType(initializerType);
|
|
||||||
initDecl->copyFormalAccessFrom(derived.Nominal,
|
initDecl->copyFormalAccessFrom(derived.Nominal,
|
||||||
/*sourceIsParentContext*/ true);
|
/*sourceIsParentContext*/ true);
|
||||||
|
|
||||||
|
|||||||
@@ -141,37 +141,11 @@ static ValueDecl *deriveInitDecl(DerivedConformance &derived, Type paramType,
|
|||||||
// Synthesize the body.
|
// Synthesize the body.
|
||||||
synthesizer(initDecl);
|
synthesizer(initDecl);
|
||||||
|
|
||||||
// Compute the type of the initializer.
|
|
||||||
TupleTypeElt element(paramType, paramName);
|
|
||||||
TupleTypeElt interfaceElement(paramType, paramName);
|
|
||||||
auto interfaceArgType = TupleType::get(interfaceElement, C);
|
|
||||||
|
|
||||||
// Compute the interface type of the initializer.
|
// Compute the interface type of the initializer.
|
||||||
Type retInterfaceType =
|
if (auto env = parentDC->getGenericEnvironmentOfContext())
|
||||||
OptionalType::get(parentDC->getDeclaredInterfaceType());
|
initDecl->setGenericEnvironment(env);
|
||||||
Type interfaceType = FunctionType::get(interfaceArgType, retInterfaceType);
|
initDecl->computeType();
|
||||||
auto selfParam = computeSelfParam(initDecl);
|
|
||||||
auto initSelfParam = computeSelfParam(initDecl, /*init*/ true);
|
|
||||||
|
|
||||||
Type allocIfaceType;
|
|
||||||
Type initIfaceType;
|
|
||||||
if (auto sig = parentDC->getGenericSignatureOfContext()) {
|
|
||||||
initDecl->setGenericEnvironment(parentDC->getGenericEnvironmentOfContext());
|
|
||||||
|
|
||||||
allocIfaceType = GenericFunctionType::get(sig, {selfParam},
|
|
||||||
interfaceType,
|
|
||||||
FunctionType::ExtInfo());
|
|
||||||
initIfaceType = GenericFunctionType::get(sig, {initSelfParam},
|
|
||||||
interfaceType,
|
|
||||||
FunctionType::ExtInfo());
|
|
||||||
} else {
|
|
||||||
allocIfaceType = FunctionType::get({selfParam},
|
|
||||||
interfaceType, FunctionType::ExtInfo());
|
|
||||||
initIfaceType = FunctionType::get({initSelfParam},
|
|
||||||
interfaceType, FunctionType::ExtInfo());
|
|
||||||
}
|
|
||||||
initDecl->setInterfaceType(allocIfaceType);
|
|
||||||
initDecl->setInitializerInterfaceType(initIfaceType);
|
|
||||||
initDecl->setAccess(derived.Nominal->getFormalAccess());
|
initDecl->setAccess(derived.Nominal->getFormalAccess());
|
||||||
initDecl->setValidationToChecked();
|
initDecl->setValidationToChecked();
|
||||||
|
|
||||||
|
|||||||
@@ -647,25 +647,11 @@ deriveEquatable_eq(DerivedConformance &derived, Identifier generatedIdentifier,
|
|||||||
|
|
||||||
eqDecl->setBodySynthesizer(bodySynthesizer);
|
eqDecl->setBodySynthesizer(bodySynthesizer);
|
||||||
|
|
||||||
// Compute the type.
|
|
||||||
Type paramsTy = params->getInterfaceType(C);
|
|
||||||
|
|
||||||
// Compute the interface type.
|
// Compute the interface type.
|
||||||
Type interfaceTy;
|
if (auto genericEnv = parentDC->getGenericEnvironmentOfContext())
|
||||||
auto selfParam = computeSelfParam(eqDecl);
|
eqDecl->setGenericEnvironment(genericEnv);
|
||||||
if (auto genericSig = parentDC->getGenericSignatureOfContext()) {
|
eqDecl->computeType();
|
||||||
eqDecl->setGenericEnvironment(parentDC->getGenericEnvironmentOfContext());
|
|
||||||
|
|
||||||
interfaceTy = FunctionType::get(paramsTy, boolTy,
|
|
||||||
AnyFunctionType::ExtInfo());
|
|
||||||
interfaceTy = GenericFunctionType::get(genericSig, {selfParam}, interfaceTy,
|
|
||||||
AnyFunctionType::ExtInfo());
|
|
||||||
} else {
|
|
||||||
interfaceTy = FunctionType::get(paramsTy, boolTy);
|
|
||||||
interfaceTy = FunctionType::get({selfParam}, interfaceTy,
|
|
||||||
FunctionType::ExtInfo());
|
|
||||||
}
|
|
||||||
eqDecl->setInterfaceType(interfaceTy);
|
|
||||||
eqDecl->copyFormalAccessFrom(derived.Nominal, /*sourceIsParentContext*/ true);
|
eqDecl->copyFormalAccessFrom(derived.Nominal, /*sourceIsParentContext*/ true);
|
||||||
eqDecl->setValidationToChecked();
|
eqDecl->setValidationToChecked();
|
||||||
|
|
||||||
@@ -781,24 +767,9 @@ deriveHashable_hashInto(DerivedConformance &derived,
|
|||||||
hashDecl->setImplicit();
|
hashDecl->setImplicit();
|
||||||
hashDecl->setBodySynthesizer(bodySynthesizer);
|
hashDecl->setBodySynthesizer(bodySynthesizer);
|
||||||
|
|
||||||
// Evaluate type of Self in (Self) -> (into: inout Hasher) -> ()
|
if (auto env = parentDC->getGenericEnvironmentOfContext())
|
||||||
auto selfParam = computeSelfParam(hashDecl);
|
hashDecl->setGenericEnvironment(env);
|
||||||
auto inoutFlag = ParameterTypeFlags().withInOut(true);
|
hashDecl->computeType();
|
||||||
auto hasherParam = AnyFunctionType::Param(hasherType, C.Id_into, inoutFlag);
|
|
||||||
auto innerType = FunctionType::get({hasherParam}, returnType,
|
|
||||||
FunctionType::ExtInfo());
|
|
||||||
|
|
||||||
Type interfaceType;
|
|
||||||
if (auto sig = parentDC->getGenericSignatureOfContext()) {
|
|
||||||
hashDecl->setGenericEnvironment(parentDC->getGenericEnvironmentOfContext());
|
|
||||||
interfaceType = GenericFunctionType::get(sig, {selfParam}, innerType,
|
|
||||||
FunctionType::ExtInfo());
|
|
||||||
} else {
|
|
||||||
// (Self) -> innerType == (inout Hasher) -> ()
|
|
||||||
interfaceType = FunctionType::get({selfParam}, innerType,
|
|
||||||
FunctionType::ExtInfo());
|
|
||||||
}
|
|
||||||
hashDecl->setInterfaceType(interfaceType);
|
|
||||||
hashDecl->copyFormalAccessFrom(derived.Nominal);
|
hashDecl->copyFormalAccessFrom(derived.Nominal);
|
||||||
hashDecl->setValidationToChecked();
|
hashDecl->setValidationToChecked();
|
||||||
|
|
||||||
@@ -1104,21 +1075,11 @@ static ValueDecl *deriveHashable_hashValue(DerivedConformance &derived) {
|
|||||||
getterDecl->setImplicit();
|
getterDecl->setImplicit();
|
||||||
getterDecl->setBodySynthesizer(&deriveBodyHashable_hashValue);
|
getterDecl->setBodySynthesizer(&deriveBodyHashable_hashValue);
|
||||||
|
|
||||||
// Compute the type of hashValue().
|
|
||||||
Type methodType = FunctionType::get(TupleType::getEmpty(C), intType);
|
|
||||||
|
|
||||||
// Compute the interface type of hashValue().
|
// Compute the interface type of hashValue().
|
||||||
Type interfaceType;
|
if (auto env = parentDC->getGenericEnvironmentOfContext())
|
||||||
auto selfParam = computeSelfParam(getterDecl);
|
getterDecl->setGenericEnvironment(env);
|
||||||
if (auto sig = parentDC->getGenericSignatureOfContext()) {
|
getterDecl->computeType();
|
||||||
getterDecl->setGenericEnvironment(parentDC->getGenericEnvironmentOfContext());
|
|
||||||
interfaceType = GenericFunctionType::get(sig, {selfParam}, methodType,
|
|
||||||
AnyFunctionType::ExtInfo());
|
|
||||||
} else
|
|
||||||
interfaceType = FunctionType::get({selfParam}, methodType,
|
|
||||||
AnyFunctionType::ExtInfo());
|
|
||||||
|
|
||||||
getterDecl->setInterfaceType(interfaceType);
|
|
||||||
getterDecl->setValidationToChecked();
|
getterDecl->setValidationToChecked();
|
||||||
getterDecl->copyFormalAccessFrom(derived.Nominal,
|
getterDecl->copyFormalAccessFrom(derived.Nominal,
|
||||||
/*sourceIsParentContext*/ true);
|
/*sourceIsParentContext*/ true);
|
||||||
|
|||||||
@@ -341,37 +341,11 @@ deriveRawRepresentable_init(DerivedConformance &derived) {
|
|||||||
initDecl->setImplicit();
|
initDecl->setImplicit();
|
||||||
initDecl->setBodySynthesizer(&deriveBodyRawRepresentable_init);
|
initDecl->setBodySynthesizer(&deriveBodyRawRepresentable_init);
|
||||||
|
|
||||||
// Compute the type of the initializer.
|
|
||||||
TupleTypeElt element(rawType, C.Id_rawValue);
|
|
||||||
TupleTypeElt interfaceElement(rawInterfaceType, C.Id_rawValue);
|
|
||||||
auto interfaceArgType = TupleType::get(interfaceElement, C);
|
|
||||||
|
|
||||||
// Compute the interface type of the initializer.
|
// Compute the interface type of the initializer.
|
||||||
Type retInterfaceType
|
if (auto env = parentDC->getGenericEnvironmentOfContext())
|
||||||
= OptionalType::get(parentDC->getDeclaredInterfaceType());
|
initDecl->setGenericEnvironment(env);
|
||||||
Type interfaceType = FunctionType::get(interfaceArgType, retInterfaceType);
|
initDecl->computeType();
|
||||||
auto selfParam = computeSelfParam(initDecl);
|
|
||||||
auto initSelfParam = computeSelfParam(initDecl, /*init*/ true);
|
|
||||||
|
|
||||||
Type allocIfaceType;
|
|
||||||
Type initIfaceType;
|
|
||||||
if (auto sig = parentDC->getGenericSignatureOfContext()) {
|
|
||||||
initDecl->setGenericEnvironment(parentDC->getGenericEnvironmentOfContext());
|
|
||||||
|
|
||||||
allocIfaceType = GenericFunctionType::get(sig, {selfParam},
|
|
||||||
interfaceType,
|
|
||||||
FunctionType::ExtInfo());
|
|
||||||
initIfaceType = GenericFunctionType::get(sig, {initSelfParam},
|
|
||||||
interfaceType,
|
|
||||||
FunctionType::ExtInfo());
|
|
||||||
} else {
|
|
||||||
allocIfaceType = FunctionType::get({selfParam},
|
|
||||||
interfaceType, FunctionType::ExtInfo());
|
|
||||||
initIfaceType = FunctionType::get({initSelfParam},
|
|
||||||
interfaceType, FunctionType::ExtInfo());
|
|
||||||
}
|
|
||||||
initDecl->setInterfaceType(allocIfaceType);
|
|
||||||
initDecl->setInitializerInterfaceType(initIfaceType);
|
|
||||||
initDecl->copyFormalAccessFrom(enumDecl, /*sourceIsParentContext*/true);
|
initDecl->copyFormalAccessFrom(enumDecl, /*sourceIsParentContext*/true);
|
||||||
initDecl->setValidationToChecked();
|
initDecl->setValidationToChecked();
|
||||||
|
|
||||||
|
|||||||
@@ -309,19 +309,10 @@ DerivedConformance::declareDerivedPropertyGetter(TypeChecker &tc,
|
|||||||
getterDecl->getAttrs().add(new (C) FinalAttr(/*IsImplicit=*/true));
|
getterDecl->getAttrs().add(new (C) FinalAttr(/*IsImplicit=*/true));
|
||||||
|
|
||||||
// Compute the interface type of the getter.
|
// Compute the interface type of the getter.
|
||||||
Type interfaceType = FunctionType::get(TupleType::getEmpty(C),
|
if (auto env = parentDC->getGenericEnvironmentOfContext())
|
||||||
propertyInterfaceType);
|
getterDecl->setGenericEnvironment(env);
|
||||||
auto selfParam = computeSelfParam(getterDecl);
|
getterDecl->computeType();
|
||||||
if (auto sig = parentDC->getGenericSignatureOfContext()) {
|
|
||||||
getterDecl->setGenericEnvironment(
|
|
||||||
parentDC->getGenericEnvironmentOfContext());
|
|
||||||
interfaceType = GenericFunctionType::get(sig, {selfParam},
|
|
||||||
interfaceType,
|
|
||||||
FunctionType::ExtInfo());
|
|
||||||
} else
|
|
||||||
interfaceType = FunctionType::get({selfParam}, interfaceType,
|
|
||||||
FunctionType::ExtInfo());
|
|
||||||
getterDecl->setInterfaceType(interfaceType);
|
|
||||||
getterDecl->copyFormalAccessFrom(property);
|
getterDecl->copyFormalAccessFrom(property);
|
||||||
getterDecl->setValidationToChecked();
|
getterDecl->setValidationToChecked();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user