Skip to content

Commit 36a3c6e

Browse files
Merge pull request #85644 from aschwaighofer/wip_embedded_exits_with_eriks_changes_v1
[embedded] Fix associated type conformances for specialized witness tables
2 parents 61fc635 + a71e3d9 commit 36a3c6e

File tree

20 files changed

+517
-9
lines changed

20 files changed

+517
-9
lines changed

SwiftCompilerSources/Sources/AST/Declarations.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ final public class ClassDecl: NominalTypeDecl {
134134

135135
final public class ProtocolDecl: NominalTypeDecl {
136136
public var requiresClass: Bool { bridged.ProtocolDecl_requiresClass() }
137+
public var isMarkerProtocol: Bool { bridged.ProtocolDecl_isMarkerProtocol() }
137138
}
138139

139140
final public class BuiltinTupleDecl: NominalTypeDecl {}

SwiftCompilerSources/Sources/Optimizer/ModulePasses/MandatoryPerformanceOptimizations.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ private func optimize(function: Function, _ context: FunctionPassContext, _ modu
143143
}
144144
}
145145

146+
case let initExAddr as InitExistentialAddrInst:
147+
if context.options.enableEmbeddedSwift {
148+
for c in initExAddr.conformances where c.isConcrete && !c.protocol.isMarkerProtocol {
149+
specializeWitnessTable(for: c, moduleContext)
150+
worklist.addWitnessMethods(of: c, moduleContext)
151+
}
152+
}
153+
146154
case let bi as BuiltinInst:
147155
switch bi.id {
148156
case .BuildOrdinaryTaskExecutorRef,

SwiftCompilerSources/Sources/Optimizer/Utilities/GenericSpecialization.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func specializeWitnessTable(for conformance: Conformance, _ context: ModulePassC
151151
guard !methodSubs.conformances.contains(where: {!$0.isValid}),
152152
context.loadFunction(function: origMethod, loadCalleesRecursively: true),
153153
let specializedMethod = context.specialize(function: origMethod, for: methodSubs,
154-
convertIndirectToDirect: true, isMandatory: true)
154+
convertIndirectToDirect: false, isMandatory: true)
155155
else {
156156
return origEntry
157157
}
@@ -218,7 +218,7 @@ private func specializeDefaultMethods(for conformance: Conformance,
218218
guard !methodSubs.conformances.contains(where: {!$0.isValid}),
219219
context.loadFunction(function: origMethod, loadCalleesRecursively: true),
220220
let specializedMethod = context.specialize(function: origMethod, for: methodSubs,
221-
convertIndirectToDirect: true, isMandatory: true)
221+
convertIndirectToDirect: false, isMandatory: true)
222222
else {
223223
return origEntry
224224
}

SwiftCompilerSources/Sources/Optimizer/Utilities/OptUtils.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,8 @@ func isCastSupportedInEmbeddedSwift(from sourceType: Type,
10561056
return false
10571057
}
10581058

1059-
if !destType.isStruct && !destType.isClass && !destType.isEnum && !destType.isTuple {
1059+
if !destType.isStruct && !destType.isClass && !destType.isEnum &&
1060+
!destType.isTuple && !destType.isLoweredFunction {
10601061
return false
10611062
}
10621063

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,10 @@ class InitExistentialAddrInst : SingleValueInstruction, UnaryInstruction {
925925
public var conformances: ConformanceArray {
926926
ConformanceArray(bridged: bridged.InitExistentialAddrInst_getConformances())
927927
}
928+
929+
public var formalConcreteType: CanonicalType {
930+
CanonicalType(bridged: bridged.InitExistentialAddrInst_getFormalConcreteType())
931+
}
928932
}
929933

930934
final public

include/swift/AST/ASTBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ struct BridgedDeclObj {
348348
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedDeclObj Class_getDestructor() const;
349349
BRIDGED_INLINE bool Class_isForeign() const;
350350
BRIDGED_INLINE bool ProtocolDecl_requiresClass() const;
351+
BRIDGED_INLINE bool ProtocolDecl_isMarkerProtocol() const;
351352
BRIDGED_INLINE bool AbstractFunction_isOverridden() const;
352353
BRIDGED_INLINE bool Destructor_isIsolated() const;
353354
BRIDGED_INLINE bool EnumElementDecl_hasAssociatedValues() const;

include/swift/AST/ASTBridgingImpl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ bool BridgedDeclObj::ProtocolDecl_requiresClass() const {
264264
return getAs<swift::ProtocolDecl>()->requiresClass();
265265
}
266266

267+
bool BridgedDeclObj::ProtocolDecl_isMarkerProtocol() const {
268+
return getAs<swift::ProtocolDecl>()->isMarkerProtocol();
269+
}
270+
267271
bool BridgedDeclObj::AbstractFunction_isOverridden() const {
268272
return getAs<swift::AbstractFunctionDecl>()->isOverridden();
269273
}

include/swift/SIL/SILBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,7 @@ struct BridgedInstruction {
809809
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedConformanceArray InitExistentialRefInst_getConformances() const;
810810
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedCanType InitExistentialRefInst_getFormalConcreteType() const;
811811
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedConformanceArray InitExistentialAddrInst_getConformances() const;
812+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedCanType InitExistentialAddrInst_getFormalConcreteType() const;
812813
BRIDGED_INLINE bool OpenExistentialAddr_isImmutable() const;
813814
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedGlobalVar GlobalAccessInst_getGlobal() const;
814815
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedGlobalVar AllocGlobalInst_getGlobal() const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,11 @@ BridgedCanType BridgedInstruction::InitExistentialRefInst_getFormalConcreteType(
12921292
BridgedConformanceArray BridgedInstruction::InitExistentialAddrInst_getConformances() const {
12931293
return {getAs<swift::InitExistentialAddrInst>()->getConformances()};
12941294
}
1295+
1296+
BridgedCanType BridgedInstruction::InitExistentialAddrInst_getFormalConcreteType() const {
1297+
return getAs<swift::InitExistentialAddrInst>()->getFormalConcreteType();
1298+
}
1299+
12951300
bool BridgedInstruction::OpenExistentialAddr_isImmutable() const {
12961301
switch (getAs<swift::OpenExistentialAddrInst>()->getAccessKind()) {
12971302
case swift::OpenedExistentialAccess::Immutable: return true;

include/swift/SILOptimizer/Utils/Generics.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,9 @@ class ReabstractionInfo {
216216

217217
ReabstractionInfo(CanSILFunctionType substitutedType,
218218
SILDeclRef methodDecl,
219+
bool convertIndirectToDirect,
219220
SILModule &M) :
221+
ConvertIndirectToDirect(convertIndirectToDirect),
220222
SubstitutedType(substitutedType),
221223
methodDecl(methodDecl),
222224
M(&M), isWholeModule(M.isWholeModule()) {}

0 commit comments

Comments
 (0)