Comments (10)
Would you know if we were tracking anything related to this? This crash seems to be fixed in 6.0…
I could not find anything similar enough. It seems so — I cannot get it to crash either.
As for workarounds, indirection does the job, as it often does:
private struct FnBox<T> {
let fn: () -> T
}
struct Repeater<each Element> {
private let _elements: (repeat FnBox<each Element>)
var elements: (repeat () -> each Element) {
return (repeat (each _elements).fn)
}
init(elements element: repeat @escaping () -> each Element) {
self._elements = (repeat FnBox(fn: each element))
}
func printElements() {
print((repeat (each elements)()))
}
}
let repeater = Repeater(elements: { 2 }, { "" }, { true })
repeater.printElements()
from swift.
Dear first-time contributors, this only needs an IRGen test case. Here is a minimal crash reproduction for Swift 5.10:
struct Foo<each T> {
let tuple: (repeat () -> each T)
}
func test(_: Foo<Int>) {} // Boom
// func test(_: Foo<Int, Int>) {} // No boom
from swift.
I was unable to repro the crash with this example from
Xcode_15.4.0
andswiftlang-5.10.0.13 clang-1500.3.9.4
.
I confirmed the crash with the godbolt.org 5.10 compiler. Does it reproduce in your terminal? Try
echo 'struct Foo<each T> {let tuple: (repeat () -> each T)};func test(_: Foo<Int>) {}' | swiftc -emit-ir -
where swiftc
is your 5.10 compiler.
from swift.
Godbolt looks like it is running on Intel. I am running on Apple Silicon.
Ok, this is starting to make more sense. A x86_64-apple-macosx14.0
5.10 asserts compiler downloaded from Swift.org hits an LLVM assertion:
Assertion failed: (isa<To>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file Casting.h, line 578.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0. Program arguments: /Users/mac/Library/Developer/Toolchains/swift-5.10-DEVELOPMENT-SNAPSHOT-2024-05-31-a.xctoolchain/usr/bin/swift-frontend -frontend -emit-ir -primary-file - -target x86_64-apple-macosx14.0 -enable-objc-interop -color-diagnostics -new-driver-path /Users/mac/Library/Developer/Toolchains/swift-5.10-DEVELOPMENT-SNAPSHOT-2024-05-31-a.xctoolchain/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /Users/mac/Library/Developer/Toolchains/swift-5.10-DEVELOPMENT-SNAPSHOT-2024-05-31-a.xctoolchain/usr/lib/swift -module-name main -plugin-path /Users/mac/Library/Developer/Toolchains/swift-5.10-DEVELOPMENT-SNAPSHOT-2024-05-31-a.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Users/mac/Library/Developer/Toolchains/swift-5.10-DEVELOPMENT-SNAPSHOT-2024-05-31-a.xctoolchain/usr/local/lib/swift/host/plugins -o -
1. Apple Swift version 5.10-dev (LLVM e98989b1092ff3a, Swift 0e5cb27c42ec3c7)
2. Compiling with the current language version
3. While evaluating request IRGenRequest(IR Generation for file "<stdin>")
4. While evaluating request ExecuteSILPipelineRequest(Run pipelines { IRGen Preparation } on SIL for main)
5. While running pass #4 SILModuleTransform "LoadableByAddress".
6. While converting type 'Foo<Int>' (declared at [<stdin>:1:1 - line:1:53] RangeText="struct Foo<each T> {let tuple: (repeat () -> each T)")
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 0x000000010f02fb8b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 43
1 swift-frontend 0x000000010f02eed5 llvm::sys::RunSignalHandlers() + 85
2 swift-frontend 0x000000010f0301be SignalHandler(int) + 270
3 libsystem_platform.dylib 0x00007ff80d870fdd _sigtramp + 29
4 swift-frontend 0x000000010ac8e9b2 profileParams(llvm::FoldingSetNodeID&, llvm::ArrayRef<swift::AnyFunctionType::Param>) + 34
5 libsystem_c.dylib 0x00007ff80d767a79 abort + 126
6 libsystem_c.dylib 0x00007ff80d766d68 err + 0
7 swift-frontend 0x000000010f410b63 swift::Lowering::AbstractionPattern::getNumFunctionParams() const (.cold.5) + 35
8 swift-frontend 0x000000010a485e58 swift::Lowering::AbstractionPattern::getNumFunctionParams() const + 104
9 swift-frontend 0x000000010a486024 swift::Lowering::FunctionParamGenerator::FunctionParamGenerator(swift::Lowering::AbstractionPattern, swift::ArrayRefView<swift::AnyFunctionType::Param, swift::AnyFunctionType::CanParam, swift::AnyFunctionType::CanParam::getFromParam(swift::AnyFunctionType::Param const&), true>, bool) + 212
10 swift-frontend 0x000000010a488aa1 (anonymous namespace)::SubstFunctionTypePatternVisitor::handleUnabstractedFunctionType(swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern) + 177
11 swift-frontend 0x000000010a488607 swift::Lowering::AbstractionPattern::getSubstFunctionTypePattern(swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::TypeConverter&, swift::Lowering::AbstractionPattern, swift::CanType, bool&) const + 503
12 swift-frontend 0x000000010a4d6a93 getSILFunctionType(swift::Lowering::TypeConverter&, swift::TypeExpansionContext, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::SILExtInfoBuilder, (anonymous namespace)::Conventions const&, swift::ForeignInfo const&, llvm::Optional<swift::SILDeclRef>, llvm::Optional<swift::SILDeclRef>, llvm::Optional<swift::SubstitutionMap>, swift::ProtocolConformanceRef) + 6339
13 swift-frontend 0x000000010a4cbfba getNativeSILFunctionType(swift::Lowering::TypeConverter&, swift::TypeExpansionContext, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::SILExtInfoBuilder, llvm::Optional<swift::SILDeclRef>, llvm::Optional<swift::SILDeclRef>, llvm::Optional<swift::SubstitutionMap>, swift::ProtocolConformanceRef) + 1546
14 swift-frontend 0x000000010a578165 swift::Lowering::TypeConverter::computeLoweredRValueType(swift::TypeExpansionContext, swift::Lowering::AbstractionPattern, swift::CanType)::LoweredRValueTypeVisitor::visitAnyFunctionType(swift::CanTypeWrapper<swift::AnyFunctionType>) + 901
15 swift-frontend 0x000000010a5641b4 swift::Lowering::TypeConverter::getTypeLowering(swift::Lowering::AbstractionPattern, swift::Type, swift::TypeExpansionContext) + 900
16 swift-frontend 0x000000010a558c11 swift::SILType::getFieldType(swift::VarDecl*, swift::Lowering::TypeConverter&, swift::TypeExpansionContext) const + 241
17 swift-frontend 0x0000000109a56a74 swift::irgen::TypeConverter::convertStructType(swift::TypeBase*, swift::CanType, swift::StructDecl*) + 1140
18 swift-frontend 0x0000000109a7e751 swift::irgen::TypeConverter::convertAnyNominalType(swift::CanType, swift::NominalTypeDecl*) + 417
19 swift-frontend 0x0000000109a7ce81 swift::irgen::TypeConverter::convertType(swift::CanType) + 289
20 swift-frontend 0x0000000109a7c6e0 swift::irgen::TypeConverter::getTypeEntry(swift::CanType) + 768
21 swift-frontend 0x0000000109b2a351 isLargeLoadableType(swift::GenericEnvironment*, swift::SILType, swift::irgen::IRGenModule&) + 289
22 swift-frontend 0x0000000109b295bb LargeSILTypeMapper::getNewSILType(swift::GenericEnvironment*, swift::SILType, swift::irgen::IRGenModule&) + 459
23 swift-frontend 0x0000000109b3c4ba (anonymous namespace)::LoadableStorageAllocation::allocateLoadableStorage() + 1258
24 swift-frontend 0x0000000109b2b671 (anonymous namespace)::LoadableByAddress::run() + 849
25 swift-frontend 0x0000000109feeac1 swift::SILPassManager::runModulePass(unsigned int) + 865
26 swift-frontend 0x0000000109ff174b swift::SILPassManager::execute() + 619
27 swift-frontend 0x0000000109feb638 swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 72
28 swift-frontend 0x0000000109feb5b1 swift::ExecuteSILPipelineRequest::evaluate(swift::Evaluator&, swift::SILPipelineExecutionDescriptor) const + 65
29 swift-frontend 0x000000010a02bf5d swift::SimpleRequest<swift::ExecuteSILPipelineRequest, std::__1::tuple<> (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&) + 29
30 swift-frontend 0x000000010a006489 llvm::Expected<swift::ExecuteSILPipelineRequest::OutputType> swift::Evaluator::getResultUncached<swift::ExecuteSILPipelineRequest>(swift::ExecuteSILPipelineRequest const&) + 233
31 swift-frontend 0x0000000109feb7e2 swift::executePassPipelinePlan(swift::SILModule*, swift::SILPassPipelinePlan const&, bool, swift::irgen::IRGenModule*) + 82
32 swift-frontend 0x0000000109a98dee swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 2590
33 swift-frontend 0x0000000109af3fcf swift::GeneratedModule swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::callDerived<0ul>(swift::Evaluator&, std::__1::integer_sequence<unsigned long, 0ul>) const + 223
34 swift-frontend 0x0000000109af3eae swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenRequest const&, swift::Evaluator&) + 14
35 swift-frontend 0x0000000109aa58d6 llvm::Expected<swift::IRGenRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenRequest>(swift::IRGenRequest const&) + 246
36 swift-frontend 0x0000000109a9b717 swift::performIRGeneration(swift::FileUnit*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::GlobalVariable**) + 311
37 swift-frontend 0x0000000109550444 generateIR(swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, llvm::GlobalVariable*&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>) + 180
38 swift-frontend 0x000000010954bc5e performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 1566
39 swift-frontend 0x000000010954ae06 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 806
40 swift-frontend 0x000000010955db5f withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 143
41 swift-frontend 0x000000010954dc17 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 935
42 swift-frontend 0x000000010954c9c0 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3136
43 swift-frontend 0x00000001093f1370 swift::mainEntry(int, char const**) + 1648
44 dyld 0x00007ff80d4b6366 start + 1942
Abort trap: 6
Since neither yours nor the Godbolt 5.10 compilers hit an assertion, they must be no-asserts compilers. Without this assertion to terminate the program we get a memory access violation, which appears to not be deterministically caught by Apple Silicon in contrast to x86_64
.
from swift.
@AnthonyLatsis Would you know if we were tracking anything related to this? This crash seems to be fixed in 6.0… but I don't know if someone landed a fix to this issue directly or this fix came along implicitly with a fix for a different issue. Were there any related 5.10 workarounds to another issue that might workaround this one before 6.0 ships? Thanks!
from swift.
@slavapestov Do you remember if we were tracking anything similar to this in 5.10? Do you know if we documented any workarounds to compile that code from 5.10? Thanks!
from swift.
Dear first-time contributors, this only needs an IRGen test case. Here is a minimal crash reproduction for Swift 5.10:
struct Foo<each T> { let tuple: (repeat () -> each T) } func test(_: Foo<Int>) {} // Boom // func test(_: Foo<Int, Int>) {} // No boom
@AnthonyLatsis Hmm… I was unable to repro the crash with this example from Xcode_15.4.0
and swiftlang-5.10.0.13 clang-1500.3.9.4
. Are there are any specific parameters I should be passing to the compiler for that for producing the crash?
from swift.
Would you know if we were tracking anything related to this? This crash seems to be fixed in 6.0…
I could not find anything similar enough. It seems so — I cannot get it to crash either.
As for workarounds, indirection does the job, as it often does:
private struct FnBox<T> { let fn: () -> T } struct Repeater<each Element> { private let _elements: (repeat FnBox<each Element>) var elements: (repeat () -> each Element) { return (repeat (each _elements).fn) } init(elements element: repeat @escaping () -> each Element) { self._elements = (repeat FnBox(fn: each element)) } func printElements() { print((repeat (each elements)())) } } let repeater = Repeater(elements: { 2 }, { "" }, { true }) repeater.printElements()
Ahh… it looks like this works for me for 5.10 and unblocks my original use-case. Thanks!
from swift.
'struct Foo<each T> {let tuple: (repeat () -> each T)};func test(_: Foo<Int>) {}'
https://gist.github.com/vanvoorden/aa279eb43920870f70dac07343c5fcc2
Hmm… I tried this locally and don't see a crash in here. Godbolt looks like it is running on Intel. I am running on Apple Silicon. Would that have something to do with it?
from swift.
@AnthonyLatsis For some reason this workaround seems to lead to some Global is external, but doesn't have external or weak linkage!
crashes. I am unblocked with the workarounds from #75405.
from swift.
Related Issues (20)
- source compatibility project vapor_routing fails with compile error
- source compatibility project Deferred fails with a compiler error
- source compatibility project violet fails with a compiler error HOT 1
- source compatibility project penny-bot fails with a compiler error HOT 1
- Runtime crash: 'freed pointer was not the last allocation'
- Swift 6 includes swift format sub command but does not list it
- 6.0 conformance regression with abstract type witness HOT 1
- Improve dynamic actor isolation diagnostics HOT 1
- Incorrect `key.modulename` of constructor in Cursor Info
- TaskLocal.withValue typed throws
- False positive warning about closure isolation but only when not using trailing closure syntax
- False positive warning about closure isolation but only when argument label is omitted HOT 1
- Combination of sending generic + isolated(any) results in demangling failure
- Use of TaskLocal seems to defeat sending
- Function argument labels escape when using curried application in SequenceExpr
- Pattern that the region based isolation checker does not understand how to check. Please file a bug
- Appending a writable/sendable key path loses writability HOT 3
- Pattern that the region based isolation checker does not understand how to check. Please file a bug.
- False positive `requires_generic_param_made_equal_to_concrete`
- [stdlib] Update the `gen-unicode-data` package
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swift.