Skip to content

Commit d523e30

Browse files
committed
SIL/AST: move some SIL.Type APIs to the TypeProperties protocol which makes them also available for AST.Type and AST.CanonicalType
1 parent 380ea88 commit d523e30

File tree

6 files changed

+54
-39
lines changed

6 files changed

+54
-39
lines changed

SwiftCompilerSources/Sources/AST/Type.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,20 @@ extension TypeProperties {
162162
return false
163163
}
164164

165+
//===--------------------------------------------------------------------===//
166+
// Properties of lowered `SILFunctionType`s
167+
//===--------------------------------------------------------------------===//
168+
169+
public var isLoweredFunction: Bool { rawType.bridged.isLoweredFunction() }
170+
public var isNoEscapeFunction: Bool { rawType.bridged.isNoEscapeFunction() }
171+
public var isCalleeConsumedFunction: Bool { rawType.bridged.isCalleeConsumedFunction() }
172+
public var isThickFunction: Bool { rawType.bridged.isThickFunction() }
173+
public var isAsyncFunction: Bool { rawType.bridged.isAsyncFunction() }
174+
175+
public var invocationGenericSignatureOfFunction: GenericSignature {
176+
GenericSignature(bridged: rawType.bridged.getInvocationGenericSignatureOfFunctionType())
177+
}
178+
165179
//===--------------------------------------------------------------------===//
166180
// Type properties
167181
//===--------------------------------------------------------------------===//

SwiftCompilerSources/Sources/SIL/Type.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,7 @@ public struct Type : TypeProperties, CustomStringConvertible, NoReflectionChildr
101101
// Properties of lowered `SILFunctionType`s
102102
//===--------------------------------------------------------------------===//
103103

104-
public var isLoweredFunction: Bool { bridged.isFunction() }
105-
public var isNoEscapeFunction: Bool { bridged.isNoEscapeFunction() }
106-
public var isCalleeConsumedFunction: Bool { bridged.isCalleeConsumedFunction() }
107104
public var containsNoEscapeFunction: Bool { bridged.containsNoEscapeFunction() }
108-
public var isThickFunction: Bool { bridged.isThickFunction() }
109-
public var isAsyncFunction: Bool { bridged.isAsyncFunction() }
110-
111-
public var invocationGenericSignatureOfFunction: GenericSignature {
112-
GenericSignature(bridged: bridged.getInvocationGenericSignatureOfFunctionType())
113-
}
114105

