Skip to content

Instantly share code, notes, and snippets.

Created November 4, 2016 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/275823bd74fdb339bc04aa8ea95440ac to your computer and use it in GitHub Desktop.
Save anonymous/275823bd74fdb339bc04aa8ea95440ac to your computer and use it in GitHub Desktop.
ObservableProperty
SOURCE:
struct ObservableProperty {
var variable: Int {
willSet {
print(self.variable)
}
didSet {
print(self.variable)
print(oldValue)
}
}
mutating func function() {
self.variable = 1
}
}
SWIFTC:
swiftc -dump-ast ObservableProperty.swift
AST:
(source_file
(struct_decl "ObservableProperty" type='ObservableProperty.Type' access=internal @_fixed_layout
(pattern_binding_decl
(pattern_typed type='Int'
(pattern_named type='Int' 'variable')
(type_ident
(component id='Int' bind=Swift.(file).Int))))
(var_decl "variable" type='Int' access=internal storage_kind=stored_with_observers
(func_decl implicit 'anonname=0x7f8b2a0a73d0' type='(ObservableProperty) -> () -> Int' access=internal getter_for=variable
(parameter_list
(parameter "self" type='ObservableProperty'))
(parameter_list)
(result
(type_ident
(component id='Int' bind=none)))
(brace_stmt
(return_stmt
(member_ref_expr implicit type='Int' decl=ObservableProperty.(file).ObservableProperty.variable@ObservableProperty.swift:10:9 direct_to_storage
(declref_expr implicit type='ObservableProperty' decl=ObservableProperty.(file).ObservableProperty.func decl.self specialized=no)))))
(func_decl implicit 'anonname=0x7f8b2a0a7670' type='(inout ObservableProperty) -> (Int) -> ()' access=internal setter_for=variable
(parameter_list
(parameter "self" type='inout ObservableProperty' mutable))
(parameter_list
(parameter "newValue" type='Int'))
(brace_stmt
(pattern_binding_decl implicit
(pattern_named implicit type='Int' 'tmp')
(load_expr implicit type='Int'
(member_ref_expr implicit type='@lvalue Int' accessKind=read decl=ObservableProperty.(file).ObservableProperty.variable@ObservableProperty.swift:10:9 direct_to_storage
(declref_expr implicit type='@lvalue ObservableProperty' accessKind=read decl=ObservableProperty.(file).ObservableProperty.func decl.self specialized=no))))
(var_decl implicit "tmp" type='Int' access=private let storage_kind=stored)
(call_expr implicit type='()' nothrow
(dot_syntax_call_expr implicit type='(Int) -> ()' nothrow
(declref_expr implicit type='(inout ObservableProperty) -> (Int) -> ()' decl=ObservableProperty.(file).ObservableProperty._@ObservableProperty.swift:11:9 specialized=no)
(inout_expr implicit type='inout ObservableProperty'
(declref_expr implicit type='@lvalue ObservableProperty' accessKind=readwrite decl=ObservableProperty.(file).ObservableProperty.func decl.self specialized=no)))
(declref_expr implicit type='Int' decl=ObservableProperty.(file).ObservableProperty.func decl.newValue@ObservableProperty.swift:11:9 specialized=no))
(assign_expr
(member_ref_expr implicit type='@lvalue Int' accessKind=write decl=ObservableProperty.(file).ObservableProperty.variable@ObservableProperty.swift:10:9 direct_to_storage
(declref_expr implicit type='@lvalue ObservableProperty' accessKind=readwrite decl=ObservableProperty.(file).ObservableProperty.func decl.self specialized=no))
(declref_expr implicit type='Int' decl=ObservableProperty.(file).ObservableProperty.func decl.newValue@ObservableProperty.swift:11:9 specialized=no))
(call_expr implicit type='()' nothrow
(dot_syntax_call_expr implicit type='(Int) -> ()' nothrow
(declref_expr implicit type='(inout ObservableProperty) -> (Int) -> ()' decl=ObservableProperty.(file).ObservableProperty._@ObservableProperty.swift:15:9 specialized=no)
(inout_expr implicit type='inout ObservableProperty'
(declref_expr implicit type='@lvalue ObservableProperty' accessKind=readwrite decl=ObservableProperty.(file).ObservableProperty.func decl.self specialized=no)))
(declref_expr implicit type='Int' decl=ObservableProperty.(file).ObservableProperty.func decl.tmp specialized=no))))
(func_decl implicit 'anonname=0x7f8b2a0afd00' type='(inout ObservableProperty) -> (Builtin.RawPointer, inout Builtin.UnsafeValueBuffer) -> (Builtin.RawPointer, (@convention(thin) (Builtin.RawPointer, inout Builtin.UnsafeValueBuffer, inout ObservableProperty, @thick ObservableProperty.Type) -> ())?)' access=internal materializeForSet_for=variable
(parameter_list
(parameter "self" type='inout ObservableProperty' mutable))
(parameter_list
(parameter "buffer" type='Builtin.RawPointer')
(parameter "callbackStorage" type='inout Builtin.UnsafeValueBuffer' mutable)))
(func_decl 'anonname=0x7f8b2a0a6b30' type='(inout ObservableProperty) -> (Int) -> ()' access=internal willset_for=variable
(parameter_list
(parameter "self" type='inout ObservableProperty' mutable))
(parameter_list
(parameter "newValue" type='Int'))
(brace_stmt
(call_expr type='()' location=ObservableProperty.swift:12:13 range=[ObservableProperty.swift:12:13 - line:12:32] nothrow
(declref_expr type='(Any..., separator: String, terminator: String) -> ()' location=ObservableProperty.swift:12:13 range=[ObservableProperty.swift:12:13 - line:12:13] decl=Swift.(file).print(_:separator:terminator:) specialized=no)
(tuple_shuffle_expr implicit type='(Any..., separator: String, terminator: String)' location=ObservableProperty.swift:12:24 range=[ObservableProperty.swift:12:18 - line:12:32] sourceIsScalar elements=[-2, -1, -1] variadic_sources=[0]
(paren_expr type='Any' location=ObservableProperty.swift:12:24 range=[ObservableProperty.swift:12:18 - line:12:32]
(erasure_expr implicit type='Any' location=ObservableProperty.swift:12:24 range=[ObservableProperty.swift:12:19 - line:12:24]
(load_expr implicit type='Int' location=ObservableProperty.swift:12:24 range=[ObservableProperty.swift:12:19 - line:12:24]
(member_ref_expr type='@lvalue Int' accessKind=read location=ObservableProperty.swift:12:24 range=[ObservableProperty.swift:12:19 - line:12:24] decl=ObservableProperty.(file).ObservableProperty.variable@ObservableProperty.swift:10:9 direct_to_storage
(declref_expr type='@lvalue ObservableProperty' accessKind=read location=ObservableProperty.swift:12:19 range=[ObservableProperty.swift:12:19 - line:12:19] decl=ObservableProperty.(file).ObservableProperty.func decl.self@ObservableProperty.swift:11:9 specialized=no)))))))))
(func_decl 'anonname=0x7f8b2a0a6fb0' type='(inout ObservableProperty) -> (Int) -> ()' access=internal didset_for=variable
(parameter_list
(parameter "self" type='inout ObservableProperty' mutable))
(parameter_list
(parameter "oldValue" type='Int'))
(brace_stmt
(call_expr type='()' location=ObservableProperty.swift:16:13 range=[ObservableProperty.swift:16:13 - line:16:32] nothrow
(declref_expr type='(Any..., separator: String, terminator: String) -> ()' location=ObservableProperty.swift:16:13 range=[ObservableProperty.swift:16:13 - line:16:13] decl=Swift.(file).print(_:separator:terminator:) specialized=no)
(tuple_shuffle_expr implicit type='(Any..., separator: String, terminator: String)' location=ObservableProperty.swift:16:24 range=[ObservableProperty.swift:16:18 - line:16:32] sourceIsScalar elements=[-2, -1, -1] variadic_sources=[0]
(paren_expr type='Any' location=ObservableProperty.swift:16:24 range=[ObservableProperty.swift:16:18 - line:16:32]
(erasure_expr implicit type='Any' location=ObservableProperty.swift:16:24 range=[ObservableProperty.swift:16:19 - line:16:24]
(load_expr implicit type='Int' location=ObservableProperty.swift:16:24 range=[ObservableProperty.swift:16:19 - line:16:24]
(member_ref_expr type='@lvalue Int' accessKind=read location=ObservableProperty.swift:16:24 range=[ObservableProperty.swift:16:19 - line:16:24] decl=ObservableProperty.(file).ObservableProperty.variable@ObservableProperty.swift:10:9 direct_to_storage
(declref_expr type='@lvalue ObservableProperty' accessKind=read location=ObservableProperty.swift:16:19 range=[ObservableProperty.swift:16:19 - line:16:19] decl=ObservableProperty.(file).ObservableProperty.func decl.self@ObservableProperty.swift:15:9 specialized=no)))))))
(call_expr type='()' location=ObservableProperty.swift:17:13 range=[ObservableProperty.swift:17:13 - line:17:27] nothrow
(declref_expr type='(Any..., separator: String, terminator: String) -> ()' location=ObservableProperty.swift:17:13 range=[ObservableProperty.swift:17:13 - line:17:13] decl=Swift.(file).print(_:separator:terminator:) specialized=no)
(tuple_shuffle_expr implicit type='(Any..., separator: String, terminator: String)' location=ObservableProperty.swift:17:19 range=[ObservableProperty.swift:17:18 - line:17:27] sourceIsScalar elements=[-2, -1, -1] variadic_sources=[0]
(paren_expr type='Any' location=ObservableProperty.swift:17:19 range=[ObservableProperty.swift:17:18 - line:17:27]
(erasure_expr implicit type='Any' location=ObservableProperty.swift:17:19 range=[ObservableProperty.swift:17:19 - line:17:19]
(declref_expr type='Int' location=ObservableProperty.swift:17:19 range=[ObservableProperty.swift:17:19 - line:17:19] decl=ObservableProperty.(file).ObservableProperty.func decl.oldValue@ObservableProperty.swift:15:9 specialized=no))))))))
(func_decl 'anonname=0x7f8b2a0a6b30' type='(inout ObservableProperty) -> (Int) -> ()' access=internal willset_for=variable
(parameter_list
(parameter "self" type='inout ObservableProperty' mutable))
(parameter_list
(parameter "newValue" type='Int'))
(brace_stmt
(call_expr type='()' location=ObservableProperty.swift:12:13 range=[ObservableProperty.swift:12:13 - line:12:32] nothrow
(declref_expr type='(Any..., separator: String, terminator: String) -> ()' location=ObservableProperty.swift:12:13 range=[ObservableProperty.swift:12:13 - line:12:13] decl=Swift.(file).print(_:separator:terminator:) specialized=no)
(tuple_shuffle_expr implicit type='(Any..., separator: String, terminator: String)' location=ObservableProperty.swift:12:24 range=[ObservableProperty.swift:12:18 - line:12:32] sourceIsScalar elements=[-2, -1, -1] variadic_sources=[0]
(paren_expr type='Any' location=ObservableProperty.swift:12:24 range=[ObservableProperty.swift:12:18 - line:12:32]
(erasure_expr implicit type='Any' location=ObservableProperty.swift:12:24 range=[ObservableProperty.swift:12:19 - line:12:24]
(load_expr implicit type='Int' location=ObservableProperty.swift:12:24 range=[ObservableProperty.swift:12:19 - line:12:24]
(member_ref_expr type='@lvalue Int' accessKind=read location=ObservableProperty.swift:12:24 range=[ObservableProperty.swift:12:19 - line:12:24] decl=ObservableProperty.(file).ObservableProperty.variable@ObservableProperty.swift:10:9 direct_to_storage
(declref_expr type='@lvalue ObservableProperty' accessKind=read location=ObservableProperty.swift:12:19 range=[ObservableProperty.swift:12:19 - line:12:19] decl=ObservableProperty.(file).ObservableProperty.func decl.self@ObservableProperty.swift:11:9 specialized=no)))))))))
(func_decl 'anonname=0x7f8b2a0a6fb0' type='(inout ObservableProperty) -> (Int) -> ()' access=internal didset_for=variable
(parameter_list
(parameter "self" type='inout ObservableProperty' mutable))
(parameter_list
(parameter "oldValue" type='Int'))
(brace_stmt
(call_expr type='()' location=ObservableProperty.swift:16:13 range=[ObservableProperty.swift:16:13 - line:16:32] nothrow
(declref_expr type='(Any..., separator: String, terminator: String) -> ()' location=ObservableProperty.swift:16:13 range=[ObservableProperty.swift:16:13 - line:16:13] decl=Swift.(file).print(_:separator:terminator:) specialized=no)
(tuple_shuffle_expr implicit type='(Any..., separator: String, terminator: String)' location=ObservableProperty.swift:16:24 range=[ObservableProperty.swift:16:18 - line:16:32] sourceIsScalar elements=[-2, -1, -1] variadic_sources=[0]
(paren_expr type='Any' location=ObservableProperty.swift:16:24 range=[ObservableProperty.swift:16:18 - line:16:32]
(erasure_expr implicit type='Any' location=ObservableProperty.swift:16:24 range=[ObservableProperty.swift:16:19 - line:16:24]
(load_expr implicit type='Int' location=ObservableProperty.swift:16:24 range=[ObservableProperty.swift:16:19 - line:16:24]
(member_ref_expr type='@lvalue Int' accessKind=read location=ObservableProperty.swift:16:24 range=[ObservableProperty.swift:16:19 - line:16:24] decl=ObservableProperty.(file).ObservableProperty.variable@ObservableProperty.swift:10:9 direct_to_storage
(declref_expr type='@lvalue ObservableProperty' accessKind=read location=ObservableProperty.swift:16:19 range=[ObservableProperty.swift:16:19 - line:16:19] decl=ObservableProperty.(file).ObservableProperty.func decl.self@ObservableProperty.swift:15:9 specialized=no)))))))
(call_expr type='()' location=ObservableProperty.swift:17:13 range=[ObservableProperty.swift:17:13 - line:17:27] nothrow
(declref_expr type='(Any..., separator: String, terminator: String) -> ()' location=ObservableProperty.swift:17:13 range=[ObservableProperty.swift:17:13 - line:17:13] decl=Swift.(file).print(_:separator:terminator:) specialized=no)
(tuple_shuffle_expr implicit type='(Any..., separator: String, terminator: String)' location=ObservableProperty.swift:17:19 range=[ObservableProperty.swift:17:18 - line:17:27] sourceIsScalar elements=[-2, -1, -1] variadic_sources=[0]
(paren_expr type='Any' location=ObservableProperty.swift:17:19 range=[ObservableProperty.swift:17:18 - line:17:27]
(erasure_expr implicit type='Any' location=ObservableProperty.swift:17:19 range=[ObservableProperty.swift:17:19 - line:17:19]
(declref_expr type='Int' location=ObservableProperty.swift:17:19 range=[ObservableProperty.swift:17:19 - line:17:19] decl=ObservableProperty.(file).ObservableProperty.func decl.oldValue@ObservableProperty.swift:15:9 specialized=no)))))))
(func_decl implicit 'anonname=0x7f8b2a0a73d0' type='(ObservableProperty) -> () -> Int' access=internal getter_for=variable
(parameter_list
(parameter "self" type='ObservableProperty'))
(parameter_list)
(result
(type_ident
(component id='Int' bind=none)))
(brace_stmt
(return_stmt
(member_ref_expr implicit type='Int' decl=ObservableProperty.(file).ObservableProperty.variable@ObservableProperty.swift:10:9 direct_to_storage
(declref_expr implicit type='ObservableProperty' decl=ObservableProperty.(file).ObservableProperty.func decl.self specialized=no)))))
(func_decl implicit 'anonname=0x7f8b2a0a7670' type='(inout ObservableProperty) -> (Int) -> ()' access=internal setter_for=variable
(parameter_list
(parameter "self" type='inout ObservableProperty' mutable))
(parameter_list
(parameter "newValue" type='Int'))
(brace_stmt
(pattern_binding_decl implicit
(pattern_named implicit type='Int' 'tmp')
(load_expr implicit type='Int'
(member_ref_expr implicit type='@lvalue Int' accessKind=read decl=ObservableProperty.(file).ObservableProperty.variable@ObservableProperty.swift:10:9 direct_to_storage
(declref_expr implicit type='@lvalue ObservableProperty' accessKind=read decl=ObservableProperty.(file).ObservableProperty.func decl.self specialized=no))))
(var_decl implicit "tmp" type='Int' access=private let storage_kind=stored)
(call_expr implicit type='()' nothrow
(dot_syntax_call_expr implicit type='(Int) -> ()' nothrow
(declref_expr implicit type='(inout ObservableProperty) -> (Int) -> ()' decl=ObservableProperty.(file).ObservableProperty._@ObservableProperty.swift:11:9 specialized=no)
(inout_expr implicit type='inout ObservableProperty'
(declref_expr implicit type='@lvalue ObservableProperty' accessKind=readwrite decl=ObservableProperty.(file).ObservableProperty.func decl.self specialized=no)))
(declref_expr implicit type='Int' decl=ObservableProperty.(file).ObservableProperty.func decl.newValue@ObservableProperty.swift:11:9 specialized=no))
(assign_expr
(member_ref_expr implicit type='@lvalue Int' accessKind=write decl=ObservableProperty.(file).ObservableProperty.variable@ObservableProperty.swift:10:9 direct_to_storage
(declref_expr implicit type='@lvalue ObservableProperty' accessKind=readwrite decl=ObservableProperty.(file).ObservableProperty.func decl.self specialized=no))
(declref_expr implicit type='Int' decl=ObservableProperty.(file).ObservableProperty.func decl.newValue@ObservableProperty.swift:11:9 specialized=no))
(call_expr implicit type='()' nothrow
(dot_syntax_call_expr implicit type='(Int) -> ()' nothrow
(declref_expr implicit type='(inout ObservableProperty) -> (Int) -> ()' decl=ObservableProperty.(file).ObservableProperty._@ObservableProperty.swift:15:9 specialized=no)
(inout_expr implicit type='inout ObservableProperty'
(declref_expr implicit type='@lvalue ObservableProperty' accessKind=readwrite decl=ObservableProperty.(file).ObservableProperty.func decl.self specialized=no)))
(declref_expr implicit type='Int' decl=ObservableProperty.(file).ObservableProperty.func decl.tmp specialized=no))))
(func_decl implicit 'anonname=0x7f8b2a0afd00' type='(inout ObservableProperty) -> (Builtin.RawPointer, inout Builtin.UnsafeValueBuffer) -> (Builtin.RawPointer, (@convention(thin) (Builtin.RawPointer, inout Builtin.UnsafeValueBuffer, inout ObservableProperty, @thick ObservableProperty.Type) -> ())?)' access=internal materializeForSet_for=variable
(parameter_list
(parameter "self" type='inout ObservableProperty' mutable))
(parameter_list
(parameter "buffer" type='Builtin.RawPointer')
(parameter "callbackStorage" type='inout Builtin.UnsafeValueBuffer' mutable)))
(func_decl "function()" type='(inout ObservableProperty) -> () -> ()' access=internal
(parameter_list
(parameter "self" type='inout ObservableProperty' mutable))
(parameter_list)
(brace_stmt
(assign_expr
(member_ref_expr type='@lvalue Int' accessKind=write location=ObservableProperty.swift:22:14 range=[ObservableProperty.swift:22:9 - line:22:14] decl=ObservableProperty.(file).ObservableProperty.variable@ObservableProperty.swift:10:9
(inout_expr implicit type='inout ObservableProperty' location=ObservableProperty.swift:22:9 range=[ObservableProperty.swift:22:9 - line:22:9]
(declref_expr type='@lvalue ObservableProperty' accessKind=readwrite location=ObservableProperty.swift:22:9 range=[ObservableProperty.swift:22:9 - line:22:9] decl=ObservableProperty.(file).ObservableProperty.func decl.self@ObservableProperty.swift:21:19 specialized=no)))
(call_expr implicit type='Int' location=ObservableProperty.swift:22:25 range=[ObservableProperty.swift:22:25 - line:22:25] nothrow
(constructor_ref_call_expr implicit type='(_builtinIntegerLiteral: Int2048) -> Int' location=ObservableProperty.swift:22:25 range=[ObservableProperty.swift:22:25 - line:22:25] nothrow
(declref_expr implicit type='Int.Type -> (_builtinIntegerLiteral: Int2048) -> Int' location=ObservableProperty.swift:22:25 range=[ObservableProperty.swift:22:25 - line:22:25] decl=Swift.(file).Int.init(_builtinIntegerLiteral:) specialized=no)
(type_expr implicit type='Int.Type' location=ObservableProperty.swift:22:25 range=[ObservableProperty.swift:22:25 - line:22:25] typerepr='Int'))
(tuple_expr implicit type='(_builtinIntegerLiteral: Int2048)' location=ObservableProperty.swift:22:25 range=[ObservableProperty.swift:22:25 - line:22:25] names=_builtinIntegerLiteral
(integer_literal_expr type='Int2048' location=ObservableProperty.swift:22:25 range=[ObservableProperty.swift:22:25 - line:22:25] value=1))))))
(constructor_decl implicit "init(variable:)" type='ObservableProperty.Type -> (variable: Int) -> ObservableProperty' access=internal designated
(parameter_list
(parameter "self" type='inout ObservableProperty' mutable))
(parameter_list
(parameter "variable" apiName=variable type='Int')))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment