Skip to content

Commit 67556cf

Browse files
committed
SIL: add some Function APIs
* `var wasDeserializedCanonical` * `var genericSignature` * `func mapTypeIntoContext` * `var forwardingSubstitutionMap`
1 parent 59ad8b6 commit 67556cf

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

SwiftCompilerSources/Sources/AST/Type.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public struct Type: TypeProperties, CustomStringConvertible, NoReflectionChildre
4040
self.bridged = bridgedOrNil
4141
}
4242

43-
init(bridged: BridgedASTType) {
43+
public init(bridged: BridgedASTType) {
4444
self.bridged = bridged
4545
}
4646

SwiftCompilerSources/Sources/SIL/Function.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ final public class Function : CustomStringConvertible, HasShortDescription, Hash
3636
hasher.combine(ObjectIdentifier(self))
3737
}
3838

39+
public var wasDeserializedCanonical: Bool { bridged.wasDeserializedCanonical() }
40+
3941
public var isTrapNoReturn: Bool { bridged.isTrapNoReturn() }
4042

4143
public var isAutodiffVJP: Bool { bridged.isAutodiffVJP() }
@@ -61,6 +63,18 @@ final public class Function : CustomStringConvertible, HasShortDescription, Hash
6163
CanonicalType(bridged: bridged.getLoweredFunctionTypeInContext())
6264
}
6365

66+
public var genericSignature: GenericSignature {
67+
GenericSignature(bridged: bridged.getGenericSignature())
68+
}
69+
70+
public var forwardingSubstitutionMap: SubstitutionMap {
71+
SubstitutionMap(bridged: bridged.getForwardingSubstitutionMap())
72+
}
73+
74+
public func mapTypeIntoContext(_ type: AST.`Type`) -> AST.`Type` {
75+
return AST.`Type`(bridged: bridged.mapTypeIntoContext(type.bridged))
76+
}
77+
6478
/// Returns true if the function is a definition and not only an external declaration.
6579
///
6680
/// This is the case if the functioun contains a body, i.e. some basic blocks.

include/swift/SIL/SILBridging.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,9 @@ struct BridgedFunction {
462462
BRIDGED_INLINE bool hasOwnership() const;
463463
BRIDGED_INLINE bool hasLoweredAddresses() const;
464464
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedCanType getLoweredFunctionTypeInContext() const;
465+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedGenericSignature getGenericSignature() const;
466+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedSubstitutionMap getForwardingSubstitutionMap() const;
467+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType mapTypeIntoContext(BridgedASTType ty) const;
465468
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedBasicBlock getFirstBlock() const;
466469
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedBasicBlock getLastBlock() const;
467470
BRIDGED_INLINE SwiftInt getNumIndirectFormalResults() const;
@@ -491,6 +494,7 @@ struct BridgedFunction {
491494
BRIDGED_INLINE ThunkKind isThunk() const;
492495
BRIDGED_INLINE void setThunk(ThunkKind) const;
493496
BRIDGED_INLINE bool needsStackProtection() const;
497+
BRIDGED_INLINE bool wasDeserializedCanonical() const;
494498
BRIDGED_INLINE void setNeedStackProtection(bool needSP) const;
495499
BRIDGED_INLINE void setIsPerformanceConstraint(bool isPerfConstraint) const;
496500
BRIDGED_INLINE bool isResilientNominalDecl(BridgedDeclObj decl) const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,18 @@ BridgedCanType BridgedFunction::getLoweredFunctionTypeInContext() const {
655655
return getFunction()->getLoweredFunctionTypeInContext(expansion);
656656
}
657657

658+
BridgedGenericSignature BridgedFunction::getGenericSignature() const {
659+
return {getFunction()->getGenericSignature().getPointer()};
660+
}
661+
662+
BridgedSubstitutionMap BridgedFunction::getForwardingSubstitutionMap() const {
663+
return {getFunction()->getForwardingSubstitutionMap()};
664+
}
665+
666+
BridgedASTType BridgedFunction::mapTypeIntoContext(BridgedASTType ty) const {
667+
return {getFunction()->mapTypeIntoContext(ty.unbridged()).getPointer()};
668+
}
669+
658670
OptionalBridgedBasicBlock BridgedFunction::getFirstBlock() const {
659671
return {getFunction()->empty() ? nullptr : getFunction()->getEntryBlock()};
660672
}
@@ -781,6 +793,10 @@ bool BridgedFunction::needsStackProtection() const {
781793
return getFunction()->needsStackProtection();
782794
}
783795

796+
bool BridgedFunction::wasDeserializedCanonical() const {
797+
return getFunction()->wasDeserializedCanonical();
798+
}
799+
784800
void BridgedFunction::setNeedStackProtection(bool needSP) const {
785801
getFunction()->setNeedStackProtection(needSP);
786802
}

0 commit comments

Comments
 (0)