Open
Description
Description
No response
Reproduction
For e.g:
import SwiftSyntax
import SwiftSyntaxMacros
public struct SetterMacro: AccessorMacro, Macro {
public static func expansion(
of node: AttributeSyntax,
providingAccessorsOf declaration: some DeclSyntaxProtocol,
in context: some MacroExpansionContext
) throws -> [AccessorDeclSyntax] {
return [
"""
set {
}
""",
]
}
}
and:
@attached(accessor)
macro setterMacro() =
#externalMacro(module: "MacroDefinition", type: "SetterMacro")
struct S {
var _storage = 0
@setterMacro
subscript() -> Int {
get { _storage }
}
}
var s = S()
s[] = 0
an assertion is hit in SILGen:
Assertion failed: (method->getDeclContext()->isTypeContext()), function isNonMutatingSelfIndirect, file SILGenApply.cpp, line 5361.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0. Program arguments: ./swift -frontend -c /Users/hamish/src/swift-test-arena/main.swift -sdk /Users/hamish/src/MacOSX.sdk -debug-diagnostic-names -load-plugin-library libMacroDefinition.dylib -o /tmp/foo.o
1. Swift version 5.11-dev (LLVM 572a5a4fbafb69e, Swift 3b38e15427d68f0)
2. Compiling with the current language version
3. While evaluating request ASTLoweringRequest(Lowering AST to SIL for module foo)
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0 swift-frontend 0x0000000109bbf2f4 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1 swift-frontend 0x0000000109bbd6ac llvm::sys::RunSignalHandlers() + 112
2 swift-frontend 0x0000000109bbf988 SignalHandler(int) + 352
3 libsystem_platform.dylib 0x00000001829a5a24 _sigtramp + 56
4 libsystem_pthread.dylib 0x0000000182976cc0 pthread_kill + 288
5 libsystem_c.dylib 0x0000000182886a50 abort + 180
6 libsystem_c.dylib 0x0000000182885d6c err + 0
7 swift-frontend 0x0000000109cb208c swift::Lowering::SILGenFunction::emitApply(std::__1::unique_ptr<swift::Lowering::ResultPlan, std::__1::default_delete<swift::Lowering::ResultPlan>>&&, swift::Lowering::ArgumentScope&&, swift::SILLocation, swift::Lowering::ManagedValue, swift::SubstitutionMap, llvm::ArrayRef<swift::Lowering::ManagedValue>, swift::Lowering::CalleeTypeInfo const&, swift::optionset::OptionSet<swift::ApplyFlags, unsigned char>, swift::Lowering::SGFContext, std::__1::optional<swift::ActorIsolation>) (.cold.1) + 0
8 swift-frontend 0x0000000104a1bc20 swift::Lowering::SILGenModule::isNonMutatingSelfIndirect(swift::SILDeclRef) + 328
9 swift-frontend 0x0000000104aa30fc getBaseAccessKind(swift::Lowering::SILGenModule&, swift::AbstractStorageDecl*, swift::Lowering::SGFAccessKind, swift::AccessStrategy, swift::CanType) + 176
10 swift-frontend 0x0000000104aa3430 SILGenLValue::visitSubscriptExpr(swift::SubscriptExpr*, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions) + 372
11 swift-frontend 0x0000000104a9f390 swift::Lowering::SILGenFunction::emitLValue(swift::Expr*, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions) + 56
12 swift-frontend 0x0000000104a858f4 (anonymous namespace)::RValueEmitter::visitAssignExpr(swift::AssignExpr*, swift::Lowering::SGFContext) + 956
13 swift-frontend 0x0000000104a71c6c swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 896
14 swift-frontend 0x0000000104af4440 swift::Lowering::SILGenTopLevel::visitTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 220
15 swift-frontend 0x0000000104af3b00 swift::Lowering::SILGenTopLevel::visitSourceFile(swift::SourceFile*) + 100
16 swift-frontend 0x0000000104af33ac swift::Lowering::SILGenModule::emitEntryPoint(swift::SourceFile*, swift::SILFunction*) + 776
17 swift-frontend 0x0000000104af3e14 swift::Lowering::SILGenModule::emitEntryPoint(swift::SourceFile*) + 212
18 swift-frontend 0x0000000104a13d98 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 828
19 swift-frontend 0x0000000104ae88f4 swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>> (swift::ASTLoweringDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) + 132
20 swift-frontend 0x0000000104a171c4 llvm::Expected<swift::ASTLoweringRequest::OutputType> swift::Evaluator::getResultUncached<swift::ASTLoweringRequest>(swift::ASTLoweringRequest const&) + 380
21 swift-frontend 0x0000000104a1440c swift::performASTLowering(swift::ModuleDecl*, swift::Lowering::TypeConverter&, swift::SILOptions const&, swift::IRGenOptions const*) + 128
22 swift-frontend 0x00000001044423b4 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1112
23 swift-frontend 0x00000001044529c8 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 160
24 swift-frontend 0x0000000104444618 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 692
25 swift-frontend 0x00000001044436b8 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2316
26 swift-frontend 0x00000001042d6420 swift::mainEntry(int, char const**) + 2176
27 dyld 0x00000001825fd058 start + 2224
fish: Job 1, './swift -frontend -c ~/src/swif…' terminated by signal SIGABRT (Abort)
Expected behavior
It should build
Environment
Swift version 5.11-dev (LLVM 572a5a4fbafb69e, Swift 3b38e15)
Target: arm64-apple-macosx14.0
Additional information
No response
Metadata
Metadata
Assignees
Labels
Area → compiler: The SIL generation stageBug → crash: An assertion failureA deviation from expected or documented behavior. Also: expected but undesirable behavior.The Swift compiler itselfBug: A crash, i.e., an abnormal termination of softwareFeature: declarationsFeature: Subscript declarationsFeature → declarations: Swift `macro` declarations