Skip to content

SwiftSyntax crashes macro expansion when the macro depends on package that imports SwiftSyntax #9196

@stansmida

Description

@stansmida

Description

SwiftSyntax crashes in macro CompilerPlugin when the macro depends on package that imports SwiftSyntax.

SwiftCompile normal arm64 Compiling\ main.swift /Users/stan/Desktop/CrashingSwiftSyntax/CrashingMacro/Sources/CrashingMacroClient/main.swift (in target 'CrashingMacroClient' from project 'CrashingMacro')

Simultaneous accesses to 0x80b000c68, but modification requires exclusive access.
Previous access (a modification) started at CrashingMacroMacros`ParsingRawSyntaxArena.sourceBuffer.modify + 40 (0x103032d04).
Current access (a read) started at:
0    libswiftCore.dylib                 0x00000001977876f4 swift::runtime::AccessSet::insert(swift::runtime::Access*, void*, void*, swift::ExclusivityFlags) + 476
1    libswiftCore.dylib                 0x0000000197787988 swift_beginAccess + 84
2    CrashingMacroMacros                0x00000001030333d8 ParsingRawSyntaxArena.sourceBufferContains(_:) + 92
3    CrashingMacroMacros                0x00000001030332e0 ParsingRawSyntaxArena.contains(text:) + 128
4    CrashingMacroMacros                0x0000000103029348 implicit closure swiftlang/swift-syntax#1 in static RawSyntax.parsedToken(kind:wholeText:textRange:presence:tokenDiagnostic:arena:) + 52
5    CrashingMacroMacros                0x0000000103018c7c assert(_:_:file:line:) + 92
6    CrashingMacroMacros                0x0000000103029110 static RawSyntax.parsedToken(kind:wholeText:textRange:presence:tokenDiagnostic:arena:) + 256
7    CrashingMacroMacros                0x0000000103038304 RawTokenSyntax.init(kind:wholeText:textRange:presence:tokenDiagnostic:arena:) + 120
8    CrashingMacroMacros                0x00000001038b1148 Parser.expect(_:) + 1240
9    CrashingMacroMacros                0x0000000103878a5c Parser.parsePrimaryExpression(pattern:flavor:) + 1452
10   CrashingMacroMacros                0x00000001038762a4 Parser.parseUnaryExpression(flavor:pattern:) + 556
11   CrashingMacroMacros                0x0000000103873b88 Parser.parseSequenceExpressionElement(flavor:pattern:) + 696
12   CrashingMacroMacros                0x0000000103873150 Parser.parseSequenceExpression(flavor:pattern:) + 72
13   CrashingMacroMacros                0x0000000103870774 Parser.parseExpression(flavor:pattern:) + 124
14   CrashingMacroMacros                0x000000010388a8a4 static ExprSyntax.parse(from:) + 36
15   CrashingMacroMacros                0x00000001038122e0 specialized ParsedSyntaxRegistry.parse(source:kind:) + 152
16   CrashingMacroMacros                0x0000000103810f34 SourceManager.add(_:foldingWith:) + 472
17   CrashingMacroMacros                0x000000010380ef7c specialized PluginProviderMessageHandler.expandFreestandingMacro(macro:macroRole:discriminator:expandingSyntax:lexicalContext:) + 200
18   CrashingMacroMacros                0x00000001037f243c PluginProviderMessageHandler.handleMessage(_:) + 604
19   CrashingMacroMacros                0x00000001037f28c0 protocol witness for PluginMessageHandler.handleMessage(_:) in conformance PluginProviderMessageHandler<A> + 20
20   CrashingMacroMacros                0x00000001037f2120 CompilerPluginMessageListener.handleNextMessage() + 204
21   CrashingMacroMacros                0x00000001037f20d0 CompilerPluginMessageListener.main() + 28
22   CrashingMacroMacros                0x00000001037f0b38 static CompilerPlugin.main() + 364
23   CrashingMacroMacros                0x0000000102ffdb84 static CrashingMacroPlugin.$main() + 44
24   CrashingMacroMacros                0x0000000102ffdcf4 main + 28
25   dyld                               0x0000000184284144 start + 7184
Fatal access conflict detected.

Steps to Reproduce

Toolchain: Xcode 26.0.1

  1. Create new library and macro package.
  2. Have the library depend on SwiftSyntax.
  3. Have the macro depend on the library.
  4. Build the macro client - crash.

You can try the crashing example at https://github.com/stansmida/crashing-swift-syntax

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions