@@ -364,11 +364,18 @@ static bool createsInfiniteSpecializationLoop(ApplySite Apply) {
364
364
// ReabstractionInfo
365
365
// =============================================================================
366
366
367
- static bool shouldNotSpecializeCallee (SILFunction *Callee,
368
- SubstitutionMap Subs = {}) {
367
+ static bool shouldNotSpecialize (SILFunction *Callee, SILFunction *Caller ,
368
+ SubstitutionMap Subs = {}) {
369
369
if (Callee->hasSemanticsAttr (" optimize.sil.specialize.generic.never" ))
370
370
return true ;
371
371
372
+ if (Caller &&
373
+ Caller->getEffectiveOptimizationMode () == OptimizationMode::ForSize &&
374
+ Callee->hasSemanticsAttr (" optimize.sil.specialize.generic.size.never" )) {
375
+ return true ;
376
+ }
377
+
378
+
372
379
if (Subs.hasAnySubstitutableParams () &&
373
380
Callee->hasSemanticsAttr (" optimize.sil.specialize.generic.partial.never" ))
374
381
return true ;
@@ -383,7 +390,7 @@ static bool shouldNotSpecializeCallee(SILFunction *Callee,
383
390
bool ReabstractionInfo::prepareAndCheck (ApplySite Apply, SILFunction *Callee,
384
391
SubstitutionMap ParamSubs,
385
392
OptRemark::Emitter *ORE) {
386
- if (shouldNotSpecializeCallee (Callee))
393
+ if (shouldNotSpecialize (Callee, Apply ? Apply. getFunction () : nullptr ))
387
394
return false ;
388
395
389
396
SpecializedGenericEnv = nullptr ;
@@ -489,7 +496,7 @@ bool ReabstractionInfo::prepareAndCheck(ApplySite Apply, SILFunction *Callee,
489
496
return false ;
490
497
491
498
// Bail if the callee should not be partially specialized.
492
- if (shouldNotSpecializeCallee (Callee, ParamSubs))
499
+ if (shouldNotSpecialize (Callee, Apply. getFunction () , ParamSubs))
493
500
return false ;
494
501
}
495
502
@@ -1763,7 +1770,7 @@ checkSpecializationRequirements(ArrayRef<Requirement> Requirements) {
1763
1770
// / This constructor is used when processing @_specialize.
1764
1771
ReabstractionInfo::ReabstractionInfo (SILFunction *Callee,
1765
1772
ArrayRef<Requirement> Requirements) {
1766
- if (shouldNotSpecializeCallee (Callee))
1773
+ if (shouldNotSpecialize (Callee, nullptr ))
1767
1774
return ;
1768
1775
1769
1776
// Perform some sanity checks for the requirements.
@@ -2281,7 +2288,7 @@ void swift::trySpecializeApplyOfGeneric(
2281
2288
if (F->isSerialized () && !RefF->hasValidLinkageForFragileInline ())
2282
2289
return ;
2283
2290
2284
- if (shouldNotSpecializeCallee (RefF))
2291
+ if (shouldNotSpecialize (RefF, F ))
2285
2292
return ;
2286
2293
2287
2294
// If the caller and callee are both fragile, preserve the fragility when
0 commit comments