Skip to content

Instantly share code, notes, and snippets.

View gottesmm's full-sized avatar

Michael Gottesman gottesmm

  • Apple, Inc.
  • San Francisco, CA
View GitHub Profile
#!/bin/bash
set -e
if [[ $# -lt 1 ]]; then
echo "Not enough arguments?!"
echo "$0 <hash1> ... <hashN>"
exit 1
fi
@gottesmm
gottesmm / example.swift
Created June 13, 2018 17:27
Guaranteed vs Owned
// # Why +0 is a better default than +1 for "normal function arguments".
//
// My intention here is to show why +0 is better default in a resilient
// word. Keep in mind that inside individual modules and with inlinable
// declarations, the optimizer can change conventions at will so from a defaults
// perspective, these are not interesting. The interesting case is calling
// non-inlinable functions in other modules.
//
// Consider a situation where I have a class Klass and a function foo that calls
// a function bar in a different module.
func foo() {
var x: (Int, Int)
x.0 = 0
print(x.0) // <--- This works
let capture = {
print(x.0) // <--- This doesn't
}
}
## // xcrun clang++ test.cpp -O3 -o - -S -std=c++11 -mavx
.section __TEXT,__text,regular,pure_instructions
.macosx_version_min 10, 13
.globl __Z7equalP2PDv8_tDv16_h ## -- Begin function _Z7equalP2PDv8_tDv16_h
.p2align 4, 0x90
__Z7equalP2PDv8_tDv16_h: ## @_Z7equalP2PDv8_tDv16_h
.cfi_startproc
## BB#0:
pushq %rbp
import Foundation
typealias CallbackBlock = @convention (block) () -> Void
func main() -> CallbackBlock {
let handler: CallbackBlock = { print("yes") }
let x = NSMutableDictionary()
x["foo"] = handler
let handler2 = x["foo"] as! CallbackBlock
return handler2