Skip to content

Commit 0f6a231

Browse files
committed
(fixup later) clean up code
1 parent 53eaa76 commit 0f6a231

File tree

7 files changed

+33
-24
lines changed

7 files changed

+33
-24
lines changed

SwiftCompilerSources/Sources/AST/Type.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ extension TypeProperties {
274274
return rawType.bridged.isSILPackElementAddress()
275275
}
276276

277-
public func getPackElementType(_ index: Int) -> Type {
278-
return Type(bridged: rawType.bridged.getPackElementType(index));
277+
public var packElementTypes: TypeArray {
278+
return TypeArray(bridged: rawType.bridged.getPackElementTypes())
279279
}
280280
}
281281

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyAllocStack.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ extension AllocStackInst : Simplifiable, SILCombineSimplifiable {
1818
if optimizeEnum(context) {
1919
return
2020
}
21-
_ = optimizeExistential(context)
21+
if optimizeExistential(context) {
22+
return
23+
}
2224
_ = optimizePackElement(context)
2325
}
2426
}
@@ -308,8 +310,10 @@ private extension AllocStackInst {
308310
///
309311
/// For example:
310312
/// ```
311-
/// %0 = alloc_stack $@pack_element(...) ...
312-
/// use %1
313+
/// %1 = dynamic_pack_index %0 of $Pack{T, U}
314+
/// %2 = open_pack_element %1 of <...> at <Pack{T, U}> ...
315+
/// %3 = alloc_stack $@pack_element(...) ...
316+
/// use %3
313317
/// ```
314318
/// is transformed to
315319
/// ```

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyUncheckedAddrCast.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,21 @@ extension UncheckedAddrCastInst : OnoneSimplifiable, SILCombineSimplifiable {
4444
// ```
4545
// %1 = vector_base_addr %0 : $*Builtin.FixedArray<N, Element>
4646
// ```
47-
_ = optimizeVectorBaseCast(context)
47+
if optimizeVectorBaseCast(context) {
48+
return
49+
}
4850

4951
// ```
50-
// %1 = unchecked_addr_cast %0 to $*pack_element("...") ...
52+
// %2 = dynamic_pack_index %1 of $Pack{T, U}
53+
// %3 = open_pack_element %2 of <...> at <Pack{T, U}> ...
54+
// %4 = pack_element_get %3 of %11 as $*Int
55+
// %5 = unchecked_addr_cast %4 to $*@pack_element(..)
5156
// ```
5257
// ->
5358
// ```
5459
// %1 = unchecked_addr_cast %0 to $T
5560
// ```
5661
_ = optimizePackElement(context)
57-
5862
}
5963
}
6064

@@ -96,7 +100,7 @@ private extension UncheckedAddrCastInst {
96100

97101
let builder = Builder(before: self, context)
98102
let newCast = builder.createUncheckedAddrCast(from: fromAddress,
99-
to:concreteType.loweredType(in: parentFunction).addressType)
103+
to: concreteType.loweredType(in: parentFunction).addressType)
100104
self.replace(with: newCast, context)
101105
return true
102106
}

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyWitnessMethod.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ import SIL
1515

1616
extension WitnessMethodInst : Simplifiable, SILCombineSimplifiable {
1717
func simplify(_ context: SimplifyContext) {
18-
_ = tryReplaceExistentialArchetype(of: self, context)
18+
if tryReplaceExistentialArchetype(of: self, context) {
19+
return
20+
}
1921
_ = tryReplacePackElementArchetype(of: self, context)
2022
}
2123
}

SwiftCompilerSources/Sources/Optimizer/Utilities/OptUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ extension Instruction {
560560
let ili = dpi.operands.first?.value as? IntegerLiteralInst,
561561
let index = ili.value
562562
{
563-
return dpi.indexedPackType.getPackElementType(index).canonical
563+
return dpi.indexedPackType.packElementTypes[index].canonical
564564
}
565565
return nil
566566
}

include/swift/AST/ASTBridging.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2915,6 +2915,15 @@ enum ENUM_EXTENSIBILITY_ATTR(open) BridgedMacroDefinitionKind : size_t {
29152915
BridgedBuiltinIsolationMacro,
29162916
};
29172917

2918+
struct BridgedASTTypeArray {
2919+
BridgedArrayRef typeArray;
2920+
2921+
SwiftInt getCount() const { return SwiftInt(typeArray.Length); }
2922+
2923+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE
2924+
BridgedASTType getAt(SwiftInt index) const;
2925+
};
2926+
29182927
struct BridgedASTType {
29192928
enum class TraitResult {
29202929
IsNot,
@@ -2994,7 +3003,7 @@ struct BridgedASTType {
29943003
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedConformance checkConformance(BridgedDeclObj proto) const;
29953004
BRIDGED_INLINE bool containsSILPackExpansionType() const;
29963005
BRIDGED_INLINE bool isSILPackElementAddress() const;
2997-
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType getPackElementType(SwiftInt index) const;
3006+
BRIDGED_INLINE BridgedASTTypeArray getPackElementTypes() const;
29983007
};
29993008

30003009
class BridgedCanType {
@@ -3007,15 +3016,6 @@ class BridgedCanType {
30073016
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType getRawType() const;
30083017
};
30093018

3010-
struct BridgedASTTypeArray {
3011-
BridgedArrayRef typeArray;
3012-
3013-
SwiftInt getCount() const { return SwiftInt(typeArray.Length); }
3014-
3015-
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE
3016-
BridgedASTType getAt(SwiftInt index) const;
3017-
};
3018-
30193019
struct BridgedConformance {
30203020
void * _Nullable opaqueValue;
30213021

include/swift/AST/ASTBridgingImpl.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,8 @@ bool BridgedASTType::isSILPackElementAddress() const {
656656
return unbridged()->castTo<swift::SILPackType>()->isElementAddress();
657657
}
658658

659-
BridgedASTType BridgedASTType::getPackElementType(SwiftInt index) const {
660-
ASSERT(index >= 0);
661-
return {unbridged()->castTo<swift::PackType>()->getElementType(index).getPointer()};
659+
BRIDGED_INLINE BridgedASTTypeArray BridgedASTType::getPackElementTypes() const {
660+
return {unbridged()->castTo<swift::PackType>()->getElementTypes()};
662661
}
663662

664663
static_assert((int)BridgedASTType::TraitResult::IsNot == (int)swift::TypeTraitResult::IsNot);

0 commit comments

Comments
 (0)