Support for number, array, and dictionary constant literal optimization #136
Labels
No labels
Arch
AMD64
Arch
m68k
Arch/PowerPC64
Bug
Documentation
Duplicate
Feature
Infeasible
Invalid
Nice to Have
ObjC++
ofarc
ofhttp
OS
AmigaOS
OS
FreeBSD
OS
Linux
OS
macOS
OS
Windows
Out of Scope
Question
Runtime
Security
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
ObjFW/ObjFW#136
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
A recent Clang PR adds support for emitting ObjC literal expressions —
@(number),@[], and@{}— as compile-time constant data structures instead of runtime message lookup calls, when the target runtime supports it.As with constant string literals (
-fconstant-string-class=), the backing classes for the other literal kinds can be customized via:The feature is gated behind
-fno-objc-constant-literalsand is automatically disabled for the fragile ABI and GNU runtimes, since it relies onObjCRuntime::hasConstantLiteralClasses()in Clang, which currently only recognizes Apple's runtimes.Question / request: Would it make sense for the ObjFW runtime to support this? Concretely, that would mean getting Clang to recognize ObjFW as a runtime with constant literal support, and having ObjFW provide the corresponding backing classes (something like
OFConstantArray,OFConstantDictionary,OFConstantNumber, or similar) so the optimization can actually kick in.Is this something you'd be open to supporting?
Please tell me if implementing this will also help fixing #56. Thank you all.
This was in the proprietary Apple Clang for a while, so it's great to see that it also made it into the open source Clang.
I'm not sure how I feel about needing to specify every class separately. On the one hand, this is better than how it was done previously, where
-fobjc-runtime=appleimplied Foundation. OTOH, I think a-fobjc-framework=objfwflag would be better, as the framework and the runtime are different things that are not necessarily the same.That said, this is probably a good idea, as it's right now the best way to avoid the hacks needed so far because Foundation is hardcoded. So as a side effect it will probably also address #56.
Yes, the
-fobjc-framework=objfwflag sounds like a good choice for setting the default framework to something other than Foundation, while still allowing each class to be specified individually. That flexibility is especially useful for those who want to use their ownString,Number,Array, orDictionaryclasses along with the ObjFW runtime.As for #56, unlike constant string literals, this optimization may not fully address the issue, since there are cases where boxed or collection literals cannot be compile-time constants. For example,
@(pow(a, b))or@[[[MyObject alloc] init], /* ... */].Perhaps with
-fobjc-framework=objfw, we could also make the previously hard-codedNSString,NSNumber,NSArray, andNSDictionaryclasses configurable.Yes, that would be the idea, as the current hack is fragile and doesn't work anymore with modern C++, as modern C++ implies ObjC modules in Clang, which are incompatible with the hack as it requires defines.