Skip to content

Instantly share code, notes, and snippets.

View Azoy's full-sized avatar
:shipit:

Alejandro Alonso Azoy

:shipit:
View GitHub Profile
@Azoy
Azoy / atomics.md
Last active May 5, 2024 22:44
Low-Level Atomic Operations
extension KeyPathObject: CustomStringConvertible {
public var description: String {
let components = self.components
assert(heapObject.metadata.kind == .class,
"KeyPath class object that's not a class?")
let classMetadata = heapObject.metadata as! ClassMetadata
assert(classMetadata.genericTypes.count == 2,
"KeyPath type without 2 generic types? Root and Leaf?")
let root = classMetadata.genericTypes[0]

Tuples Conform to Equatable, Comparable, and Hashable

  • Proposal: SE-NNNN
  • Author: Alejandro Alonso
  • Review Manager: TBD
  • Status: Awaiting review
  • Implementation Equatable: apple/swift#28833
  • Implementation Comparable: Coming Soon
  • Implementation Hashable: Coming Soon
@Azoy
Azoy / nnnn-demangle.md
Last active March 1, 2020 20:43
Demangle Function
@Azoy
Azoy / nnnn-parameterized-extensions.md
Last active June 11, 2019 01:28
Parameterized Extensions
@Azoy
Azoy / float80->32->16.sil
Created January 21, 2019 08:27
Float16(Float(_builtinFloatLiteral: value))
sil_stage canonical
import Builtin
import Swift
import SwiftShims
func x()
// main
sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
@Azoy
Azoy / float80->16.sil
Created January 21, 2019 08:20
Float16(Float80(value))
sil_stage canonical
import Builtin
import Swift
import SwiftShims
func x()
// main
sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
@Azoy
Azoy / syscall.swift
Last active August 25, 2023 21:49
Raw system calls in Swift
// macOS x86_64 syscall works as follows:
// Syscall id is moved into rax
// 1st argument is moved into rdi
// 2nd argument is moved into rsi
// 3rd argument is moved into rdx
// ... plus some more
// Return value is stored in rax (where we put syscall value)
// Mac syscall enum that contains the value to correctly call it
enum Syscall: Int {
@Azoy
Azoy / day1.swift
Last active December 2, 2018 08:04
Advent of Code 2018
// Part one
let input = """
"""
print(input.split(separator: "\n").map {
Int($0)!
}.reduce(0, +))
// Part Two
@Azoy
Azoy / memberwise-init.md
Last active October 19, 2018 03:32
State of the Memberwise Initializer

State of the Memberwise Initializer

Prolog

Hello Evolution,

I want to discuss where we are with the current memberwise initializer for structures and where I wish to see this initializer evolve.

Refer to SE-0018 and SE-0018 Rationale. I do not speak for the author here, but I'm rathering pulling ideas and references from SE-0018 to formulate this post.