Skip to content

Add experimental support for fixed arrays #70301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Dec 11, 2023
Merged

Conversation

eeckstein
Copy link
Contributor

This mainly consists of a builtin _allocateVector which is lowered to a stack allocated vector (expressed with the new SIL instruction alloc_vector) or - if used in an initializer of a global variable - to a statically initialized vector in a global.

A new pass AllocVectorLowering is doing this transformation.

All this is still experimental and must be enabled with -enable-experimental-feature FixedArrays. A lot of pieces are still missing to make this a usable feature, e.g. non-escapable types.

I added a prototype of FixedArray as a test file. It shows how the builtin can be used to implement fixed arrays or similar data structures.

@eeckstein eeckstein requested review from phausler, lorentey, kubamracek, atrick and meg-gupta and removed request for a team, xedin, slavapestov, hborla and tshortli December 7, 2023 17:20
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein
Copy link
Contributor Author

@swift-ci benchmark

@eeckstein
Copy link
Contributor Author

@swift-ci please build toolchain

* `createAddressToPointer`
* `createLoadBorrow`
* `Context.moduleIsSerialized`
* `Context.getBuiltinIntegerType`
* `Instruction.move(before:)`
* `alloc_vector`: allocates an uninitialized vector of elements on the stack or in a statically initialized global
* `vector`: creates an initialized vector in a statically initialized global
…lySite.isSemanticCall`

`Value.isValidGlobalInitValue` was privately used by the ObjectOutliner. Make it a generally usable utility.
So far the semantic annotation was just added to the internal `_getCount` function.
But for FixedArray it is also required to add the `@_semantics("array.get_count")` to the public API.
By default it lowers the builtin to an `alloc_vector` with a paired `dealloc_stack`.
If the builtin appears in the initializer of a global variable and the vector elements are initialized,
a statically initialized global is created where the initializer is a `vector` instruction.
@eeckstein
Copy link
Contributor Author

@swift-ci smoke test

@eeckstein eeckstein merged commit 484fc77 into swiftlang:main Dec 11, 2023
@eeckstein eeckstein deleted the fixed-array branch December 11, 2023 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants