Skip to content

Commit 50bf66e

Browse files
committed
SIL: replace CanonicalType.objectType and CanonicalType.addressType with silType
`SIL.Type` itself has `objectType` and `addressType` to convert between both variants.
1 parent 95ae8d1 commit 50bf66e

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

SwiftCompilerSources/Sources/SIL/ASTExtensions.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ import AST
1414
import SILBridging
1515

1616
extension CanonicalType {
17-
var objectType: Type { BridgedType.createObjectType(bridged).type }
18-
var addressType: Type { BridgedType.createAddressType(bridged).type }
17+
// This can yield nil if the AST type is not a lowered type.
18+
// For example, if the AST type is a `AnyFunctionType` for which the lowered type would be a `SILFunctionType`.
19+
public var silType: Type? {
20+
BridgedType.createSILType(bridged).typeOrNil
21+
}
1922
}
2023

2124
extension Decl {
@@ -30,7 +33,7 @@ extension NominalTypeDecl {
3033

3134
extension ClassDecl {
3235
public var superClassType: Type? {
33-
self.superClass?.canonical.objectType
36+
self.superClass?.canonical.silType!
3437
}
3538
}
3639

include/swift/SIL/SILBridging.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,7 @@ struct BridgedType {
245245
BRIDGED_INLINE swift::SILType unbridged() const;
246246
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedCanType getCanType() const;
247247

248-
static SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedType createObjectType(BridgedCanType canTy);
249-
static SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedType createAddressType(BridgedCanType canTy);
248+
static SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedType createSILType(BridgedCanType canTy);
250249
BRIDGED_INLINE BridgedOwnedString getDebugDescription() const;
251250
BRIDGED_INLINE bool isNull() const;
252251
BRIDGED_INLINE bool isAddress() const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,11 @@ BridgedType::EnumElementIterator BridgedType::EnumElementIterator::getNext() con
284284
return bridge(std::next(unbridge(*this)));
285285
}
286286

287-
BridgedType BridgedType::createObjectType(BridgedCanType canTy) {
288-
return swift::SILType::getPrimitiveObjectType(canTy.unbridged());
289-
}
290-
291-
BridgedType BridgedType::createAddressType(BridgedCanType canTy) {
292-
return swift::SILType::getPrimitiveAddressType(canTy.unbridged());
287+
BridgedType BridgedType::createSILType(BridgedCanType canTy) {
288+
auto ty = canTy.unbridged();
289+
if (ty->isLegalSILType())
290+
return swift::SILType::getPrimitiveObjectType(ty);
291+
return swift::SILType();
293292
}
294293

295294
BridgedOwnedString BridgedType::getDebugDescription() const {

0 commit comments

Comments
 (0)