Skip to content

Start using best resilience expansion in SIL #23286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/SILGen/SILGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,9 +956,8 @@ bool SILGenModule::hasNonTrivialIVars(ClassDecl *cd) {
auto *vd = dyn_cast<VarDecl>(member);
if (!vd || !vd->hasStorage()) continue;

// FIXME: Expansion
auto &ti = Types.getTypeLowering(vd->getType(),
ResilienceExpansion::Minimal);
ResilienceExpansion::Maximal);
if (!ti.isTrivial())
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/SILGen/SILGenExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3313,6 +3313,7 @@ lowerKeyPathSubscriptIndexTypes(
SmallVectorImpl<IndexTypePair> &indexPatterns,
SubscriptDecl *subscript,
SubstitutionMap subscriptSubs,
ResilienceExpansion expansion,
bool &needsGenericContext) {
// Capturing an index value dependent on the generic context means we
// need the generic context captured in the key path.
Expand All @@ -3330,11 +3331,9 @@ lowerKeyPathSubscriptIndexTypes(
indexTy = indexTy.subst(subscriptSubs);
}

// FIXME: Expansion
auto indexLoweredTy = SGM.Types.getLoweredType(
AbstractionPattern::getOpaque(),
indexTy,
ResilienceExpansion::Minimal);
indexTy, expansion);
indexLoweredTy = indexLoweredTy.mapTypeOutOfContext();
indexPatterns.push_back({indexTy->mapTypeOutOfContext()
->getCanonicalType(),
Expand Down Expand Up @@ -3531,6 +3530,7 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
SmallVector<IndexTypePair, 4> indexTypes;
lowerKeyPathSubscriptIndexTypes(*this, indexTypes,
decl, subs,
expansion,
needsGenericContext);

SmallVector<KeyPathPatternComponent::Index, 4> indexPatterns;
Expand Down
39 changes: 39 additions & 0 deletions test/SILGen/ivar_destroyer_resilience.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -enable-resilience -emit-module-path=%t/resilient_struct.swiftmodule -enable-sil-ownership %S/../Inputs/resilient_struct.swift
// RUN: %target-swift-emit-silgen -I %t -enable-sil-ownership -enable-resilience %s | %FileCheck %s

import resilient_struct

public class Base {}

public struct MyResilientInt {
var i: Int

public init(i: Int) { self.i = i }
}

public class NeedsIVarDetroyer : Base {
var x = ResilientInt(i: 0)
}

public class DoesNotNeedIVarDestroyer : Base {
var x = MyResilientInt(i: 0)
}

// CHECK-LABEL: sil_vtable NeedsIVarDetroyer {
// CHECK-NEXT: #Base.init!allocator.1: (Base.Type) -> () -> Base
// CHECK-NEXT: #NeedsIVarDetroyer.x!getter.1: (NeedsIVarDetroyer) -> () -> resilient_struct.ResilientInt
// CHECK-NEXT: #NeedsIVarDetroyer.x!setter.1: (NeedsIVarDetroyer) -> (resilient_struct.ResilientInt) -> ()
// CHECK-NEXT: #NeedsIVarDetroyer.x!modify.1: (NeedsIVarDetroyer) -> () -> ()
// CHECK-NEXT: #NeedsIVarDetroyer.deinit!deallocator.1
// CHECK-NEXT: #NeedsIVarDetroyer!ivardestroyer.1
// CHECK-NEXT: }

// CHECK-LABEL: sil_vtable DoesNotNeedIVarDestroyer {
// CHECK-NEXT: #Base.init!allocator.1: (Base.Type) -> () -> Base
// CHECK-NEXT: #DoesNotNeedIVarDestroyer.x!getter.1: (DoesNotNeedIVarDestroyer) -> () -> MyResilientInt
// CHECK-NEXT: #DoesNotNeedIVarDestroyer.x!setter.1: (DoesNotNeedIVarDestroyer) -> (MyResilientInt) -> ()
// CHECK-NEXT: #DoesNotNeedIVarDestroyer.x!modify.1: (DoesNotNeedIVarDestroyer) -> () -> ()
// CHECK-NEXT: #DoesNotNeedIVarDestroyer.deinit!deallocator.1
// CHECK-NEXT: }