Closed NachoSoto closed 2 months ago
@NachoSoto thanks for the report. What does your config.swift file look like?
Here you go:
--swiftversion 5.10
--self remove # redundantSelf
--importgrouping testable-bottom # sortedImports
--commas always # trailingCommas
--trimwhitespace always # trailingSpace
--indent 2 #indent
--ifdef no-indent #indent
--indentstrings true #indent
--wraparguments before-first # wrapArguments
--wrapparameters before-first # wrapArguments
--wrapcollections before-first # wrapArguments
--wrapconditions before-first # wrapArguments
--wrapreturntype if-multiline #wrapArguments
--wrapeffects if-multiline #wrapArguments
--closingparen same-line # wrapArguments
--wraptypealiases before-first # wrapArguments
--funcattributes prev-line # wrapAttributes
--computedvarattrs prev-line # wrapAttributes
--storedvarattrs same-line # wrapAttributes
--complexattrs prev-line # wrapAttributes
--typeattributes prev-line # wrapAttributes
--wrapternary before-operators # wrap
--structthreshold 20 # organizeDeclarations
--enumthreshold 20 # organizeDeclarations
--organizetypes class,struct,enum,extension,actor # organizeDeclarations
--extensionacl on-declarations # extensionAccessControl
--patternlet inline # hoistPatternLet
--redundanttype inferred # redundantType, propertyType
--emptybraces spaced # emptyBraces
--someAny disabled # opaqueGenericParameters
--elseposition same-line # elseOnSameLine
--guardelse next-line # elseOnSameLine
--onelineforeach convert # preferForLoop
--shortoptionals always # typeSugar
--semicolons never # semicolons
--doccomments preserve # docComments
--minversion 0.54.4
--typeblanklines remove # blankLinesAtStartOfScope, blankLinesAtEndOfScope
--maxwidth 130 # wrap
--rules anyObjectProtocol
--rules blankLinesBetweenScopes
--rules consecutiveSpaces
--rules duplicateImports
--rules extensionAccessControl
--rules hoistPatternLet
--rules indent
--rules markTypes
--rules organizeDeclarations
--rules redundantParens
--rules redundantReturn
--rules redundantSelf
--rules redundantType
--rules redundantPattern
--rules redundantGet
--rules redundantFileprivate
--rules redundantRawValues
--rules sortImports
--rules sortDeclarations
--rules strongifiedSelf
--rules trailingCommas
--rules trailingSpace
--rules typeSugar
--rules wrap
--rules wrapMultilineStatementBraces
--rules wrapArguments
--rules wrapAttributes
--rules braces
--rules redundantClosure
--rules redundantInit
--rules redundantVoidReturnType
--rules redundantOptionalBinding
--rules redundantInternal
--rules unusedArguments
--rules spaceInsideBrackets
--rules spaceInsideBraces
--rules spaceAroundBraces
--rules spaceInsideParens
--rules spaceAroundParens
--rules enumNamespaces
--rules blockComments
--rules docComments
--rules spaceAroundComments
--rules spaceInsideComments
--rules blankLinesAtStartOfScope
--rules blankLinesAtEndOfScope
--rules emptyBraces
--rules andOperator
--rules opaqueGenericParameters
--rules genericExtensions
--rules trailingClosures
--rules elseOnSameLine
--rules sortTypealiases
--rules preferForLoop
--rules conditionalAssignment
--rules wrapMultilineConditionalAssignment
--rules blankLineAfterSwitchCase
--rules consistentSwitchCaseSpacing
--rules semicolons
--rules blankLinesAroundMark
--rules consecutiveBlankLines
--rules isEmpty
--rules initCoderUnavailable
--rules modifierOrder
@NachoSoto for me, running this command:
swiftformat . --config config.swiftformat
with swiftformat 0.54.4, on a folder containing just the config above and a swift file with the contents:
// Some comment
if propertyA.x == nil {
self.propertyB = propertyA.y.z?.q
}
completes without error. Assuming that's not the case for you, any idea what variables might be different?
Yeah that's not a valid repro. The file in question is 1600+ lines which I can't share unfortunately, and I have been unable to find a small repro for it.
Here's a repro:
@MainActor
public final class A: ObservableObject {
// MARK: Lifecycle
public init(
a3: A42.ID,
a4: A43,
a5: some Publisher<Bool, Never>,
a6: @escaping (A44) -> Void,
a7: @escaping (A45) -> Void,
a8: @escaping () -> Void
) {
self.a3 = a3
self.a4 = a4
self.a6 = a6
self.a7 = a7
self.a8 = a8
a9 = A46(a: a4.a.b)
a11 = a4.a11
a10?.$a12.assign(to: &$a13)
a4.$a11
.removeDuplicates()
.dropFirst()
.assign(to: &$a11)
a4.$a
.map { A46(a: $0.a) }
.weakAssign(to: \.a9, on: self)
.store(in: &a14)
a19
.map(\.a20)
.removeDuplicates()
.assign(to: &$a21)
a15.a22
.sink { [weak self] a23, error in
guard self?.a17.contains(a23.id) == true else { return }
Task { [a24 = self?.a24] in
await a24?.present(A25.a26(a23.a27, .init(error)))
switch a23.a27 {
case .a28, .a29, .a30:
A31.a32(.a33(.a34Failed))
#if !A34
case .a35:
A31.a32(.a33(.a34Failed))
#endif
case .a36:
break
}
}
}
.store(in: &a14)
a19
.map {
if $0.contains(where: { $0.a27.a37 }) {
A38.a39
} else if $0.contains(where: { $0.a27.a40 }) {
A38.a41
} else {
A38.a42
}
}
.removeDuplicates()
.handleEvents(receiveOutput: { next in
A43.debug("A44: \(next)")
})
.assign(to: &$a45)
a4.$a46
.map(\.a47)
.removeDuplicates()
.assign(to: &$a48)
a4.$a49
.assign(to: &$a50)
let a51: AnyPublisher<A52?, Never>
let a53 = a4.$a.map(\.a?.a54)
let a55 = { [a56] a57 in
a56.$a58
.map(\.[a57])
.map { x in
if let a59 = x?.a54 {
AnyPublisher(Just<A52?>(.init(a59)))
} else {
AnyPublisher(a53)
}
}
.switchToLatest()
}
a51 = .init(
a4.$a57
.removeDuplicates()
.map { a57 in
if let a57 {
AnyPublisher(a55(a57))
} else {
AnyPublisher(a53)
}
}
.switchToLatest())
a51.map(\.?.a60)
.removeDuplicates()
.sink { [weak self] _ in
guard let self else { return }
if !a17.isEmpty {
a15.a61(a17)
a17 = []
}
}
.store(in: &a14)
if a4.a57 == nil {
self.a51 = a4.a.b?.a54
}
a51.assign(to: &$a51)
a4.a62(
a63: A64.shared.a65(for: a3).a66())
.assign(to: &$a67)
a5.assign(to: &$a68)
a4.$a69
.assign(to: &$a70)
a71()
$a72
.map { $0 != nil }
.removeDuplicates()
.assign(to: &$a73)
a74.a75(for: .known(.a76))
.assign(to: &$a72)
a4.$a77
.removeDuplicates()
.combineLatest(a74.a75(for: .a(.a78)))
.sink { [weak self] a77, a78 in
self?.a79 = a78 != nil
self?.a80 = a77.map {
A81(
a82: $0,
a83: { [weak self] in self?.a4.a84() },
a85: { [weak self] in self?.a86($0) })
}
}
.store(in: &a14)
runAttachedTask { weakSelf in
weakSelf.value?.a87 = await A88.x()
}
a89
.a90
.assign(to: &$a91)
#if os(macOS) && !A34
a92
.$a93
.map { [a4] a94 in
guard a94?.a95 == a4.a96.id else { return nil }
return a94?.a97
}
.assign(to: &$a98)
#endif
if Self.a99 == nil {
Self.a99 = a100
}
a101()
}
}
@NachoSoto thanks, that was very helpful. I've found the problem and landed a fix
Thanks! Any idea when that will ship! We're currently ignoring this file but we'd like to re-enable it 🙏🏻
I'll try to roll it out asap - within the next few days I would think
@NachoSoto fixed in 0.54.5
Crash report
Open
``` ------------------------------------- Translated Report (Full Report Below) ------------------------------------- Process: swiftformat [26520] Path: /usr/local/Cellar/swiftformat/0.54.4/bin/swiftformat Identifier: swiftformat Version: ??? Code Type: X86-64 (Translated) Parent Process: bash [89785] Responsible: iTerm2 [992] User ID: 502 Date/Time: 2024-09-08 08:53:44.5179 -0700 OS Version: macOS 14.6.1 (23G93) Report Version: 12 Anonymous UUID: 6021A40C-BD78-6726-FC0E-6DB80E7C7D7E Sleep/Wake UUID: 72BEB05F-F5D4-48FC-BE61-F986E302F1F9 Time Awake Since Boot: 520000 seconds Time Since Wake: 206 seconds System Integrity Protection: enabled Notes: PC register does not match crashing frame (0x0 vs 0x1036A4888) Crashed Thread: 25 Dispatch queue: swiftformat.formatting Exception Type: EXC_BAD_INSTRUCTION (SIGILL) Exception Codes: 0x0000000000000001, 0x0000000000000000 Termination Reason: Namespace SIGNAL, Code 4 Illegal instruction: 4 Terminating Process: exc handler [26520] Error Formulating Crash Report: PC register does not match crashing frame (0x0 vs 0x1036A4888) Thread 0:: Dispatch queue: com.apple.main-thread 0 ??? 0x7ff8abd06a78 ??? 1 libsystem_kernel.dylib 0x7ff81ba19846 __ulock_wait + 10 2 libdispatch.dylib 0x7ff81b8b75d4 _dlock_wait + 46 3 libdispatch.dylib 0x7ff81b8b7895 _dispatch_group_wait_slow + 42 4 swiftformat 0x102ff10e8 enumerateFiles(withInputURL:outputURL:options:concurrent:logger:skipped:handler:) + 2056 5 swiftformat 0x102ea559c specialized processInput(_:andWriteToOutput:options:overrides:lineRange:verbose:dryrun:lint:lenient:cacheURL:reporter:) + 1964 6 swiftformat 0x102e9ffd5 closure #10 in processArguments(_:environment:in:) + 309 7 swiftformat 0x102ea3dc9 partial apply for closure #10 in processArguments(_:environment:in:) + 105 8 swiftformat 0x102e99323 timeEvent(block:) + 35 9 swiftformat 0x102e95556 processArguments(_:environment:in:) + 17286 10 swiftformat 0x102e911a7 static CLI.run(in:with:) + 151 11 swiftformat 0x102e6876b CommandLineTool_main + 715 12 dyld 0x20341e345 start + 1909 Thread 1:: com.apple.rosetta.exceptionserver 0 runtime 0x7ff7ffd35414 0x7ff7ffd31000 + 17428 Thread 2:: Dispatch queue: com.apple.root.user-initiated-qos 0 libswiftCore.dylib 0x7ff82cbd9b40 swift_bridgeObjectRelease + 0 1 libswiftCore.dylib 0x7ff82cb74b5a swift_arrayDestroy + 138 2 libswiftCore.dylib 0x7ff82c9f46f0 _SetStorage.deinit + 192 3 libswiftCore.dylib 0x7ff82c9f4769 _SetStorage.__deallocating_deinit + 9 4 libswiftCore.dylib 0x7ff82cb87230 _swift_release_dealloc + 16 5 libswiftCore.dylib 0x7ff82cb87bdb bool swift::RefCountsOther information:
I've isolated it to a particular file in our codebase, and running it with
--dry-run
doesn't crash, so I can see it's one of these 2 rules:Removing code chunk by chunk on that file I isolated it to these 3 lines inside the constructor:
Edit: Actually if I run it with
--dry-run
and the whole file it still crashes, so the information above is probably only part of the reason it was crashing. Looks like based on the crash report it'sunusedArguments
.