@@ -126,6 +126,13 @@ extension Regex {
126
126
/// A program representation that caches any lowered representation for
127
127
/// execution.
128
128
internal final class Program {
129
+
130
+ // This stored property should be stored at offset zero. We perform atomic
131
+ // operations on it.
132
+ //
133
+ /// Do not access this property directly - all accesses must go through `_loweredProgramStoragePtr `.
134
+ fileprivate var _loweredProgramStorage : AnyObject ? = nil
135
+
129
136
/// The underlying IR.
130
137
///
131
138
/// FIXME: If Regex is the unit of composition, then it should be a Node instead,
@@ -141,14 +148,16 @@ extension Regex {
141
148
init ( _ value: MEProgram ) { self . value = value }
142
149
}
143
150
144
- /// Do not use directly - all accesses must go through `loweredProgram`.
145
- fileprivate var _loweredProgramStorage : AnyObject ? = nil
146
-
151
+ fileprivate var _loweredProgramStoragePtr : UnsafeMutablePointer < AnyObject ? > {
152
+ _getUnsafePointerToStoredProperties ( self )
153
+ . assumingMemoryBound ( to: Optional< AnyObject> . self )
154
+ }
155
+
147
156
/// The program for execution with the matching engine.
148
157
var loweredProgram : MEProgram {
149
158
/// Atomically loads the compiled program if it has already been stored.
150
159
func loadProgram( ) -> MEProgram ? {
151
- guard let loweredObject = _stdlib_atomicLoadARCRef ( object: & _loweredProgramStorage )
160
+ guard let loweredObject = _stdlib_atomicLoadARCRef ( object: _loweredProgramStoragePtr )
152
161
else { return nil }
153
162
return unsafeDowncast ( loweredObject, to: ProgramBox . self) . value
154
163
}
@@ -161,7 +170,7 @@ extension Regex {
161
170
// Compile the DSLTree into a lowered program and store it atomically.
162
171
let compiledProgram = try ! Compiler ( tree: tree, compileOptions: compileOptions) . emit ( )
163
172
let storedNewProgram = _stdlib_atomicInitializeARCRef (
164
- object: & _loweredProgramStorage ,
173
+ object: _loweredProgramStoragePtr ,
165
174
desired: ProgramBox ( compiledProgram) )
166
175
167
176
// Return the winner of the storage race. We're guaranteed at this point
0 commit comments