@@ -1060,16 +1060,39 @@ void SILGenModule::emitDestructor(ClassDecl *cd, DestructorDecl *dd) {
10601060 }
10611061}
10621062
1063- void SILGenModule::emitDefaultArgGenerator (SILDeclRef constant, Expr *arg,
1064- DefaultArgumentKind kind,
1065- DeclContext *initDC) {
1066- switch (kind) {
1063+ void SILGenModule::emitDefaultArgGenerator (SILDeclRef constant,
1064+ ParamDecl *param) {
1065+ auto initDC = param->getDefaultArgumentInitContext ();
1066+
1067+ switch (param->getDefaultArgumentKind ()) {
10671068 case DefaultArgumentKind::None:
10681069 llvm_unreachable (" No default argument here?" );
10691070
1070- case DefaultArgumentKind::Normal:
1071- case DefaultArgumentKind::StoredProperty:
1072- break ;
1071+ case DefaultArgumentKind::Normal: {
1072+ auto arg = param->getDefaultValue ();
1073+ emitOrDelayFunction (*this , constant,
1074+ [this ,constant,arg,initDC](SILFunction *f) {
1075+ preEmitFunction (constant, arg, f, arg);
1076+ PrettyStackTraceSILFunction X (" silgen emitDefaultArgGenerator " , f);
1077+ SILGenFunction SGF (*this , *f, initDC);
1078+ SGF.emitGeneratorFunction (constant, arg);
1079+ postEmitFunction (constant, f);
1080+ });
1081+ return ;
1082+ }
1083+
1084+ case DefaultArgumentKind::StoredProperty: {
1085+ auto arg = param->getStoredProperty ();
1086+ emitOrDelayFunction (*this , constant,
1087+ [this ,constant,arg,initDC](SILFunction *f) {
1088+ preEmitFunction (constant, arg, f, arg);
1089+ PrettyStackTraceSILFunction X (" silgen emitDefaultArgGenerator " , f);
1090+ SILGenFunction SGF (*this , *f, initDC);
1091+ SGF.emitGeneratorFunction (constant, arg);
1092+ postEmitFunction (constant, f);
1093+ });
1094+ return ;
1095+ }
10731096
10741097 case DefaultArgumentKind::Inherited:
10751098 case DefaultArgumentKind::Column:
@@ -1082,15 +1105,6 @@ void SILGenModule::emitDefaultArgGenerator(SILDeclRef constant, Expr *arg,
10821105 case DefaultArgumentKind::EmptyDictionary:
10831106 return ;
10841107 }
1085-
1086- emitOrDelayFunction (*this , constant,
1087- [this ,constant,arg,initDC](SILFunction *f) {
1088- preEmitFunction (constant, arg, f, arg);
1089- PrettyStackTraceSILFunction X (" silgen emitDefaultArgGenerator " , f);
1090- SILGenFunction SGF (*this , *f, initDC);
1091- SGF.emitGeneratorFunction (constant, arg);
1092- postEmitFunction (constant, f);
1093- });
10941108}
10951109
10961110void SILGenModule::
@@ -1159,15 +1173,9 @@ void SILGenModule::emitDefaultArgGenerators(SILDeclRef::Loc decl,
11591173 ParameterList *paramList) {
11601174 unsigned index = 0 ;
11611175 for (auto param : *paramList) {
1162- auto defaultArg = param->getDefaultValue ();
1163-
1164- if (auto var = param->getStoredProperty ())
1165- defaultArg = var->getParentInitializer ();
1166-
1167- if (defaultArg)
1176+ if (param->isDefaultArgument ())
11681177 emitDefaultArgGenerator (SILDeclRef::getDefaultArgGenerator (decl, index),
1169- defaultArg, param->getDefaultArgumentKind (),
1170- param->getDefaultArgumentInitContext ());
1178+ param);
11711179 ++index;
11721180 }
11731181}
0 commit comments