@@ -677,6 +677,39 @@ bool SILGenModule::hasFunction(SILDeclRef constant) {
677677void SILGenModule::visitFuncDecl (FuncDecl *fd) { emitFunction (fd); }
678678
679679void SILGenModule::emitFunctionDefinition (SILDeclRef constant, SILFunction *f) {
680+
681+ if (constant.isForeignToNativeThunk ()) {
682+ f->setThunk (IsThunk);
683+ if (constant.asForeign ().isClangGenerated ())
684+ f->setSerialized (IsSerializable);
685+
686+ auto loc = constant.getAsRegularLocation ();
687+ loc.markAutoGenerated ();
688+ auto *dc = loc.getAsDeclContext ();
689+ assert (dc);
690+
691+ preEmitFunction (constant, f, loc);
692+ PrettyStackTraceSILFunction X (" silgen emitForeignToNativeThunk" , f);
693+ SILGenFunction (*this , *f, dc).emitForeignToNativeThunk (constant);
694+ postEmitFunction (constant, f);
695+ return ;
696+ }
697+
698+ if (constant.isNativeToForeignThunk ()) {
699+ auto loc = constant.getAsRegularLocation ();
700+ loc.markAutoGenerated ();
701+ auto *dc = loc.getAsDeclContext ();
702+ assert (dc);
703+
704+ preEmitFunction (constant, f, loc);
705+ PrettyStackTraceSILFunction X (" silgen emitNativeToForeignThunk" , f);
706+ f->setBare (IsBare);
707+ f->setThunk (IsThunk);
708+ SILGenFunction (*this , *f, dc).emitNativeToForeignThunk (constant);
709+ postEmitFunction (constant, f);
710+ return ;
711+ }
712+
680713 switch (constant.kind ) {
681714 case SILDeclRef::Kind::Func: {
682715 if (auto *ce = constant.getAbstractClosureExpr ()) {
@@ -1412,14 +1445,7 @@ void SILGenModule::emitObjCMethodThunk(FuncDecl *method) {
14121445 return ;
14131446
14141447 // ObjC entry points are always externally usable, so can't be delay-emitted.
1415-
1416- SILFunction *f = getFunction (thunk, ForDefinition);
1417- preEmitFunction (thunk, f, method);
1418- PrettyStackTraceSILFunction X (" silgen emitObjCMethodThunk" , f);
1419- f->setBare (IsBare);
1420- f->setThunk (IsThunk);
1421- SILGenFunction (*this , *f, method).emitNativeToForeignThunk (thunk);
1422- postEmitFunction (thunk, f);
1448+ emitNativeToForeignThunk (thunk);
14231449}
14241450
14251451void SILGenModule::emitObjCPropertyMethodThunks (AbstractStorageDecl *prop) {
@@ -1435,33 +1461,17 @@ void SILGenModule::emitObjCPropertyMethodThunks(AbstractStorageDecl *prop) {
14351461 if (hasFunction (getterRef))
14361462 return ;
14371463
1438- auto thunkBodyLoc = RegularLocation::getAutoGeneratedLocation (prop);
14391464 // ObjC entry points are always externally usable, so emitting can't be
14401465 // delayed.
1441- {
1442- SILFunction *f = getFunction (getterRef, ForDefinition);
1443- preEmitFunction (getterRef, f, thunkBodyLoc);
1444- PrettyStackTraceSILFunction X (" silgen objc property getter thunk" , f);
1445- f->setBare (IsBare);
1446- f->setThunk (IsThunk);
1447- SILGenFunction (*this , *f, getter).emitNativeToForeignThunk (getterRef);
1448- postEmitFunction (getterRef, f);
1449- }
1466+ emitNativeToForeignThunk (getterRef);
14501467
14511468 if (!prop->isSettable (prop->getDeclContext ()))
14521469 return ;
14531470
14541471 // FIXME: Add proper location.
14551472 auto *setter = prop->getOpaqueAccessor (AccessorKind::Set);
14561473 auto setterRef = SILDeclRef (setter, SILDeclRef::Kind::Func).asForeign ();
1457-
1458- SILFunction *f = getFunction (setterRef, ForDefinition);
1459- preEmitFunction (setterRef, f, thunkBodyLoc);
1460- PrettyStackTraceSILFunction X (" silgen objc property setter thunk" , f);
1461- f->setBare (IsBare);
1462- f->setThunk (IsThunk);
1463- SILGenFunction (*this , *f, setter).emitNativeToForeignThunk (setterRef);
1464- postEmitFunction (setterRef, f);
1474+ emitNativeToForeignThunk (setterRef);
14651475}
14661476
14671477void SILGenModule::emitObjCConstructorThunk (ConstructorDecl *constructor) {
@@ -1473,15 +1483,7 @@ void SILGenModule::emitObjCConstructorThunk(ConstructorDecl *constructor) {
14731483 return ;
14741484 // ObjC entry points are always externally usable, so emitting can't be
14751485 // delayed.
1476-
1477- SILFunction *f = getFunction (thunk, ForDefinition);
1478- auto loc = RegularLocation::getAutoGeneratedLocation (constructor);
1479- preEmitFunction (thunk, f, loc);
1480- PrettyStackTraceSILFunction X (" silgen objc constructor thunk" , f);
1481- f->setBare (IsBare);
1482- f->setThunk (IsThunk);
1483- SILGenFunction (*this , *f, constructor).emitNativeToForeignThunk (thunk);
1484- postEmitFunction (thunk, f);
1486+ emitNativeToForeignThunk (thunk);
14851487}
14861488
14871489void SILGenModule::emitObjCDestructorThunk (DestructorDecl *destructor) {
@@ -1491,14 +1493,8 @@ void SILGenModule::emitObjCDestructorThunk(DestructorDecl *destructor) {
14911493 // Don't emit the thunk if it already exists.
14921494 if (hasFunction (thunk))
14931495 return ;
1494- SILFunction *f = getFunction (thunk, ForDefinition);
1495- auto loc = RegularLocation::getAutoGeneratedLocation (destructor);
1496- preEmitFunction (thunk, destructor, f, loc);
1497- PrettyStackTraceSILFunction X (" silgen objc destructor thunk" , f);
1498- f->setBare (IsBare);
1499- f->setThunk (IsThunk);
1500- SILGenFunction (*this , *f, destructor).emitNativeToForeignThunk (thunk);
1501- postEmitFunction (thunk, f);
1496+
1497+ emitNativeToForeignThunk (thunk);
15021498}
15031499
15041500void SILGenModule::visitPatternBindingDecl (PatternBindingDecl *pd) {
0 commit comments