@@ -628,7 +628,7 @@ Some additional meaningful categories of type:
628
628
629
629
- A *heap object reference * type is a type whose representation consists of a
630
630
single strong-reference-counted pointer. This includes all class types,
631
- the ``Builtin.NativeObject `` and ``Builtin.UnknownObject `` types, and
631
+ the ``Builtin.NativeObject `` and ``AnyObject `` types, and
632
632
archetypes that conform to one or more class protocols.
633
633
- A *reference type * is more general in that its low-level representation may
634
634
include additional global pointers alongside a strong-reference-counted
@@ -734,7 +734,7 @@ The following types are considered layout-compatible:
734
734
``B `` and a derived class ``D `` inheriting from ``B ``, a value of
735
735
type ``B `` referencing an instance of type ``D `` is layout compatible with
736
736
both ``B `` and ``D ``, as well as ``Builtin.NativeObject `` and
737
- ``Builtin.UnknownObject ``. It is not layout compatible with an unrelated class
737
+ ``AnyObject ``. It is not layout compatible with an unrelated class
738
738
type ``E ``.
739
739
- For payloaded enums, the payload type of the first payloaded case is
740
740
layout-compatible with the enum (*not * commutatively).
@@ -1034,11 +1034,14 @@ VTables
1034
1034
sil-vtable-entry ::= sil-decl-ref ':' sil-linkage? sil-function-name
1035
1035
1036
1036
SIL represents dynamic dispatch for class methods using the `class_method `_,
1037
- `super_method `_, and `dynamic_method `_ instructions. The potential destinations
1038
- for these dispatch operations are tracked in ``sil_vtable `` declarations for
1039
- every class type. The declaration contains a mapping from every method of the
1040
- class (including those inherited from its base class) to the SIL function that
1041
- implements the method for that class::
1037
+ `super_method `_, `objc_method `_, `objc_super_method `_ and `dynamic_method `_
1038
+ instructions.
1039
+
1040
+ The potential destinations for `class_method `_ and `super_method `_ are
1041
+ tracked in ``sil_vtable `` declarations for every class type. The declaration
1042
+ contains a mapping from every method of the class (including those inherited
1043
+ from its base class) to the SIL function that implements the method for that
1044
+ class::
1042
1045
1043
1046
class A {
1044
1047
func foo()
@@ -1592,9 +1595,9 @@ typed, so aliasing of classes is constrained by the type system as follows:
1592
1595
including a Swift class instance, a box allocated by ``alloc_box ``,
1593
1596
or a thick function's closure context.
1594
1597
It may not alias natively Objective-C class instances.
1595
- * A ``Builtin.UnknownObject `` or ``Builtin.BridgeObject `` may alias
1596
- any class instance, whether Swift or Objective-C, but may not alias
1597
- non-class-instance heap objects.
1598
+ * An ``AnyObject `` or ``Builtin.BridgeObject `` may alias any class instance,
1599
+ whether Swift or Objective-C, but may not alias non-class-instance
1600
+ heap objects.
1598
1601
* Two values of the same class type ``$C `` may alias. Two values of related
1599
1602
class type ``$B `` and ``$D ``, where there is a subclass relationship between
1600
1603
``$B `` and ``$D ``, may alias. Two values of unrelated class types may not
@@ -2937,24 +2940,19 @@ method name segment.
2937
2940
Dynamic Dispatch
2938
2941
~~~~~~~~~~~~~~~~
2939
2942
2940
- These instructions perform dynamic lookup of class and generic methods. They
2941
- share a common set of attributes::
2943
+ These instructions perform dynamic lookup of class and generic methods.
2942
2944
2943
- sil-method-attributes ::= '[' 'volatile'? ']'
2945
+ The ``class_method `` and ``super_method `` instructions must reference
2946
+ Swift native methods and always use vtable dispatch.
2944
2947
2945
- The ``volatile `` attribute on a dynamic dispatch instruction indicates that
2946
- the method lookup is semantically required (as, for example, in Objective-C).
2947
- When the type of a dynamic dispatch instruction's operand is known,
2948
- optimization passes can promote non-``volatile `` dispatch instructions
2949
- into static ``function_ref `` instructions.
2948
+ The ``objc_method ``, ``objc_super_method `` and ``dynamic_method ``
2949
+ instructions must reference Objective-C methods (indicated by the
2950
+ ``foreign `` marker on a method reference, as in
2951
+ ``#NSObject.description!1.foreign ``).
2950
2952
2951
- If a dynamic dispatch instruction references an Objective-C method
2952
- (indicated by the ``foreign `` marker on a method reference, as in
2953
- ``#NSObject.description!1.foreign ``), then the instruction
2954
- represents an ``objc_msgSend `` invocation. ``objc_msgSend `` invocations can
2955
- only be used as the callee of an ``apply `` instruction or ``partial_apply ``
2956
- instruction. They cannot be stored or used as ``apply `` or ``partial_apply ``
2957
- arguments. ``objc_msgSend `` invocations must always be ``volatile ``.
2953
+ Note that ``objc_msgSend `` invocations can only be used as the callee
2954
+ of an ``apply `` instruction or ``partial_apply `` instruction. They cannot
2955
+ be stored or used as ``apply `` or ``partial_apply `` arguments.
2958
2956
2959
2957
class_method
2960
2958
````````````
@@ -2963,30 +2961,55 @@ class_method
2963
2961
sil-instruction ::= 'class_method' sil-method-attributes?
2964
2962
sil-operand ',' sil-decl-ref ':' sil-type
2965
2963
2966
- %1 = class_method %0 : $T, #T.method!1 : $@convention(thin ) U -> V
2964
+ %1 = class_method %0 : $T, #T.method!1 : $@convention(class_method ) U -> V
2967
2965
// %0 must be of a class type or class metatype $T
2968
- // #T.method!1 must be a reference to a dynamically-dispatched method of T or
2969
- // of one of its superclasses, at uncurry level > = 1
2966
+ // #T.method!1 must be a reference to a Swift native method of T or
2967
+ // of one of its superclasses, at uncurry level = = 1
2970
2968
// %1 will be of type $U -> V
2971
2969
2972
2970
Looks up a method based on the dynamic type of a class or class metatype
2973
- instance. It is undefined behavior if the class value is null and the
2974
- method is not an Objective-C method.
2971
+ instance. It is undefined behavior if the class value is null.
2975
2972
2976
- If:
2973
+ If the static type of the class instance is known, or the method is known
2974
+ to be final, then the instruction is a candidate for devirtualization
2975
+ optimization. A devirtualization pass can consult the module's `VTables `_
2976
+ to find the SIL function that implements the method and promote the
2977
+ instruction to a static `function_ref `_.
2977
2978
2978
- - the instruction is not ``[volatile] ``,
2979
- - the referenced method is not a ``foreign `` method,
2980
- - and the static type of the class instance is known, or the method is known
2981
- to be final,
2979
+ objc_method
2980
+ ```````````
2981
+ ::
2982
2982
2983
- then the instruction is a candidate for devirtualization optimization. A
2984
- devirtualization pass can consult the module's `VTables `_ to find the
2985
- SIL function that implements the method and promote the instruction to a
2986
- static `function_ref `_.
2983
+ sil-instruction ::= 'objc_method' sil-method-attributes?
2984
+ sil-operand ',' sil-decl-ref ':' sil-type
2985
+
2986
+ %1 = objc_method %0 : $T, #T.method!1.foreign : $@convention(objc_method) U -> V
2987
+ // %0 must be of a class type or class metatype $T
2988
+ // #T.method!1 must be a reference to an Objective-C method of T or
2989
+ // of one of its superclasses, at uncurry level == 1
2990
+ // %1 will be of type $U -> V
2991
+
2992
+ Performs Objective-C method dispatch using ``objc_msgSend() ``.
2993
+
2994
+ Objective-C method calls are never candidates for devirtualization.
2987
2995
2988
2996
super_method
2989
2997
````````````
2998
+ ::
2999
+
3000
+ sil-instruction ::= 'super_method' sil-method-attributes?
3001
+ sil-operand ',' sil-decl-ref ':' sil-type
3002
+
3003
+ %1 = super_method %0 : $T, #Super.method!1 : $@convention(thin) U -> V
3004
+ // %0 must be of a non-root class type or class metatype $T
3005
+ // #Super.method!1 must be a reference to a native Swift method of T's
3006
+ // superclass or of one of its ancestor classes, at uncurry level >= 1
3007
+ // %1 will be of type $@convention(thin) U -> V
3008
+
3009
+ Looks up a method in the superclass of a class or class metatype instance.
3010
+
3011
+ objc_super_method
3012
+ `````````````````
2990
3013
::
2991
3014
2992
3015
sil-instruction ::= 'super_method' sil-method-attributes?
@@ -2998,11 +3021,8 @@ super_method
2998
3021
// superclass or of one of its ancestor classes, at uncurry level >= 1
2999
3022
// %1 will be of type $@convention(thin) U -> V
3000
3023
3001
- Looks up a method in the superclass of a class or class metatype instance.
3002
- Note that for native Swift methods, ``super.method `` calls are statically
3003
- dispatched, so this instruction is only valid for Objective-C methods.
3004
- It is undefined behavior if the class value is null and the method is
3005
- not an Objective-C method.
3024
+ This instruction performs an Objective-C message send using
3025
+ ``objc_msgSuper() ``.
3006
3026
3007
3027
witness_method
3008
3028
``````````````
@@ -3040,13 +3060,13 @@ dynamic_method
3040
3060
// or protocol type
3041
3061
//
3042
3062
// The "self" argument of the method type $@convention(thin) U -> V must be
3043
- // Builtin.UnknownObject
3063
+ // AnyObject
3044
3064
3045
3065
Looks up the implementation of an Objective-C method with the same
3046
3066
selector as the named method for the dynamic type of the
3047
3067
value inside an existential container. The "self" operand of the result
3048
3068
function value is represented using an opaque type, the value for which must
3049
- be projected out as a value of type ``Builtin.UnknownObject ``.
3069
+ be projected out as a value of type ``AnyObject ``.
3050
3070
3051
3071
It is undefined behavior if the dynamic type of the operand does not
3052
3072
have an implementation for the Objective-C method with the selector to
@@ -4363,7 +4383,7 @@ ref_to_raw_pointer
4363
4383
sil-instruction ::= 'ref_to_raw_pointer' sil-operand 'to' sil-type
4364
4384
4365
4385
%1 = ref_to_raw_pointer %0 : $C to $Builtin.RawPointer
4366
- // $C must be a class type, or Builtin.NativeObject, or Builtin.UnknownObject
4386
+ // $C must be a class type, or Builtin.NativeObject, or AnyObject
4367
4387
// %1 will be of type $Builtin.RawPointer
4368
4388
4369
4389
Converts a heap object reference to a ``Builtin.RawPointer ``. The ``RawPointer ``
@@ -4378,7 +4398,7 @@ raw_pointer_to_ref
4378
4398
sil-instruction ::= 'raw_pointer_to_ref' sil-operand 'to' sil-type
4379
4399
4380
4400
%1 = raw_pointer_to_ref %0 : $Builtin.RawPointer to $C
4381
- // $C must be a class type, or Builtin.NativeObject, or Builtin.UnknownObject
4401
+ // $C must be a class type, or Builtin.NativeObject, or AnyObject
4382
4402
// %1 will be of type $C
4383
4403
4384
4404
Converts a ``Builtin.RawPointer `` back to a heap object reference. Casting
0 commit comments