Skip to content

Commit 3cab840

Browse files
committed
[Serialization] Serialize type of default expression
This type is going to be use to infer generic parameters at the call site.
1 parent cd61b35 commit 3cab840

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3197,13 +3197,15 @@ class DeclDeserializer {
31973197
bool isIsolated;
31983198
bool isCompileTimeConst;
31993199
uint8_t rawDefaultArg;
3200+
TypeID defaultExprType;
32003201

32013202
decls_block::ParamLayout::readRecord(scratch, argNameID, paramNameID,
32023203
contextID, rawSpecifier,
32033204
interfaceTypeID, isIUO, isVariadic,
32043205
isAutoClosure, isIsolated,
32053206
isCompileTimeConst,
3206-
rawDefaultArg);
3207+
rawDefaultArg,
3208+
defaultExprType);
32073209

32083210
auto argName = MF.getIdentifier(argNameID);
32093211
auto paramName = MF.getIdentifier(paramNameID);
@@ -3246,6 +3248,7 @@ class DeclDeserializer {
32463248
param->setDefaultArgumentKind(*defaultArg);
32473249
if (!blobData.empty())
32483250
param->setDefaultValueStringRepresentation(blobData);
3251+
// TODO: Set default expression type.
32493252
}
32503253
return param;
32513254
}

lib/Serialization/ModuleFormat.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5656
/// describe what change you made. The content of this comment isn't important;
5757
/// it just ensures a conflict if two people change the module format.
5858
/// Don't worry about adhering to the 80-column limit for this line.
59-
const uint16_t SWIFTMODULE_VERSION_MINOR = 671; // ParameterizedProtocolType with multiple arguments
59+
const uint16_t SWIFTMODULE_VERSION_MINOR = 672; // default expression type
6060

6161
/// A standard hash seed used for all string hashes in a serialized module.
6262
///
@@ -1376,6 +1376,7 @@ namespace decls_block {
13761376
BCFixed<1>, // isIsolated?
13771377
BCFixed<1>, // isCompileTimeConst?
13781378
DefaultArgumentField, // default argument kind
1379+
TypeIDField, // default argument type
13791380
BCBlob // default argument text
13801381
>;
13811382

lib/Serialization/Serialization.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3770,12 +3770,21 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
37703770
// any of the special ones.
37713771
StringRef defaultArgumentText;
37723772
SmallString<128> scratch;
3773+
// Type of the default expression.
3774+
Type defaultExprType;
3775+
37733776
swift::DefaultArgumentKind argKind = param->getDefaultArgumentKind();
37743777
if (argKind == swift::DefaultArgumentKind::Normal ||
3775-
argKind == swift::DefaultArgumentKind::StoredProperty)
3778+
argKind == swift::DefaultArgumentKind::StoredProperty) {
37763779
defaultArgumentText =
37773780
param->getDefaultValueStringRepresentation(scratch);
37783781

3782+
if (argKind == swift::DefaultArgumentKind::Normal) {
3783+
if (auto *defaultExpr = param->getTypeCheckedDefaultExpr())
3784+
defaultExprType = defaultExpr->getType();
3785+
}
3786+
}
3787+
37793788
unsigned abbrCode = S.DeclTypeAbbrCodes[ParamLayout::Code];
37803789
ParamLayout::emitRecord(S.Out, S.ScratchRecord, abbrCode,
37813790
S.addDeclBaseNameRef(param->getArgumentName()),
@@ -3789,6 +3798,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
37893798
param->isIsolated(),
37903799
param->isCompileTimeConst(),
37913800
getRawStableDefaultArgumentKind(argKind),
3801+
S.addTypeRef(defaultExprType),
37923802
defaultArgumentText);
37933803

37943804
if (interfaceType->hasError() && !S.allowCompilerErrors()) {

0 commit comments

Comments
 (0)