mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
SIL: let TypeValueInst.value return an optional Int
and don't require the client to check if it's an integer type. Also, implement `var value` natively and without bridging.
This commit is contained in:
@@ -15,7 +15,7 @@ import SIL
|
||||
extension TypeValueInst: OnoneSimplifiable, SILCombineSimplifiable {
|
||||
func simplify(_ context: SimplifyContext) {
|
||||
// If our parameter is not known statically, then bail.
|
||||
guard paramType.isInteger else {
|
||||
guard let value = value else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -862,8 +862,12 @@ final public class TypeValueInst: SingleValueInstruction, UnaryInstruction {
|
||||
CanonicalType(bridged: bridged.TypeValueInst_getParamType())
|
||||
}
|
||||
|
||||
public var value: Int {
|
||||
bridged.TypeValueInst_getValue()
|
||||
/// Returns the value of the Integer type is known and fits into an `Int`.
|
||||
public var value: Int? {
|
||||
if paramType.isInteger {
|
||||
return paramType.valueOfInteger
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -857,7 +857,6 @@ struct BridgedInstruction {
|
||||
BRIDGED_INLINE SwiftInt FullApplySite_numIndirectResultArguments() const;
|
||||
BRIDGED_INLINE bool ConvertFunctionInst_withoutActuallyEscaping() const;
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedCanType TypeValueInst_getParamType() const;
|
||||
BRIDGED_INLINE SwiftInt TypeValueInst_getValue() const;
|
||||
|
||||
// =========================================================================//
|
||||
// VarDeclInst and DebugVariableInst
|
||||
|
||||
@@ -1659,19 +1659,6 @@ BridgedCanType BridgedInstruction::TypeValueInst_getParamType() const {
|
||||
return getAs<swift::TypeValueInst>()->getParamType();
|
||||
}
|
||||
|
||||
SwiftInt BridgedInstruction::TypeValueInst_getValue() const {
|
||||
auto tvi = getAs<swift::TypeValueInst>();
|
||||
|
||||
// Assume we've already checked that the parameter type is an IntegerType.
|
||||
auto integer = tvi->getParamType()->castTo<swift::IntegerType>();
|
||||
|
||||
if (integer->isNegative()) {
|
||||
return integer->getValue().getSExtValue();
|
||||
} else {
|
||||
return integer->getValue().getZExtValue();
|
||||
}
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// VarDeclInst and DebugVariableInst
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
Reference in New Issue
Block a user