Skip to content

Commit 2237fac

Browse files
committed
[SILOptimizer] Refines the implementation of of the bridged SILType for Swift.
1 parent 775e28f commit 2237fac

File tree

7 files changed

+9
-14
lines changed

7 files changed

+9
-14
lines changed

SwiftCompilerSources/Sources/AST/Type.swift

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ extension TypeProperties {
9393
public var isEscapable: Bool { type.bridged.isEscapable() }
9494
public var isNoEscape: Bool { type.bridged.isNoEscape() }
9595
public var isInteger: Bool { type.bridged.isInteger() }
96+
public var isOptional: Bool { type.bridged.isOptional() }
9697
public var isMetatypeType: Bool { type.bridged.isMetatypeType() }
9798
public var isExistentialMetatypeType: Bool { type.bridged.isExistentialMetatypeType() }
9899
public var representationOfMetatype: AST.`Type`.MetatypeRepresentation {

SwiftCompilerSources/Sources/SIL/Type.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public struct Type : CustomStringConvertible, NoReflectionChildren {
6363
public var isFunction: Bool { bridged.isFunction() }
6464
public var isMetatype: Bool { bridged.isMetatype() }
6565
public var isClassExistential: Bool { bridged.isClassExistential() }
66-
public var isOptional: Bool { bridged.isOptional() }
66+
public var isOptional: Bool { astType.isOptional }
6767
public var isNoEscapeFunction: Bool { bridged.isNoEscapeFunction() }
6868
public var containsNoEscapeFunction: Bool { bridged.containsNoEscapeFunction() }
6969
public var isThickFunction: Bool { bridged.isThickFunction() }

include/swift/AST/ASTBridging.h

+1
Original file line numberDiff line numberDiff line change
@@ -3021,6 +3021,7 @@ struct BridgedASTType {
30213021
BRIDGED_INLINE bool isInteger() const;
30223022
BRIDGED_INLINE bool isMetatypeType() const;
30233023
BRIDGED_INLINE bool isExistentialMetatypeType() const;
3024+
BRIDGED_INLINE bool isOptional() const;
30243025
BRIDGED_INLINE TraitResult canBeClass() const;
30253026
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedDeclObj getAnyNominal() const;
30263027
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType getInstanceTypeOfMetatype() const;

include/swift/AST/ASTBridgingImpl.h

+4
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,10 @@ bool BridgedASTType::isMetatypeType() const {
430430
return unbridged()->is<swift::AnyMetatypeType>();
431431
}
432432

433+
bool BridgedASTType::isOptional() const {
434+
return unbridged()->getCanonicalType()->isOptional();
435+
}
436+
433437
bool BridgedASTType::isExistentialMetatypeType() const {
434438
return unbridged()->is<swift::ExistentialMetatypeType>();
435439
}

include/swift/AST/Types.h

-7
Original file line numberDiff line numberDiff line change
@@ -795,9 +795,6 @@ class alignas(1 << TypeAlignInBits) TypeBase
795795
/// Determine whether the type is an opened existential type with Error inside
796796
bool isOpenedExistentialWithError();
797797

798-
/// Determine whether the type is an Optional type.
799-
bool isOptional() const;
800-
801798
/// Retrieve the set of type parameter packs that occur within this type.
802799
void getTypeParameterPacks(SmallVectorImpl<Type> &rootParameterPacks);
803800

@@ -7929,10 +7926,6 @@ inline bool TypeBase::isClassExistentialType() {
79297926
return false;
79307927
}
79317928

7932-
inline bool TypeBase::isOptional() const {
7933-
return getCanonicalType()->isOptional();
7934-
}
7935-
79367929
inline bool TypeBase::canDynamicallyBeOptionalType(bool includeExistential) {
79377930
CanType T = getCanonicalType();
79387931
auto isArchetypeOrExistential = isa<ArchetypeType>(T) ||

include/swift/SIL/SILBridgingImpl.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,8 @@ bool BridgedType::isClassExistential() const {
403403
}
404404

405405
bool BridgedType::isOptional() const {
406-
return unbridged().isOptional();
406+
swift::CanType astType = unbridged().getASTType();
407+
return astType->isOptional();
407408
}
408409

409410
bool BridgedType::isNoEscapeFunction() const {

include/swift/SIL/SILType.h

-5
Original file line numberDiff line numberDiff line change
@@ -458,11 +458,6 @@ class SILType {
458458
return getASTType()->hasOpenedExistential();
459459
}
460460

461-
/// Returns true if the referenced type is an Optional type.
462-
bool isOptional() const {
463-
return getASTType()->isOptional();
464-
}
465-
466461
TypeTraitResult canBeClass() const {
467462
return getASTType()->canBeClass();
468463
}

0 commit comments

Comments
 (0)