@@ -2440,14 +2440,14 @@ TypeConverter::checkForABIDifferences(SILModule &M,
2440
2440
// If the types are identical and there was no optionality change,
2441
2441
// we're done.
2442
2442
if (type1 == type2 && !optionalityChange)
2443
- return ABIDifference::Trivial ;
2443
+ return ABIDifference::CompatibleRepresentation ;
2444
2444
2445
2445
// Classes, class-constrained archetypes, and pure-ObjC existential types
2446
2446
// all have single retainable pointer representation; optionality change
2447
2447
// is allowed.
2448
2448
if (type1.getASTType ()->satisfiesClassConstraint () &&
2449
2449
type2.getASTType ()->satisfiesClassConstraint ())
2450
- return ABIDifference::Trivial ;
2450
+ return ABIDifference::CompatibleRepresentation ;
2451
2451
2452
2452
// Function parameters are ABI compatible if their differences are
2453
2453
// trivial.
@@ -2470,7 +2470,7 @@ TypeConverter::checkForABIDifferences(SILModule &M,
2470
2470
if (meta1->getRepresentation () == meta2->getRepresentation () &&
2471
2471
(!optionalityChange ||
2472
2472
meta1->getRepresentation () == MetatypeRepresentation::Thick))
2473
- return ABIDifference::Trivial ;
2473
+ return ABIDifference::CompatibleRepresentation ;
2474
2474
}
2475
2475
}
2476
2476
@@ -2483,7 +2483,7 @@ TypeConverter::checkForABIDifferences(SILModule &M,
2483
2483
if (auto meta2 = type2.getAs <ExistentialMetatypeType>()) {
2484
2484
if (meta1->getRepresentation () == meta2->getRepresentation () &&
2485
2485
meta1->getRepresentation () == MetatypeRepresentation::ObjC)
2486
- return ABIDifference::Trivial ;
2486
+ return ABIDifference::CompatibleRepresentation ;
2487
2487
}
2488
2488
}
2489
2489
@@ -2498,12 +2498,12 @@ TypeConverter::checkForABIDifferences(SILModule &M,
2498
2498
if (checkForABIDifferences (M,
2499
2499
type1.getTupleElementType (i),
2500
2500
type2.getTupleElementType (i))
2501
- != ABIDifference::Trivial )
2501
+ != ABIDifference::CompatibleRepresentation )
2502
2502
return ABIDifference::NeedsThunk;
2503
2503
}
2504
2504
2505
2505
// Tuple lengths and elements match
2506
- return ABIDifference::Trivial ;
2506
+ return ABIDifference::CompatibleRepresentation ;
2507
2507
}
2508
2508
}
2509
2509
}
@@ -2517,10 +2517,19 @@ TypeConverter::ABIDifference
2517
2517
TypeConverter::checkFunctionForABIDifferences (SILModule &M,
2518
2518
SILFunctionType *fnTy1,
2519
2519
SILFunctionType *fnTy2) {
2520
+ // For now, only differentiate representation from calling convention when
2521
+ // staging in substituted function types.
2522
+ //
2523
+ // We might still want to conditionalize this behavior even after we commit
2524
+ // substituted function types, to avoid bloating
2525
+ // IR for platforms that don't differentiate function type representations.
2526
+ bool DifferentFunctionTypesHaveDifferentRepresentation
2527
+ = Context.LangOpts .EnableSubstSILFunctionTypesForFunctionValues ;
2528
+
2520
2529
// Fast path -- if both functions were unwrapped from a CanSILFunctionType,
2521
2530
// we might have pointer equality here.
2522
2531
if (fnTy1 == fnTy2)
2523
- return ABIDifference::Trivial ;
2532
+ return ABIDifference::CompatibleRepresentation ;
2524
2533
2525
2534
if (fnTy1->getParameters ().size () != fnTy2->getParameters ().size ())
2526
2535
return ABIDifference::NeedsThunk;
@@ -2548,7 +2557,7 @@ TypeConverter::checkFunctionForABIDifferences(SILModule &M,
2548
2557
result1.getSILStorageType (M, fnTy1),
2549
2558
result2.getSILStorageType (M, fnTy2),
2550
2559
/* thunk iuos*/ fnTy1->getLanguage () == SILFunctionLanguage::Swift)
2551
- != ABIDifference::Trivial )
2560
+ != ABIDifference::CompatibleRepresentation )
2552
2561
return ABIDifference::NeedsThunk;
2553
2562
}
2554
2563
@@ -2563,7 +2572,7 @@ TypeConverter::checkFunctionForABIDifferences(SILModule &M,
2563
2572
yield1.getSILStorageType (M, fnTy1),
2564
2573
yield2.getSILStorageType (M, fnTy2),
2565
2574
/* thunk iuos*/ fnTy1->getLanguage () == SILFunctionLanguage::Swift)
2566
- != ABIDifference::Trivial )
2575
+ != ABIDifference::CompatibleRepresentation )
2567
2576
return ABIDifference::NeedsThunk;
2568
2577
}
2569
2578
@@ -2580,7 +2589,7 @@ TypeConverter::checkFunctionForABIDifferences(SILModule &M,
2580
2589
error1.getSILStorageType (M, fnTy1),
2581
2590
error2.getSILStorageType (M, fnTy2),
2582
2591
/* thunk iuos*/ fnTy1->getLanguage () == SILFunctionLanguage::Swift)
2583
- != ABIDifference::Trivial )
2592
+ != ABIDifference::CompatibleRepresentation )
2584
2593
return ABIDifference::NeedsThunk;
2585
2594
}
2586
2595
@@ -2592,26 +2601,34 @@ TypeConverter::checkFunctionForABIDifferences(SILModule &M,
2592
2601
2593
2602
// Parameters are contravariant and our relation is not symmetric, so
2594
2603
// make sure to flip the relation around.
2595
- std::swap (param1, param2);
2596
-
2597
2604
if (checkForABIDifferences (M,
2598
- param1.getSILStorageType (M, fnTy1),
2599
2605
param2.getSILStorageType (M, fnTy2),
2606
+ param1.getSILStorageType (M, fnTy1),
2600
2607
/* thunk iuos*/ fnTy1->getLanguage () == SILFunctionLanguage::Swift)
2601
- != ABIDifference::Trivial )
2608
+ != ABIDifference::CompatibleRepresentation )
2602
2609
return ABIDifference::NeedsThunk;
2603
2610
}
2604
2611
2605
2612
auto rep1 = fnTy1->getRepresentation (), rep2 = fnTy2->getRepresentation ();
2606
2613
if (rep1 != rep2) {
2607
2614
if (rep1 == SILFunctionTypeRepresentation::Thin &&
2608
- rep2 == SILFunctionTypeRepresentation::Thick)
2609
- return ABIDifference::ThinToThick;
2615
+ rep2 == SILFunctionTypeRepresentation::Thick) {
2616
+ if (DifferentFunctionTypesHaveDifferentRepresentation) {
2617
+ // FIXME: check whether the representations are compatible modulo
2618
+ // context
2619
+ return ABIDifference::CompatibleCallingConvention_ThinToThick;
2620
+ } else {
2621
+ return ABIDifference::CompatibleRepresentation_ThinToThick;
2622
+ }
2623
+ }
2610
2624
2611
2625
return ABIDifference::NeedsThunk;
2612
2626
}
2613
2627
2614
- return ABIDifference::Trivial;
2628
+ if (DifferentFunctionTypesHaveDifferentRepresentation)
2629
+ return ABIDifference::CompatibleCallingConvention;
2630
+ else
2631
+ return ABIDifference::CompatibleRepresentation;
2615
2632
}
2616
2633
2617
2634
CanSILBoxType
0 commit comments