115106
// Returns a new SILFunctionType with changed "escapeness".
116107
public func getFunctionType(withNoEscape: Bool) -> Type {

include/swift/AST/ASTBridging.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3088,6 +3088,11 @@ struct BridgedASTType {
30883088
BRIDGED_INLINE bool isExistentialMetatypeType() const;
30893089
BRIDGED_INLINE bool isTuple() const;
30903090
BRIDGED_INLINE bool isFunction() const;
3091+
BRIDGED_INLINE bool isLoweredFunction() const;
3092+
BRIDGED_INLINE bool isNoEscapeFunction() const;
3093+
BRIDGED_INLINE bool isThickFunction() const;
3094+
BRIDGED_INLINE bool isAsyncFunction() const;
3095+
BRIDGED_INLINE bool isCalleeConsumedFunction() const;
30913096
BRIDGED_INLINE bool isBuiltinInteger() const;
30923097
BRIDGED_INLINE bool isBuiltinFloat() const;
30933098
BRIDGED_INLINE bool isBuiltinVector() const;
@@ -3101,6 +3106,7 @@ struct BridgedASTType {
31013106
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType getSuperClassType() const;
31023107
BRIDGED_INLINE MetatypeRepresentation getRepresentationOfMetatype() const;
31033108
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedSubstitutionMap getContextSubstitutionMap() const;
3109+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedGenericSignature getInvocationGenericSignatureOfFunctionType() const;
31043110
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType subst(BridgedSubstitutionMap substMap) const;
31053111
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType subst(BridgedASTType fromType, BridgedASTType toType) const;
31063112
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedConformance checkConformance(BridgedDeclObj proto) const;

include/swift/AST/ASTBridgingImpl.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,36 @@ bool BridgedASTType::isFunction() const {
459459
return unbridged()->is<swift::FunctionType>();
460460
}
461461

462+
bool BridgedASTType::isLoweredFunction() const {
463+
return unbridged()->is<swift::SILFunctionType>();
464+
}
465+
466+
bool BridgedASTType::isNoEscapeFunction() const {
467+
if (auto *fTy = unbridged()->getAs<swift::SILFunctionType>()) {
468+
return fTy->isNoEscape();
469+
}
470+
return false;
471+
}
472+
473+
bool BridgedASTType::isThickFunction() const {
474+
if (auto *fTy = unbridged()->getAs<swift::SILFunctionType>()) {
475+
return fTy->getRepresentation() == swift::SILFunctionType::Representation::Thick;
476+
}
477+
return false;
478+
}
479+
480+
bool BridgedASTType::isAsyncFunction() const {
481+
if (auto *fTy = unbridged()->getAs<swift::SILFunctionType>()) {
482+
return fTy->isAsync();
483+
}
484+
return false;
485+
}
486+
487+
bool BridgedASTType::isCalleeConsumedFunction() const {
488+
auto *funcTy = unbridged()->castTo<swift::SILFunctionType>();
489+
return funcTy->isCalleeConsumed() && !funcTy->isNoEscape();
490+
}
491+
462492
bool BridgedASTType::isBuiltinInteger() const {
463493
return unbridged()->is<swift::BuiltinIntegerType>();
464494
}
@@ -517,6 +547,10 @@ BridgedSubstitutionMap BridgedASTType::getContextSubstitutionMap() const {
517547
return unbridged()->getContextSubstitutionMap();
518548
}
519549

550+
BridgedGenericSignature BridgedASTType::getInvocationGenericSignatureOfFunctionType() const {
551+
return {unbridged()->castTo<swift::SILFunctionType>()->getInvocationGenericSignature().getPointer()};
552+
}
553+
520554
BridgedASTType BridgedASTType::subst(BridgedSubstitutionMap substMap) const {
521555
return {unbridged().subst(substMap.unbridged()).getPointer()};
522556
}

include/swift/SIL/SILBridging.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,16 +250,11 @@ struct BridgedType {
250250
BRIDGED_INLINE bool isNonTrivialOrContainsRawPointer(BridgedFunction f) const;
251251
BRIDGED_INLINE bool isLoadable(BridgedFunction f) const;
252252
BRIDGED_INLINE bool isReferenceCounted(BridgedFunction f) const;
253-
BRIDGED_INLINE bool isFunction() const;
254-
BRIDGED_INLINE bool isNoEscapeFunction() const;
255253
BRIDGED_INLINE bool containsNoEscapeFunction() const;
256-
BRIDGED_INLINE bool isThickFunction() const;
257-
BRIDGED_INLINE bool isAsyncFunction() const;
258254
BRIDGED_INLINE bool isEmpty(BridgedFunction f) const;
259255
BRIDGED_INLINE bool isMoveOnly() const;
260256
BRIDGED_INLINE bool isEscapable(BridgedFunction f) const;
261257
BRIDGED_INLINE bool isExactSuperclassOf(BridgedType t) const;
262-
BRIDGED_INLINE bool isCalleeConsumedFunction() const;
263258
BRIDGED_INLINE bool isMarkedAsImmortal() const;
264259
BRIDGED_INLINE bool isAddressableForDeps(BridgedFunction f) const;
265260
BRIDGED_INLINE SwiftInt getCaseIdxOfEnumType(BridgedStringRef name) const;
@@ -274,7 +269,6 @@ struct BridgedType {
274269
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedType
275270
getTupleElementType(SwiftInt idx) const;
276271
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedType getFunctionTypeWithNoEscape(bool withNoEscape) const;
277-
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedGenericSignature getInvocationGenericSignatureOfFunctionType() const;
278272
BRIDGED_INLINE BridgedArgumentConvention getCalleeConvention() const;
279273
};
280274

include/swift/SIL/SILBridgingImpl.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -348,26 +348,10 @@ bool BridgedType::isReferenceCounted(BridgedFunction f) const {
348348
return unbridged().isReferenceCounted(f.getFunction());
349349
}
350350

351-
bool BridgedType::isFunction() const {
352-
return unbridged().isFunction();
353-
}
354-
355-
bool BridgedType::isNoEscapeFunction() const {
356-
return unbridged().isNoEscapeFunction();
357-
}
358-
359351
bool BridgedType::containsNoEscapeFunction() const {
360352
return unbridged().containsNoEscapeFunction();
361353
}
362354

363-
bool BridgedType::isThickFunction() const {
364-
return unbridged().isThickFunction();
365-
}
366-
367-
bool BridgedType::isAsyncFunction() const {
368-
return unbridged().isAsyncFunction();
369-
}
370-
371355
bool BridgedType::isEmpty(BridgedFunction f) const {
372356
return unbridged().isEmpty(*f.getFunction());
373357
}
@@ -384,10 +368,6 @@ bool BridgedType::isExactSuperclassOf(BridgedType t) const {
384368
return unbridged().isExactSuperclassOf(t.unbridged());
385369
}
386370

387-
bool BridgedType::isCalleeConsumedFunction() const {
388-
return unbridged().isCalleeConsumedFunction();
389-
}
390-
391371
bool BridgedType::isMarkedAsImmortal() const {
392372
return unbridged().isMarkedAsImmortal();
393373
}
@@ -448,10 +428,6 @@ BridgedType BridgedType::getFunctionTypeWithNoEscape(bool withNoEscape) const {
448428
return swift::SILType::getPrimitiveObjectType(newTy);
449429
}
450430

451-
BridgedGenericSignature BridgedType::getInvocationGenericSignatureOfFunctionType() const {
452-
return {unbridged().castTo<swift::SILFunctionType>()->getInvocationGenericSignature().getPointer()};
453-
}
454-
455431
BridgedArgumentConvention BridgedType::getCalleeConvention() const {
456432
auto fnType = unbridged().getAs<swift::SILFunctionType>();
457433
return getArgumentConvention(fnType->getCalleeConvention());

0 commit comments

Comments
 (0)