Skip to content

[sil-open-archetypes-tracker] Add type dependent operands to more instructions #9104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions include/swift/SIL/SILBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -677,8 +677,8 @@ class SILBuilder {

ConvertFunctionInst *createConvertFunction(SILLocation Loc, SILValue Op,
SILType Ty) {
return insert(new (F.getModule())
ConvertFunctionInst(getSILDebugLocation(Loc), Op, Ty));
return insert(ConvertFunctionInst::create(getSILDebugLocation(Loc), Op, Ty,
F, OpenedArchetypes));
}

ThinFunctionToPointerInst *
Expand All @@ -689,13 +689,13 @@ class SILBuilder {

PointerToThinFunctionInst *
createPointerToThinFunction(SILLocation Loc, SILValue Op, SILType Ty) {
return insert(new (F.getModule()) PointerToThinFunctionInst(
getSILDebugLocation(Loc), Op, Ty));
return insert(PointerToThinFunctionInst::create(
getSILDebugLocation(Loc), Op, Ty, F, OpenedArchetypes));
}

UpcastInst *createUpcast(SILLocation Loc, SILValue Op, SILType Ty) {
return insert(new (F.getModule())
UpcastInst(getSILDebugLocation(Loc), Op, Ty));
return insert(UpcastInst::create(getSILDebugLocation(Loc), Op, Ty, F,
OpenedArchetypes));
}

AddressToPointerInst *createAddressToPointer(SILLocation Loc, SILValue Op,
Expand Down Expand Up @@ -782,8 +782,8 @@ class SILBuilder {

ThinToThickFunctionInst *createThinToThickFunction(SILLocation Loc,
SILValue Op, SILType Ty) {
return insert(new (F.getModule()) ThinToThickFunctionInst(
getSILDebugLocation(Loc), Op, Ty));
return insert(ThinToThickFunctionInst::create(getSILDebugLocation(Loc), Op,
Ty, F, OpenedArchetypes));
}

ThickToObjCMetatypeInst *createThickToObjCMetatype(SILLocation Loc,
Expand Down
66 changes: 46 additions & 20 deletions include/swift/SIL/SILInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -2972,13 +2972,20 @@ class ConversionInst : public SILInstruction {

/// ConvertFunctionInst - Change the type of a function value without
/// affecting how it will codegen.
class ConvertFunctionInst
: public UnaryInstructionBase<ValueKind::ConvertFunctionInst, ConversionInst>
{
class ConvertFunctionInst final
: public UnaryInstructionWithTypeDependentOperandsBase<
ValueKind::ConvertFunctionInst, ConvertFunctionInst, ConversionInst,
/* HAS_RESULT */ true> {
friend SILBuilder;

ConvertFunctionInst(SILDebugLocation DebugLoc, SILValue Operand, SILType Ty)
: UnaryInstructionBase(DebugLoc, Operand, Ty) {}
ConvertFunctionInst(SILDebugLocation DebugLoc, SILValue Operand,
ArrayRef<SILValue> TypeDependentOperands, SILType Ty)
: UnaryInstructionWithTypeDependentOperandsBase(
DebugLoc, Operand, TypeDependentOperands, Ty) {}

static ConvertFunctionInst *
create(SILDebugLocation DebugLoc, SILValue Operand, SILType Ty,
SILFunction &F, SILOpenedArchetypesState &OpenedArchetypes);
};

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

/// PointerToThinFunctionInst - Convert a Builtin.RawPointer to a thin
/// function pointer.
class PointerToThinFunctionInst
: public UnaryInstructionBase<ValueKind::PointerToThinFunctionInst,
ConversionInst>
{
class PointerToThinFunctionInst final
: public UnaryInstructionWithTypeDependentOperandsBase<
ValueKind::PointerToThinFunctionInst, PointerToThinFunctionInst,
ConversionInst, /* HAS_RESULT */ true> {
friend SILBuilder;

PointerToThinFunctionInst(SILDebugLocation DebugLoc, SILValue operand,
ArrayRef<SILValue> TypeDependentOperands,
SILType ty)
: UnaryInstructionBase(DebugLoc, operand, ty) {}
: UnaryInstructionWithTypeDependentOperandsBase(
DebugLoc, operand, TypeDependentOperands, ty) {}

static PointerToThinFunctionInst *
create(SILDebugLocation DebugLoc, SILValue Operand, SILType Ty,
SILFunction &F, SILOpenedArchetypesState &OpenedArchetypes);
};

/// UpcastInst - Perform a conversion of a class instance to a supertype.
class UpcastInst
: public UnaryInstructionBase<ValueKind::UpcastInst, ConversionInst>
class UpcastInst final : public UnaryInstructionWithTypeDependentOperandsBase<
ValueKind::UpcastInst, UpcastInst, ConversionInst,
/* HAS_RESULT */ true>

{
friend SILBuilder;

UpcastInst(SILDebugLocation DebugLoc, SILValue Operand, SILType Ty)
: UnaryInstructionBase(DebugLoc, Operand, Ty) {}
UpcastInst(SILDebugLocation DebugLoc, SILValue Operand,
ArrayRef<SILValue> TypeDependentOperands, SILType Ty)
: UnaryInstructionWithTypeDependentOperandsBase(
DebugLoc, Operand, TypeDependentOperands, Ty) {}

static UpcastInst *
create(SILDebugLocation DebugLoc, SILValue Operand, SILType Ty,
SILFunction &F, SILOpenedArchetypesState &OpenedArchetypes);
};

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

/// ThinToThickFunctionInst - Given a thin function reference, adds a null
/// context to convert the value to a thick function type.
class ThinToThickFunctionInst
: public UnaryInstructionBase<ValueKind::ThinToThickFunctionInst,
ConversionInst>
{
class ThinToThickFunctionInst final
: public UnaryInstructionWithTypeDependentOperandsBase<
ValueKind::ThinToThickFunctionInst, ThinToThickFunctionInst,
ConversionInst, /* HAS_RESULT */ true> {
friend SILBuilder;

ThinToThickFunctionInst(SILDebugLocation DebugLoc, SILValue Operand,
SILType Ty)
: UnaryInstructionBase(DebugLoc, Operand, Ty) {}
ArrayRef<SILValue> TypeDependentOperands, SILType Ty)
: UnaryInstructionWithTypeDependentOperandsBase(
DebugLoc, Operand, TypeDependentOperands, Ty) {}

static ThinToThickFunctionInst *
create(SILDebugLocation DebugLoc, SILValue Operand, SILType Ty,
SILFunction &F, SILOpenedArchetypesState &OpenedArchetypes);

public:
/// Return the callee of the thin_to_thick_function.
Expand Down
59 changes: 59 additions & 0 deletions lib/SIL/SILInstructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1906,6 +1906,65 @@ MetatypeInst *MetatypeInst::create(SILDebugLocation Loc, SILType Ty,
return ::new (Buffer) MetatypeInst(Loc, Ty, TypeDependentOperands);
}

UpcastInst *UpcastInst::create(SILDebugLocation DebugLoc, SILValue Operand,
SILType Ty, SILFunction &F,
SILOpenedArchetypesState &OpenedArchetypes) {
SILModule &Mod = F.getModule();
SmallVector<SILValue, 8> TypeDependentOperands;
collectTypeDependentOperands(TypeDependentOperands, OpenedArchetypes, F,
Ty.getSwiftRValueType());
unsigned size =
totalSizeToAlloc<swift::Operand>(1 + TypeDependentOperands.size());
void *Buffer = Mod.allocateInst(size, alignof(UpcastInst));
return ::new (Buffer) UpcastInst(DebugLoc, Operand,
TypeDependentOperands, Ty);
}

ThinToThickFunctionInst *
ThinToThickFunctionInst::create(SILDebugLocation DebugLoc, SILValue Operand,
SILType Ty, SILFunction &F,
SILOpenedArchetypesState &OpenedArchetypes) {
SILModule &Mod = F.getModule();
SmallVector<SILValue, 8> TypeDependentOperands;
collectTypeDependentOperands(TypeDependentOperands, OpenedArchetypes, F,
Ty.getSwiftRValueType());
unsigned size =
totalSizeToAlloc<swift::Operand>(1 + TypeDependentOperands.size());
void *Buffer = Mod.allocateInst(size, alignof(ThinToThickFunctionInst));
return ::new (Buffer) ThinToThickFunctionInst(DebugLoc, Operand,
TypeDependentOperands, Ty);
}

PointerToThinFunctionInst *
PointerToThinFunctionInst::create(SILDebugLocation DebugLoc, SILValue Operand,
SILType Ty, SILFunction &F,
SILOpenedArchetypesState &OpenedArchetypes) {
SILModule &Mod = F.getModule();
SmallVector<SILValue, 8> TypeDependentOperands;
collectTypeDependentOperands(TypeDependentOperands, OpenedArchetypes, F,
Ty.getSwiftRValueType());
unsigned size =
totalSizeToAlloc<swift::Operand>(1 + TypeDependentOperands.size());
void *Buffer = Mod.allocateInst(size, alignof(PointerToThinFunctionInst));
return ::new (Buffer) PointerToThinFunctionInst(DebugLoc, Operand,
TypeDependentOperands, Ty);
}

ConvertFunctionInst *
ConvertFunctionInst::create(SILDebugLocation DebugLoc, SILValue Operand,
SILType Ty, SILFunction &F,
SILOpenedArchetypesState &OpenedArchetypes) {
SILModule &Mod = F.getModule();
SmallVector<SILValue, 8> TypeDependentOperands;
collectTypeDependentOperands(TypeDependentOperands, OpenedArchetypes, F,
Ty.getSwiftRValueType());
unsigned size =
totalSizeToAlloc<swift::Operand>(1 + TypeDependentOperands.size());
void *Buffer = Mod.allocateInst(size, alignof(ConvertFunctionInst));
return ::new (Buffer) ConvertFunctionInst(DebugLoc, Operand,
TypeDependentOperands, Ty);
}

bool KeyPathPatternComponent::isComputedSettablePropertyMutating() const {
switch (getKind()) {
case Kind::StoredProperty:
Expand Down
3 changes: 0 additions & 3 deletions test/Interpreter/subclass_existentials.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
// RUN: %target-build-swift %s -o %t/a.out
// RUN: %target-run %t/a.out
// REQUIRES: executable_test
//
// XFAIL: swift_test_mode_optimize
// XFAIL: swift_test_mode_optimize_unchecked

import StdlibUnittest

Expand Down