Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-5277] Passing encoder to super class causes EXC_BAD_ACCESS #47852

Closed
subdigital opened this issue Jun 21, 2017 · 9 comments
Closed

[SR-5277] Passing encoder to super class causes EXC_BAD_ACCESS #47852

subdigital opened this issue Jun 21, 2017 · 9 comments

Comments

@subdigital
Copy link

@subdigital subdigital commented Jun 21, 2017

Previous ID SR-5277
Radar rdar://problem/32927085
Original Reporter @subdigital
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

macOS Sierra 10.12.5 (16F73)
Xcode 9.0 beta (9M136h)

Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug, RunTimeCrash
Assignee @itaiferber
Priority Medium

md5: 3a67f62125ed2fc58af4c8316e432344

Issue Description:

Reading the proposal for encoding w/ inheritance I see this comment:

If a shared container is desired, it is still possible to call `super.encode(to: encoder)` and
`super.init(from: decoder)`, but we recommend the safer containerized option.

However, this seems to cause EXC_BAD_ACCESS when attempting to do so.

I've attached a playground that exhibits this issue with a contrived example.

Not sure if this is Foundation or Standard Library related.

@belkadan
Copy link
Contributor

@belkadan belkadan commented Jun 22, 2017

@itaiferber
Copy link
Contributor

@itaiferber itaiferber commented Jun 22, 2017

Backtrace from the failure:

