Files
Akira Hatanaka 154d2267b8 [ObjC] Emit number, array, and dictionary literals as constants (#185130)
When targeting runtimes that support constant literal classes, emit ObjC
literal expressions @(number), @[], and @{} as compile-time constant
data structures rather than runtime msgSend calls. This reduces code
size and runtime overhead at the cost of increased data segment size,
and avoids repeated heap allocation of equivalent literal objects.

The feature is not supported with the fragile ABI or GNU runtimes, where
it is automatically disabled.

The feature can be disabled altogether with -fno-objc-constant-literals,
or individually per literal kind:
  -fno-constant-nsnumber-literals
  -fno-constant-nsarray-literals
  -fno-constant-nsdictionary-literals

Custom backing class names can be specified via:
  -fconstant-array-class=<name>
  -fconstant-dictionary-class=<name>
  -fconstant-integer-number-class=<name>
  -fconstant-float-number-class=<name>
  -fconstant-double-number-class=<name>

rdar://45380392
rdar://168106035

---------

Co-authored-by: Ben D. Jones <bendjones@apple.com>
2026-03-25 15:03:14 -07:00
..