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. mysql workbench快捷键

    注释/取消注释, ctrl+/   暂时不知道怎么设置(原配置是 ctrl+divide)格式化sql语句(美化sql语句), ctrl+b

  2. 性能-发挥ORACLE分区表

    ORACLE分区表发挥性能 http://www.cnblogs.com/zwl715/p/3962837.html 1.1 分区表PARTITION table 在ORACLE里如果遇到特别大的表, ...

  3. python-----群发图片

    使用wxpy库给3个人群发同一张图片 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2019/2/22 15:25 # @Author ...

  4. silverlight 4中datagrid列标题和列内容居中问题,增加自增长列

    转载:http://www.cnblogs.com/guoyuanwei/archive/2011/01/02/1924163.html 命名空间:xmlns:Primitives="clr ...

  5. POJ2486 Apple Tree 【树上背包】

    一句话题意:一棵树,一共n个点,每个点上有一个权值,求从1出发,走k步,最多能遍历到的权值.可以往回走. 第一(二)道树上背包题,先是看了dalao的题解,改了一点就过样例了.然而....TLE??? ...

  6. mysql远程备份

    相关链接:https://blog.csdn.net/LiuHuan_study/article/details/81512831https://www.cnblogs.com/ryanzheng/p ...

  7. [POI2007]办公楼biu

    Description FGD开办了一家电话公司.他雇用了N个职员,给了每个职员一部手机.每个职员的手机里都存储有一些同事的电话号码.由于FGD的公司规模不断扩大,旧的办公楼已经显得十分狭窄,FGD决 ...

  8. 设置webbrowser浏览器内核

    var hklm = Microsoft.Win32.Registry.LocalMachine;            var lmRun64 = hklm.OpenSubKey(@"SO ...

  9. 关于jquery获取单选框value属性值为on的问题

    当取单选框的value值的时候,前提是要有value这个属性,如果没有value属性那么取出来的就会为on 取value值的常见三种方式为 $("input[name='XXX']:chec ...

  10. Linux之测试服务器和端口连通

    目录 wget工具 telnet工具 ssh工具 wget工具: 该工具是网络自动下载工具,如果linux或centos中不存在,需要先安装,支持http.https.ftp协议,wget名称的由来是 ...