Skip to content

Instantly share code, notes, and snippets.

@gregheo
Last active August 6, 2018 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregheo/240d35a9a58a594d63d48fed6b03dd52 to your computer and use it in GitHub Desktop.
Save gregheo/240d35a9a58a594d63d48fed6b03dd52 to your computer and use it in GitHub Desktop.
Swift synthesized == function for a struct
(func_decl implicit "__derived_struct_equals(_:_:)" interface type='(Puppy.Type) -> (Puppy, Puppy) -> Bool' access=internal type
(parameter_list
(parameter "self" interface type='Puppy.Type'))
(parameter_list
(parameter "a" type='Puppy' interface type='Puppy')
(parameter "b" type='Puppy' interface type='Puppy'))
(brace_stmt
(guard_stmt implicit
(call_expr implicit type='Int1' nothrow arg_labels=
(dot_syntax_call_expr implicit type='() -> Int1' nothrow
(declref_expr implicit type='(Bool) -> () -> Int1' decl=Swift.(file).Bool._getBuiltinLogicValue() function_ref=double)
(binary_expr implicit type='Bool' nothrow
(dot_syntax_call_expr implicit type='(String, String) -> Bool' nothrow
(declref_expr implicit type='(String.Type) -> (String, String) -> Bool' decl=Swift.(file).String.== function_ref=unapplied)
(type_expr implicit type='String.Type' typerepr='<<NULL>>'))
(tuple_expr implicit type='(String, String)'
(member_ref_expr implicit type='String' decl=eq.(file).Puppy.name@eq.swift:2:7 direct_to_storage
(declref_expr implicit type='Puppy' decl=eq.(file).Puppy.__derived_struct_equals(_:_:).a function_ref=unapplied))
(member_ref_expr implicit type='String' decl=eq.(file).Puppy.name@eq.swift:2:7 direct_to_storage
(declref_expr implicit type='Puppy' decl=eq.(file).Puppy.__derived_struct_equals(_:_:).b function_ref=unapplied)))))
(tuple_expr implicit type='()'))
(brace_stmt
(return_stmt implicit
(call_expr implicit type='Bool' nothrow arg_labels=_builtinBooleanLiteral:
(constructor_ref_call_expr implicit type='(Int1) -> Bool' nothrow
(declref_expr implicit type='(Bool.Type) -> (Int1) -> Bool' decl=Swift.(file).Bool.init(_builtinBooleanLiteral:) function_ref=single)
(type_expr implicit type='Bool.Type' typerepr='<<NULL>>'))
(tuple_expr implicit type='(_builtinBooleanLiteral: Builtin.Int1)' names=_builtinBooleanLiteral
(boolean_literal_expr implicit type='Builtin.Int1' value=false))))))
(guard_stmt implicit
(call_expr implicit type='Int1' nothrow arg_labels=
(dot_syntax_call_expr implicit type='() -> Int1' nothrow
(declref_expr implicit type='(Bool) -> () -> Int1' decl=Swift.(file).Bool._getBuiltinLogicValue() function_ref=double)
(binary_expr implicit type='Bool' nothrow
(dot_syntax_call_expr implicit type='(Int, Int) -> Bool' nothrow
(declref_expr implicit type='(Int.Type) -> (Int, Int) -> Bool' decl=Swift.(file).Int.== function_ref=unapplied)
(type_expr implicit type='Int.Type' typerepr='<<NULL>>'))
(tuple_expr implicit type='(Int, Int)'
(member_ref_expr implicit type='Int' decl=eq.(file).Puppy.age@eq.swift:3:7 direct_to_storage
(declref_expr implicit type='Puppy' decl=eq.(file).Puppy.__derived_struct_equals(_:_:).a function_ref=unapplied))
(member_ref_expr implicit type='Int' decl=eq.(file).Puppy.age@eq.swift:3:7 direct_to_storage
(declref_expr implicit type='Puppy' decl=eq.(file).Puppy.__derived_struct_equals(_:_:).b function_ref=unapplied)))))
(tuple_expr implicit type='()'))
(brace_stmt
(return_stmt implicit
(call_expr implicit type='Bool' nothrow arg_labels=_builtinBooleanLiteral:
(constructor_ref_call_expr implicit type='(Int1) -> Bool' nothrow
(declref_expr implicit type='(Bool.Type) -> (Int1) -> Bool' decl=Swift.(file).Bool.init(_builtinBooleanLiteral:) function_ref=single)
(type_expr implicit type='Bool.Type' typerepr='<<NULL>>'))
(tuple_expr implicit type='(_builtinBooleanLiteral: Builtin.Int1)' names=_builtinBooleanLiteral
(boolean_literal_expr implicit type='Builtin.Int1' value=false))))))
(return_stmt implicit
(call_expr implicit type='Bool' nothrow arg_labels=_builtinBooleanLiteral:
(constructor_ref_call_expr implicit type='(Int1) -> Bool' nothrow
(declref_expr implicit type='(Bool.Type) -> (Int1) -> Bool' decl=Swift.(file).Bool.init(_builtinBooleanLiteral:) function_ref=single)
(type_expr implicit type='Bool.Type' typerepr='<<NULL>>'))
(tuple_expr implicit type='(_builtinBooleanLiteral: Builtin.Int1)' names=_builtinBooleanLiteral
(boolean_literal_expr implicit type='Builtin.Int1' value=true))))))
// static Puppy.__derived_struct_equals(_:_:)
sil hidden @_T02eq5PuppyV23__derived_struct_equalsSbAC_ACtFZ : $@convention(method) (@owned Puppy, @owned Puppy, @thin Puppy.Type) -> Bool {
// %0 // users: %34, %15, %7, %3
// %1 // users: %33, %16, %9, %4
// %2 // user: %5
bb0(%0 : $Puppy, %1 : $Puppy, %2 : $@thin Puppy.Type):
debug_value %0 : $Puppy, let, name "a", argno 1 // id: %3
debug_value %1 : $Puppy, let, name "b", argno 2 // id: %4
debug_value %2 : $@thin Puppy.Type, let, name "self", argno 3 // id: %5
%6 = metatype $@thin String.Type // user: %12
%7 = struct_extract %0 : $Puppy, #Puppy.name // users: %12, %8
retain_value %7 : $String // id: %8
%9 = struct_extract %1 : $Puppy, #Puppy.name // users: %12, %10
retain_value %9 : $String // id: %10
// function_ref static String.== infix(_:_:)
%11 = function_ref @_T0SS2eeoiSbSS_SStFZ : $@convention(method) (@owned String, @owned String, @thin String.Type) -> Bool // user: %12
%12 = apply %11(%7, %9, %6) : $@convention(method) (@owned String, @owned String, @thin String.Type) -> Bool // user: %13
%13 = struct_extract %12 : $Bool, #Bool._value // user: %14
cond_br %13, bb1, bb4 // id: %14
bb1: // Preds: bb0
%15 = struct_extract %0 : $Puppy, #Puppy.age // user: %17
%16 = struct_extract %1 : $Puppy, #Puppy.age // user: %18
%17 = struct_extract %15 : $Int, #Int._value // user: %19
%18 = struct_extract %16 : $Int, #Int._value // user: %19
%19 = builtin "cmp_eq_Int64"(%17 : $Builtin.Int64, %18 : $Builtin.Int64) : $Builtin.Int1 // user: %20
%20 = struct $Bool (%19 : $Builtin.Int1) // user: %21
%21 = struct_extract %20 : $Bool, #Bool._value // user: %22
cond_br %21, bb2, bb3 // id: %22
bb2: // Preds: bb1
%23 = integer_literal $Builtin.Int1, -1 // user: %24
%24 = struct $Bool (%23 : $Builtin.Int1) // user: %25
br bb5(%24 : $Bool) // id: %25
bb3: // Preds: bb1
%26 = integer_literal $Builtin.Int1, 0 // user: %27
%27 = struct $Bool (%26 : $Builtin.Int1) // user: %28
br bb5(%27 : $Bool) // id: %28
bb4: // Preds: bb0
%29 = integer_literal $Builtin.Int1, 0 // user: %30
%30 = struct $Bool (%29 : $Builtin.Int1) // user: %31
br bb5(%30 : $Bool) // id: %31
// %32 // user: %35
bb5(%32 : $Bool): // Preds: bb2 bb3 bb4
release_value %1 : $Puppy // id: %33
release_value %0 : $Puppy // id: %34
return %32 : $Bool // id: %35
} // end sil function '_T02eq5PuppyV23__derived_struct_equalsSbAC_ACtFZ'
struct Puppy: Equatable {
let name: String
let age: Int
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment