mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Function builders] Add support for function builders on stored struct properties.
Implements SR-13188, which is part of the function builders proposal under review.
This commit is contained in:
@@ -261,6 +261,20 @@ static ConstructorDecl *createImplicitConstructor(NominalTypeDecl *decl,
|
||||
}
|
||||
}
|
||||
|
||||
Type functionBuilderType= var->getFunctionBuilderType();
|
||||
if (functionBuilderType) {
|
||||
// If the variable's type is structurally a function type, use that
|
||||
// type. Otherwise, form a non-escaping function type for the function
|
||||
// parameter.
|
||||
bool isStructuralFunctionType =
|
||||
varInterfaceType->lookThroughAllOptionalTypes()
|
||||
->is<AnyFunctionType>();
|
||||
if (!isStructuralFunctionType) {
|
||||
auto extInfo = ASTExtInfoBuilder().withNoEscape().build();
|
||||
varInterfaceType = FunctionType::get({ }, varInterfaceType, extInfo);
|
||||
}
|
||||
}
|
||||
|
||||
// Create the parameter.
|
||||
auto *arg = new (ctx)
|
||||
ParamDecl(SourceLoc(), Loc,
|
||||
@@ -273,6 +287,14 @@ static ConstructorDecl *createImplicitConstructor(NominalTypeDecl *decl,
|
||||
// Don't allow the parameter to accept temporary pointer conversions.
|
||||
arg->setNonEphemeralIfPossible();
|
||||
|
||||
// Attach a function builder attribute if needed.
|
||||
if (functionBuilderType) {
|
||||
auto typeExpr = TypeExpr::createImplicit(functionBuilderType, ctx);
|
||||
auto attr = CustomAttr::create(
|
||||
ctx, SourceLoc(), typeExpr, /*implicit=*/true);
|
||||
arg->getAttrs().add(attr);
|
||||
}
|
||||
|
||||
maybeAddMemberwiseDefaultArg(arg, var, params.size(), ctx);
|
||||
|
||||
params.push_back(arg);
|
||||
|
||||
Reference in New Issue
Block a user