Commit Graph

9 Commits

Author SHA1 Message Date
Erik Eckstein
ccc691cc42 ObjectOutliner: try outline alloc_refs in multiple iterations to handle multi-dimensional arrays
This allows to completely statically allocate multi-dimensional global arrays, like
```
var x = [[1, 2], [3, 4], [5, 6]]
```
2024-05-17 17:03:07 +02:00
Erik Eckstein
af68435d90 Optimizer: support static initialization of global arrays
The buffer of global arrays could already be statically initialized.
The missing piece was the array itself, which is basically a reference to the array buffer.
For example:
```
var a = [1, 2, 3]
```
ends up in two statically initialized globals:
1. the array buffer, which contains the elements
2. the variable `a` which is a single reference (= pointer) of the array buffer

This optimization removes the need for lazy initialization of such variables.

rdar://127757554
2024-05-16 21:34:36 +02:00
Erik Eckstein
524d1a5a3e tests: fix readonly_arrays test
rdar://121866611
2024-01-31 10:52:19 +01:00
Erik Eckstein
e4ea7491a2 IRGen: fix and re-enable static read-only arrays
Static read-only arrays didn't work when passed to ObjectiveC as NSArray.
The storage class of static read-only arrays doesn't carry information about the Element type.
The new `__SwiftDeferredStaticNSArray` is generic over the element type and doesn't have to rely on the element type information of the array storage.

rdar://94185998
2023-12-13 11:45:01 +01:00
Erik Eckstein
eb5aa89e95 tests: temporarily disable SILOptimizer/readonly_arrays.swift
This is a followup of https://github.com/apple/swift/pull/61830
2022-11-02 08:01:48 +01:00
Erik Eckstein
662a051941 fix the readonly_arrays.swift test
Also, add a comment for the changed metadata symbol name for static read-only arrays.
2022-09-28 17:32:33 +02:00
Erik Eckstein
24d077e78b IRGen: re-enable generate static arrays in read-only data sections.
So far, static arrays had to be put into a writable section, because the isa pointer and the (immortal) ref count field were initialized dynamically at the first use of such an array.

But with a new runtime library, which exports the symbols for the (immortal) ref count field and the isa pointer, it's possible to put the whole array into a read-only section. I.e. make it a constant global.

rdar://94185998

This reverts the revert commit df353ff3c0.
Also, I added a frontend option to disable this optimization: `-disable-readonly-static-objects`
2022-06-21 18:30:42 +02:00
Erik Eckstein
df353ff3c0 Revert "IRGen: generate static arrays in read-only data sections."
This reverts commit aca0d8358b.

I need to fix a problem before this can actually land.
2022-06-17 20:32:32 +02:00
Erik Eckstein
aca0d8358b IRGen: generate static arrays in read-only data sections.
So far, static arrays had to be put into a writable section, because the isa pointer and the (immortal) ref count field were initialized dynamically at the first use of such an array.

But with a new runtime library, which exports the symbols for the (immortal) ref count field and the isa pointer, it's possible to put the whole array into a read-only section. I.e. make it a constant global.

rdar://94185998
2022-06-17 11:21:29 +02:00