@@ -551,30 +551,35 @@ extension ExitTestConditionMacro {
551551 for macro: some FreestandingMacroExpansionSyntax ,
552552 in context: some MacroExpansionContext
553553 ) -> ExprSyntax {
554- let exitTestID : ( UInt64 , UInt64 )
555- if let sourceLocation = context. location ( of: macro, at: . afterLeadingTrivia, filePathMode: . fileID) ,
556- let fileID = sourceLocation. file. as ( StringLiteralExprSyntax . self) ? . representedLiteralValue,
557- let line = sourceLocation. line. as ( IntegerLiteralExprSyntax . self) ? . representedLiteralValue,
558- let column = sourceLocation. column. as ( IntegerLiteralExprSyntax . self) ? . representedLiteralValue {
559- // Hash the entire source location and store as many bits as possible in
560- // the resulting ID.
561- let stringValue = " \( fileID) : \( line) : \( column) "
562- exitTestID = SHA256 . hash ( stringValue. utf8) . withUnsafeBytes { sha256 in
563- sha256. loadUnaligned ( as: ( UInt64, UInt64) . self)
554+ withUnsafeTemporaryAllocation ( of: UInt64 . self, capacity: 4 ) { exitTestID in
555+ if let sourceLocation = context. location ( of: macro, at: . afterLeadingTrivia, filePathMode: . fileID) ,
556+ let fileID = sourceLocation. file. as ( StringLiteralExprSyntax . self) ? . representedLiteralValue,
557+ let line = sourceLocation. line. as ( IntegerLiteralExprSyntax . self) ? . representedLiteralValue,
558+ let column = sourceLocation. column. as ( IntegerLiteralExprSyntax . self) ? . representedLiteralValue {
559+ // Hash the entire source location and store the entire hash in the
560+ // resulting ID.
561+ let stringValue = " \( fileID) : \( line) : \( column) "
562+ exitTestID. withMemoryRebound ( to: UInt8 . self) { exitTestID in
563+ _ = exitTestID. initialize ( from: SHA256 . hash ( stringValue. utf8) )
564+ }
565+ } else {
566+ // This branch is dead code in production, but is used when we expand a
567+ // macro in our own unit tests because the macro expansion context does
568+ // not have real source location information.
569+ for i in 0 ..< exitTestID. count {
570+ exitTestID [ i] = . random( in: 0 ... . max)
571+ }
564572 }
565- } else {
566- // This branch is dead code in production, but is used when we expand a
567- // macro in our own unit tests because the macro expansion context does
568- // not have real source location information.
569- exitTestID. 0 = . random( in: 0 ... . max)
570- exitTestID. 1 = . random( in: 0 ... . max)
571- }
572573
573- // Return a tuple of integer literals (which is what the runtime __store()
574- // function is expecting.)
575- return """
576- ( \( IntegerLiteralExprSyntax ( exitTestID. 0 , radix: . hex) ) , \( IntegerLiteralExprSyntax ( exitTestID. 1 , radix: . hex) ) )
577- """
574+ // Return a tuple of integer literals (which is what the runtime __store()
575+ // function is expecting.)
576+ let tupleExpr = TupleExprSyntax {
577+ for uint64 in exitTestID {
578+ LabeledExprSyntax ( expression: IntegerLiteralExprSyntax ( uint64, radix: . hex) )
579+ }
580+ }
581+ return ExprSyntax ( tupleExpr)
582+ }
578583 }
579584}
580585
0 commit comments