VTables

https://github.com/apple/swift/blob/master/docs/SIL.rst#vtables

decl ::= sil-vtable

sil-vtable ::= 'sil_vtable' identifier '{' sil-vtable-entry* '}'

sil-vtable-entry ::= sil-decl-ref ':' sil-linkage? sil-function-name

SIL represents dynamic dispatch for class methods using the class_method, super_method, objc_method, and objc_super_method instructions.

The potential destinations for class_method and super_method are tracked in sil_vtable declarations for every class type. The declaration contains a mapping from every method of the class (including those inherited from its base class) to the SIL function that implements the method for that class:

class A {

func foo()

func bar()

func bas()

}

sil @A_foo : $@convention(thin) (@owned A) -> ()

sil @A_bar : $@convention(thin) (@owned A) -> ()

sil @A_bas : $@convention(thin) (@owned A) -> ()

sil_vtable A {

#A.foo!1: @A_foo

#A.bar!1: @A_bar

#A.bas!1: @A_bas

}

class B : A {

func bar()

}

sil @B_bar : $@convention(thin) (@owned B) -> ()

sil_vtable B {

#A.foo!1: @A_foo

#A.bar!1: @B_bar

#A.bas!1: @A_bas

}

class C : B {

func bas()

}

sil @C_bas : $@convention(thin) (@owned C) -> ()

sil_vtable C {

#A.foo!1: @A_foo

#A.bar!1: @B_bar

#A.bas!1: @C_bas

}

Note that the declaration reference in the vtable is to the least-derived method visible through that class (in the example above, B's vtable references A.bar and not B.bar, and C's vtable references A.bas and not C.bas). The Swift AST maintains override relationships between declarations that can be used to look up overridden methods in the SIL vtable for a derived class (such as C.bas in C's vtable).

In case the SIL function is a thunk, the function name is preceded with the linkage of the original implementing function.

swift VTables的更多相关文章

  1. Swift Method Dispatching — a summary of my talk at Swift Warsaw

    Swift Method Dispatching When announcing Swift, Apple described it as being much faster than Objecti ...

  2. iOS代码规范(OC和Swift)

    下面说下iOS的代码规范问题,如果大家觉得还不错,可以直接用到项目中,有不同意见 可以在下面讨论下. 相信很多人工作中最烦的就是代码不规范,命名不规范,曾经见过一个VC里有3个按钮被命名为button ...

  3. Swift与C#的基础语法比较

    背景: 这两天不小心看了一下Swift的基础语法,感觉既然看了,还是写一下笔记,留个痕迹~ 总体而言,感觉Swift是一种前后端多种语言混合的产物~~~ 做为一名.NET阵营人士,少少多多总喜欢通过对 ...

  4. iOS开发系列--Swift语言

    概述 Swift是苹果2014年推出的全新的编程语言,它继承了C语言.ObjC的特性,且克服了C语言的兼容性问题.Swift发展过程中不仅保留了ObjC很多语法特性,它也借鉴了多种现代化语言的特点,在 ...

  5. 算法与数据结构(十七) 基数排序(Swift 3.0版)

    前面几篇博客我们已经陆陆续续的为大家介绍了7种排序方式,今天博客的主题依然与排序算法相关.今天这篇博客就来聊聊基数排序,基数排序算法是不稳定的排序算法,在排序数字较小的情况下,基数排序算法的效率还是比 ...

  6. 算法与数据结构(十五) 归并排序(Swift 3.0版)

    上篇博客我们主要聊了堆排序的相关内容,本篇博客,我们就来聊一下归并排序的相关内容.归并排序主要用了分治法的思想,在归并排序中,将我们需要排序的数组进行拆分,将其拆分的足够小.当拆分的数组中只有一个元素 ...

  7. Swift enum(枚举)使用范例

    //: Playground - noun: a place where people can play import UIKit var str = "Hello, playground& ...

  8. swift开发新项目总结

    新项目用swift3.0开发,现在基本一个月,来总结一下遇到的问题及解决方案   1,在确定新项目用swift后,第一个考虑的问题是用纯swift呢?还是用swift跟OC混编      考虑到新项目 ...

  9. swift 中关于open ,public ,fileprivate,private ,internal,修饰的说明

    关于 swift 中的open ,public ,fileprivate,private, internal的区别 以下按照修饰关键字的访问约束范围 从约束的限定范围大到小的排序进行说明 open,p ...

随机推荐

  1. keywords和favicon

    1.<meta name="keywords" content="xxx"> 曾经网站风靡关键词堆积,往往在首页上设置大量的关键词,以获取最大范围搜 ...

  2. 设计模式-(8)外观(swift版)

    一,概念 为子系统中的一组接口提供一个统一的接口.外观模式定义了一个更高层次的接口,这个接口使得这一子系统更加容易使用. 二,结构图 (1)SubSystem子系统类:每个子系统定义了相关功能和模块的 ...

  3. beego07----web博客

    conf/app.conf appname = blog1 httpport = 8080 runmode = dev name=admin pwd=admin controllersmy/attac ...

  4. YTU 2913: 距离产生美

    2913: 距离产生美 时间限制: 1 Sec  内存限制: 128 MB 提交: 152  解决: 133 题目描述 小明和静静是大学同学,毕业后要去两个不同的城市工作.小明要静静做他的女朋友,静静 ...

  5. echo 到 stderr

    This question is old, but you could do this, which facilitates reading: >&2 echo "error& ...

  6. java 类属性、方法加载的顺序

    1.静态变量 2.静态代码块 3.局部代码块 4.构造函数 5.普通代码块 6.静态方法 7.普通方法 8.普通属性

  7. aapt的常用命令

    1. 列出apk包的内容 aapt l[ist] [-v] [-a] file.{zip,jar,apk} -v 以table形式列出来 -a 详细列出内容 例如:aapt l <你的apk文件 ...

  8. codeforces 682C C. Alyona and the Tree(dfs)

    题目链接: C. Alyona and the Tree time limit per test 1 second memory limit per test 256 megabytes input ...

  9. 【HAOI2007】反素数

    [题目链接] 点击打开链接 [算法] 稍加分析可知,问题等价于“求1到n中,因子个数最多的数,若有多个,求最小的” 那么我们该怎么求这个数呢? 约数个数定理 : x = p1^a1p2^a2p3^a3 ...

  10. splay启发式合并

    3545: [ONTAK2010]Peaks Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1889  Solved: 501[Submit][Sta ...