Skip to content

Commit 1731250

Browse files
committed
[sil-open-archetypes-tracker] Add type dependent operands to more instructions
The following instructions were enhanced with type dependent operands: - convert_function - pointer_to_thin_function - upcast_inst - thin_to_thick_function Fixes rdar://31879356
1 parent 13d1db0 commit 1731250

File tree

4 files changed

+113
-31
lines changed

4 files changed

+113
-31
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -677,8 +677,8 @@ class SILBuilder {
677677

678678
ConvertFunctionInst *createConvertFunction(SILLocation Loc, SILValue Op,
679679
SILType Ty) {
680-
return insert(new (F.getModule())
681-
ConvertFunctionInst(getSILDebugLocation(Loc), Op, Ty));
680+
return insert(ConvertFunctionInst::create(getSILDebugLocation(Loc), Op, Ty,
681+
F, OpenedArchetypes));
682682
}
683683

684684
ThinFunctionToPointerInst *
@@ -689,13 +689,13 @@ class SILBuilder {
689689

690690
PointerToThinFunctionInst *
691691
createPointerToThinFunction(SILLocation Loc, SILValue Op, SILType Ty) {
692-
return insert(new (F.getModule()) PointerToThinFunctionInst(
693-
getSILDebugLocation(Loc), Op, Ty));
692+
return insert(PointerToThinFunctionInst::create(
693+
getSILDebugLocation(Loc), Op, Ty, F, OpenedArchetypes));
694694
}
695695

696696
UpcastInst *createUpcast(SILLocation Loc, SILValue Op, SILType Ty) {
697-
return insert(new (F.getModule())
698-
UpcastInst(getSILDebugLocation(Loc), Op, Ty));
697+
return insert(UpcastInst::create(getSILDebugLocation(Loc), Op, Ty, F,
698+
OpenedArchetypes));
699699
}
700700

701701
AddressToPointerInst *createAddressToPointer(SILLocation Loc, SILValue Op,
@@ -782,8 +782,8 @@ class SILBuilder {
782782

783783
ThinToThickFunctionInst *createThinToThickFunction(SILLocation Loc,
784784
SILValue Op, SILType Ty) {
785-
return insert(new (F.getModule()) ThinToThickFunctionInst(
786-
getSILDebugLocation(Loc), Op, Ty));
785+
return insert(ThinToThickFunctionInst::create(getSILDebugLocation(Loc), Op,
786+
Ty, F, OpenedArchetypes));
787787
}
788788

789789
ThickToObjCMetatypeInst *createThickToObjCMetatype(SILLocation Loc,

include/swift/SIL/SILInstruction.h

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2972,13 +2972,20 @@ class ConversionInst : public SILInstruction {
29722972

29732973
/// ConvertFunctionInst - Change the type of a function value without
29742974
/// affecting how it will codegen.
2975-
class ConvertFunctionInst
2976-
: public UnaryInstructionBase<ValueKind::ConvertFunctionInst, ConversionInst>
2977-
{
2975+
class ConvertFunctionInst final
2976+
: public UnaryInstructionWithTypeDependentOperandsBase<
2977+
ValueKind::ConvertFunctionInst, ConvertFunctionInst, ConversionInst,
2978+
/* HAS_RESULT */ true> {
29782979
friend SILBuilder;
29792980

2980-
ConvertFunctionInst(SILDebugLocation DebugLoc, SILValue Operand, SILType Ty)
2981-
: UnaryInstructionBase(DebugLoc, Operand, Ty) {}
2981+
ConvertFunctionInst(SILDebugLocation DebugLoc, SILValue Operand,
2982+
ArrayRef<SILValue> TypeDependentOperands, SILType Ty)
2983+
: UnaryInstructionWithTypeDependentOperandsBase(
2984+
DebugLoc, Operand, TypeDependentOperands, Ty) {}
2985+
2986+
static ConvertFunctionInst *
2987+
create(SILDebugLocation DebugLoc, SILValue Operand, SILType Ty,
2988+
SILFunction &F, SILOpenedArchetypesState &OpenedArchetypes);
29822989
};
29832990

29842991
/// ThinFunctionToPointerInst - Convert a thin function pointer to a
@@ -2996,25 +3003,39 @@ class ThinFunctionToPointerInst
29963003

29973004
/// PointerToThinFunctionInst - Convert a Builtin.RawPointer to a thin
29983005
/// function pointer.
2999-
class PointerToThinFunctionInst
3000-
: public UnaryInstructionBase<ValueKind::PointerToThinFunctionInst,
3001-
ConversionInst>
3002-
{
3006+
class PointerToThinFunctionInst final
3007+
: public UnaryInstructionWithTypeDependentOperandsBase<
3008+
ValueKind::PointerToThinFunctionInst, PointerToThinFunctionInst,
3009+
ConversionInst, /* HAS_RESULT */ true> {
30033010
friend SILBuilder;
30043011

30053012
PointerToThinFunctionInst(SILDebugLocation DebugLoc, SILValue operand,
3013+
ArrayRef<SILValue> TypeDependentOperands,
30063014
SILType ty)
3007-
: UnaryInstructionBase(DebugLoc, operand, ty) {}
3015+
: UnaryInstructionWithTypeDependentOperandsBase(
3016+
DebugLoc, operand, TypeDependentOperands, ty) {}
3017+
3018+
static PointerToThinFunctionInst *
3019+
create(SILDebugLocation DebugLoc, SILValue Operand, SILType Ty,
3020+
SILFunction &F, SILOpenedArchetypesState &OpenedArchetypes);
30083021
};
30093022

30103023
/// UpcastInst - Perform a conversion of a class instance to a supertype.
3011-
class UpcastInst
3012-
: public UnaryInstructionBase<ValueKind::UpcastInst, ConversionInst>
3024+
class UpcastInst final : public UnaryInstructionWithTypeDependentOperandsBase<
3025+
ValueKind::UpcastInst, UpcastInst, ConversionInst,
3026+
/* HAS_RESULT */ true>
3027+
30133028
{
30143029
friend SILBuilder;
30153030

3016-
UpcastInst(SILDebugLocation DebugLoc, SILValue Operand, SILType Ty)
3017-
: UnaryInstructionBase(DebugLoc, Operand, Ty) {}
3031+
UpcastInst(SILDebugLocation DebugLoc, SILValue Operand,
3032+
ArrayRef<SILValue> TypeDependentOperands, SILType Ty)
3033+
: UnaryInstructionWithTypeDependentOperandsBase(
3034+
DebugLoc, Operand, TypeDependentOperands, Ty) {}
3035+
3036+
static UpcastInst *
3037+
create(SILDebugLocation DebugLoc, SILValue Operand, SILType Ty,
3038+
SILFunction &F, SILOpenedArchetypesState &OpenedArchetypes);
30183039
};
30193040

30203041
/// AddressToPointerInst - Convert a SIL address to a Builtin.RawPointer value.
@@ -3294,15 +3315,20 @@ class UnmanagedToRefInst
32943315

32953316
/// ThinToThickFunctionInst - Given a thin function reference, adds a null
32963317
/// context to convert the value to a thick function type.
3297-
class ThinToThickFunctionInst
3298-
: public UnaryInstructionBase<ValueKind::ThinToThickFunctionInst,
3299-
ConversionInst>
3300-
{
3318+
class ThinToThickFunctionInst final
3319+
: public UnaryInstructionWithTypeDependentOperandsBase<
3320+
ValueKind::ThinToThickFunctionInst, ThinToThickFunctionInst,
3321+
ConversionInst, /* HAS_RESULT */ true> {
33013322
friend SILBuilder;
33023323

33033324
ThinToThickFunctionInst(SILDebugLocation DebugLoc, SILValue Operand,
3304-
SILType Ty)
3305-
: UnaryInstructionBase(DebugLoc, Operand, Ty) {}
3325+
ArrayRef<SILValue> TypeDependentOperands, SILType Ty)
3326+
: UnaryInstructionWithTypeDependentOperandsBase(
3327+
DebugLoc, Operand, TypeDependentOperands, Ty) {}
3328+
3329+
static ThinToThickFunctionInst *
3330+
create(SILDebugLocation DebugLoc, SILValue Operand, SILType Ty,
3331+
SILFunction &F, SILOpenedArchetypesState &OpenedArchetypes);
33063332

33073333
public:
33083334
/// Return the callee of the thin_to_thick_function.

lib/SIL/SILInstructions.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,65 @@ MetatypeInst *MetatypeInst::create(SILDebugLocation Loc, SILType Ty,
19061906
return ::new (Buffer) MetatypeInst(Loc, Ty, TypeDependentOperands);
19071907
}
19081908

1909+
UpcastInst *UpcastInst::create(SILDebugLocation DebugLoc, SILValue Operand,
1910+
SILType Ty, SILFunction &F,
1911+
SILOpenedArchetypesState &OpenedArchetypes) {
1912+
SILModule &Mod = F.getModule();
1913+
SmallVector<SILValue, 8> TypeDependentOperands;
1914+
collectTypeDependentOperands(TypeDependentOperands, OpenedArchetypes, F,
1915+
Ty.getSwiftRValueType());
1916+
unsigned size =
1917+
totalSizeToAlloc<swift::Operand>(1 + TypeDependentOperands.size());
1918+
void *Buffer = Mod.allocateInst(size, alignof(UpcastInst));
1919+
return ::new (Buffer) UpcastInst(DebugLoc, Operand,
1920+
TypeDependentOperands, Ty);
1921+
}
1922+
1923+
ThinToThickFunctionInst *
1924+
ThinToThickFunctionInst::create(SILDebugLocation DebugLoc, SILValue Operand,
1925+
SILType Ty, SILFunction &F,
1926+
SILOpenedArchetypesState &OpenedArchetypes) {
1927+
SILModule &Mod = F.getModule();
1928+
SmallVector<SILValue, 8> TypeDependentOperands;
1929+
collectTypeDependentOperands(TypeDependentOperands, OpenedArchetypes, F,
1930+
Ty.getSwiftRValueType());
1931+
unsigned size =
1932+
totalSizeToAlloc<swift::Operand>(1 + TypeDependentOperands.size());
1933+
void *Buffer = Mod.allocateInst(size, alignof(ThinToThickFunctionInst));
1934+
return ::new (Buffer) ThinToThickFunctionInst(DebugLoc, Operand,
1935+
TypeDependentOperands, Ty);
1936+
}
1937+
1938+
PointerToThinFunctionInst *
1939+
PointerToThinFunctionInst::create(SILDebugLocation DebugLoc, SILValue Operand,
1940+
SILType Ty, SILFunction &F,
1941+
SILOpenedArchetypesState &OpenedArchetypes) {
1942+
SILModule &Mod = F.getModule();
1943+
SmallVector<SILValue, 8> TypeDependentOperands;
1944+
collectTypeDependentOperands(TypeDependentOperands, OpenedArchetypes, F,
1945+
Ty.getSwiftRValueType());
1946+
unsigned size =
1947+
totalSizeToAlloc<swift::Operand>(1 + TypeDependentOperands.size());
1948+
void *Buffer = Mod.allocateInst(size, alignof(PointerToThinFunctionInst));
1949+
return ::new (Buffer) PointerToThinFunctionInst(DebugLoc, Operand,
1950+
TypeDependentOperands, Ty);
1951+
}
1952+
1953+
ConvertFunctionInst *
1954+
ConvertFunctionInst::create(SILDebugLocation DebugLoc, SILValue Operand,
1955+
SILType Ty, SILFunction &F,
1956+
SILOpenedArchetypesState &OpenedArchetypes) {
1957+
SILModule &Mod = F.getModule();
1958+
SmallVector<SILValue, 8> TypeDependentOperands;
1959+
collectTypeDependentOperands(TypeDependentOperands, OpenedArchetypes, F,
1960+
Ty.getSwiftRValueType());
1961+
unsigned size =
1962+
totalSizeToAlloc<swift::Operand>(1 + TypeDependentOperands.size());
1963+
void *Buffer = Mod.allocateInst(size, alignof(ConvertFunctionInst));
1964+
return ::new (Buffer) ConvertFunctionInst(DebugLoc, Operand,
1965+
TypeDependentOperands, Ty);
1966+
}
1967+
19091968
bool KeyPathPatternComponent::isComputedSettablePropertyMutating() const {
19101969
switch (getKind()) {
19111970
case Kind::StoredProperty:

test/Interpreter/subclass_existentials.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
// RUN: %target-build-swift %s -o %t/a.out
1616
// RUN: %target-run %t/a.out
1717
// REQUIRES: executable_test
18-
//
19-
// XFAIL: swift_test_mode_optimize
20-
// XFAIL: swift_test_mode_optimize_unchecked
2118

2219
import StdlibUnittest
2320

0 commit comments

Comments
 (0)