Skip to content

Resolve an issue with indirect enum's match for opaque values #8282

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
Mar 22, 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
2 changes: 1 addition & 1 deletion lib/SILGen/SILGenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ emitEnumMatch(ManagedValue value, EnumElementDecl *ElementDecl,
SILValue boxedValue = SGF.B.createProjectBox(loc, eltMV.getValue(), 0);
auto &boxedTL = SGF.getTypeLowering(boxedValue->getType());
// SEMANTIC ARC TODO: Revisit this when the verifier is enabled.
if (boxedTL.isLoadable())
if (boxedTL.isLoadable() || !SGF.silConv.useLoweredAddresses())
boxedValue = boxedTL.emitLoad(SGF.B, loc, boxedValue,
LoadOwnershipQualifier::Take);

Expand Down
35 changes: 35 additions & 0 deletions test/SILGen/opaque_values_silgen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ struct AnyStruct {
let a: Any
}

indirect enum IndirectEnum<T> {
case Nil
case Node(T)
}

func s010_hasVarArg(_ args: Any...) {}

// Tests Address only enums's construction
Expand Down Expand Up @@ -675,6 +680,36 @@ func s350_______addrOnlyIf(x: Bool) -> EmptyP {
return x ? a : a
}

// Tests support for guards and indirect enums for opaque values
// ---
// CHECK-LABEL: sil hidden @_T020opaque_values_silgen21s360________guardEnumyAA08IndirectF0OyxGlF : $@convention(thin) <T> (@owned IndirectEnum<T>) -> () {
// CHECK: bb0([[ARG:%.*]] : $IndirectEnum<T>):
// CHECK: [[BORROWED_ARG:%.*]] = begin_borrow [[ARG]]
// CHECK: [[COPY__ARG:%.*]] = copy_value [[BORROWED_ARG]]
// CHECK: switch_enum [[COPY__ARG]] : $IndirectEnum<T>, case #IndirectEnum.Node!enumelt.1: bb3, default bb1
// CHECK: bb1:
// CHECK: end_borrow [[BORROWED_ARG]] from [[ARG]] : $IndirectEnum<T>, $IndirectEnum<T>
// CHECK: br bb2
// CHECK: bb2:
// CHECK: br bb4
// CHECK: bb3([[EARG:%.*]] : $<τ_0_0> { var τ_0_0 } <T>):
// CHECK: [[PROJ_BOX:%.*]] = project_box [[EARG]]
// CHECK: [[LOAD_BOX:%.*]] = load [take] [[PROJ_BOX]] : $*T
// CHECK: [[COPY_BOX:%.*]] = copy_value [[LOAD_BOX]] : $T
// CHECK: destroy_value [[EARG]]
// CHECK: end_borrow [[BORROWED_ARG]] from [[ARG]] : $IndirectEnum<T>, $IndirectEnum<T>
// CHECK: destroy_value [[COPY_BOX]]
// CHECK: br bb4
// CHECK: bb4:
// CHECK: destroy_value [[ARG]]
// CHECK: return %{{.*}} : $()
// CHECK-LABEL: } // end sil function '_T020opaque_values_silgen21s360________guardEnumyAA08IndirectF0OyxGlF'
func s360________guardEnum<T>(_ e: IndirectEnum<T>) {
do {
guard case .Node(let x) = e else { return }
}
}

// Tests conditional value casts and correspondingly generated reabstraction thunk, with <T> types
// ---
// CHECK-LABEL: sil hidden @_T020opaque_values_silgen21s999_____condTFromAnyyyp_xtlF : $@convention(thin) <T> (@in Any, @in T) -> () {
Expand Down