@@ -677,6 +677,39 @@ bool SILGenModule::hasFunction(SILDeclRef constant) {
677
677
void SILGenModule::visitFuncDecl (FuncDecl *fd) { emitFunction (fd); }
678
678
679
679
void 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
+
680
713
switch (constant.kind ) {
681
714
case SILDeclRef::Kind::Func: {
682
715
if (auto *ce = constant.getAbstractClosureExpr ()) {
@@ -1412,14 +1445,7 @@ void SILGenModule::emitObjCMethodThunk(FuncDecl *method) {
1412
1445
return ;
1413
1446
1414
1447
// 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);
1423
1449
}
1424
1450
1425
1451
void SILGenModule::emitObjCPropertyMethodThunks (AbstractStorageDecl *prop) {
@@ -1435,33 +1461,17 @@ void SILGenModule::emitObjCPropertyMethodThunks(AbstractStorageDecl *prop) {
1435
1461
if (hasFunction (getterRef))
1436
1462
return ;
1437
1463
1438
- auto thunkBodyLoc = RegularLocation::getAutoGeneratedLocation (prop);
1439
1464
// ObjC entry points are always externally usable, so emitting can't be
1440
1465
// 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);
1450
1467
1451
1468
if (!prop->isSettable (prop->getDeclContext ()))
1452
1469
return ;
1453
1470
1454
1471
// FIXME: Add proper location.
1455
1472
auto *setter = prop->getOpaqueAccessor (AccessorKind::Set);
1456
1473
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);
1465
1475
}
1466
1476
1467
1477
void SILGenModule::emitObjCConstructorThunk (ConstructorDecl *constructor) {
@@ -1473,15 +1483,7 @@ void SILGenModule::emitObjCConstructorThunk(ConstructorDecl *constructor) {
1473
1483
return ;
1474
1484
// ObjC entry points are always externally usable, so emitting can't be
1475
1485
// 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);
1485
1487
}
1486
1488
1487
1489
void SILGenModule::emitObjCDestructorThunk (DestructorDecl *destructor) {
@@ -1491,14 +1493,8 @@ void SILGenModule::emitObjCDestructorThunk(DestructorDecl *destructor) {
1491
1493
// Don't emit the thunk if it already exists.
1492
1494
if (hasFunction (thunk))
1493
1495
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);
1502
1498
}
1503
1499
1504
1500
void SILGenModule::visitPatternBindingDecl (PatternBindingDecl *pd) {
0 commit comments