fatal error: Attempt to encode with new container when already encoded with keyed container.: file /Users/itai/Development/swift-oss/swift/stdlib/public/SDK/Foundation/JSONEncoder.swift, line 216
Current stack trace:
0    libswiftCore.dylib                 0x0000000116d67930 reportNow(unsigned int, char const*) + 151
1    libswiftCore.dylib                 0x0000000116d67900 swift_reportError + 27
2    libswiftCore.dylib                 0x0000000116e467e0 _swift_stdlib_reportFatalErrorInFile + 168
3    libswiftCore.dylib                 0x0000000116843020 closure #​1 in closure #​1 in closure #​1 in _assertionFailure(_:_:file:line:flags:) + 1658
4    libswiftCore.dylib                 0x0000000116d4fcc0 partial apply for closure #​1 in closure #​1 in closure #​1 in _assertionFailure(_:_:file:line:flags:) + 119
5    libswiftCore.dylib                 0x0000000116842710 thunk for @callee_owned (@unowned UnsafeBufferPointer<UInt8>) -> () + 12
6    libswiftCore.dylib                 0x0000000116d4fd80 _T0SRys5UInt8VGIxy_ACytIxyr_TRTA.1410 + 82
7    libswiftCore.dylib                 0x0000000116840d90 StaticString.withUTF8Buffer<A>(_:) + 1130
8    libswiftCore.dylib                 0x0000000116842e90 closure #&#8203;1 in closure #&#8203;1 in _assertionFailure(_:_:file:line:flags:) + 371
9    libswiftCore.dylib                 0x0000000116d4fb60 partial apply for closure #&#8203;1 in closure #&#8203;1 in _assertionFailure(_:_:file:line:flags:) + 135
10   libswiftCore.dylib                 0x00000001168436b0 thunk for @callee_owned (@unowned UnsafeBufferPointer<UInt8>) -> (@error @owned Error) + 22
11   libswiftCore.dylib                 0x0000000116d4fc30 partial apply for thunk for @callee_owned (@unowned UnsafeBufferPointer<UInt8>) -> (@error @owned Error) + 99
12   libswiftCore.dylib                 0x0000000116842910 String._withUnsafeBufferPointerToUTF8<A>(_:) + 493
13   libswiftCore.dylib                 0x0000000116842730 closure #&#8203;1 in _assertionFailure(_:_:file:line:flags:) + 422
14   libswiftCore.dylib                 0x0000000116c706d0 partial apply for closure #&#8203;1 in _assertionFailure(_:_:file:line:flags:) + 167
15   libswiftCore.dylib                 0x0000000116842710 thunk for @callee_owned (@unowned UnsafeBufferPointer<UInt8>) -> () + 12
16   libswiftCore.dylib                 0x0000000116c707c0 partial apply for thunk for @callee_owned (@unowned UnsafeBufferPointer<UInt8>) -> () + 82
17   libswiftCore.dylib                 0x0000000116840d90 StaticString.withUTF8Buffer<A>(_:) + 1130
18   libswiftCore.dylib                 0x000000011683f9a0 _assertionFailure(_:_:file:line:flags:) + 420
19   libswiftFoundation.dylib           0x00000001175e7a40 _JSONEncoder.assertCanRequestNewContainer() + 1674
20   libswiftFoundation.dylib           0x00000001175e80d0 _JSONEncoder.container<A>(keyedBy:) + 51
21   libswiftFoundation.dylib           0x00000001175e8870 protocol witness for Encoder.container<A>(keyedBy:) in conformance _JSONEncoder + 85
25   libswiftFoundation.dylib           0x00000001175e54a0 JSONEncoder.encode<A>(_:) + 667
27   swift                              0x0000000102e6b930 llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) + 1358
28   swift                              0x0000000102e771e0 llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, char const* const*) + 3650
29   swift                              0x00000001018f9740 swift::RunImmediately(swift::CompilerInstance&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, swift::IRGenOptions&, swift::SILOptions const&) + 8630
30   swift                              0x00000001018750f0 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 23454
31   swift                              0x0000000101870b30 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 9274
32   swift                              0x00000001017a12a0 main + 4809
33   libdyld.dylib                      0x00007fffbde55ff8 start + 1
0  swift                    0x0000000108a5254c llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 60
1  swift                    0x0000000108a52b49 PrintStackTraceSignalHandler(void*) + 25
2  swift                    0x0000000108a4e329 llvm::sys::RunSignalHandlers() + 425
3  swift                    0x0000000108a52fe2 SignalHandler(int) + 354
4  libsystem_platform.dylib 0x00007fffbe0d4f5a _sigtramp + 26
5  libsystem_platform.dylib 0x0000000100000002 _sigtramp + 1106424002
6  libswiftFoundation.dylib 0x00000001175e80ca _T010Foundation12_JSONEncoder33_12768CA107A31EF2DCE034FD75B541C9LLC28assertCanRequestNewContaineryyF + 1674
7  libswiftFoundation.dylib 0x00000001175e8103 _T010Foundation12_JSONEncoder33_12768CA107A31EF2DCE034FD75B541C9LLC9containers22KeyedEncodingContainerVyxGxm7keyedBy_ts9CodingKeyRzlF + 51
8  libswiftFoundation.dylib 0x00000001175e88c5 _T010Foundation12_JSONEncoder33_12768CA107A31EF2DCE034FD75B541C9LLCs7EncoderAAsAEP9containers22KeyedEncodingContainerVyqd__Gqd__m7keyedBy_ts9CodingKeyRd__lFTW + 85
9  libswiftFoundation.dylib 0x00000001146ad989 _T010Foundation12_JSONEncoder33_12768CA107A31EF2DCE034FD75B541C9LLCs7EncoderAAsAEP9containers22KeyedEncodingContainerVyqd__Gqd__m7keyedBy_ts9CodingKeyRd__lFTW + 4245442841
10 libswiftFoundation.dylib 0x00000001146ae628 _T010Foundation12_JSONEncoder33_12768CA107A31EF2DCE034FD75B541C9LLCs7EncoderAAsAEP9containers22KeyedEncodingContainerVyqd__Gqd__m7keyedBy_ts9CodingKeyRd__lFTW + 4245446072
11 libswiftFoundation.dylib 0x00000001146ade53 _T010Foundation12_JSONEncoder33_12768CA107A31EF2DCE034FD75B541C9LLCs7EncoderAAsAEP9containers22KeyedEncodingContainerVyqd__Gqd__m7keyedBy_ts9CodingKeyRd__lFTW + 4245444067
12 libswiftFoundation.dylib 0x00000001175e573b _T010Foundation11JSONEncoderC6encodeAA4DataVxKs9EncodableRzlF + 667
13 libswiftFoundation.dylib 0x00000001146ad283 _T010Foundation11JSONEncoderC6encodeAA4DataVxKs9EncodableRzlF + 4245454307
14 swift                    0x0000000102e6be7e llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) + 1358
15 swift                    0x0000000102e78022 llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, char const* const*) + 3650
16 swift                    0x00000001018fb8f6 swift::RunImmediately(swift::CompilerInstance&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, swift::IRGenOptions&, swift::SILOptions const&) + 8630
17 swift                    0x000000010187ac8e performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 23454
18 swift                    0x0000000101872f6a swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 9274
19 swift                    0x00000001017a2569 main + 4809
20 libdyld.dylib            0x00007fffbde55ff9 start + 1
Stack dump:
0.  Program arguments: /Users/itai/Development/swift-oss/build/Ninja-DebugAssert/swift-macosx-x86_64/bin/swift -frontend -interpret /Users/itai/Downloads/Swift 4 JSON - Inheritance.playground/Contents.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -color-diagnostics -module-name Contents
fish: './bin/swift ~/Downloads/Swift\…' terminated by signal SIGILL (Illegal instruction)

@itaiferber
Copy link
Contributor

@itaiferber itaiferber commented Jun 22, 2017

This happens because asking for a container from JSONEncoder currently attempts to push a new container when it could be returning the current top-level container.

@itaiferber
Copy link
Contributor

@itaiferber itaiferber commented Jun 22, 2017

@swift-ci create

@itaiferber
Copy link
Contributor

@itaiferber itaiferber commented Jun 22, 2017

@belkadan Thanks for passing all of these along to me, by the way! Appreciate the help. 🙂

@itaiferber
Copy link
Contributor

@itaiferber itaiferber commented Jun 23, 2017

Up against master at PR-10520

@itaiferber
Copy link
Contributor

@itaiferber itaiferber commented Jun 23, 2017

Up against swift-4.0-branch in PR=10538

@swift-ci
Copy link
Collaborator

@swift-ci swift-ci commented Jun 24, 2017

Comment by Garric Nahapetian (JIRA)

Is this still in progress?

@itaiferber
Copy link
Contributor

@itaiferber itaiferber commented Jun 26, 2017

This is now complete.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants