Bug 170875

Summary: Cannot compile JavaScriptCore/runtime/VMTraps.cpp on FreeBSD because std::pair has a non-trivial copy constructor
Product: WebKit Reporter: Ting-Wei Lan <lantw44>
Component: JavaScriptCoreAssignee: JF Bastien <jfbastien>
Status: RESOLVED FIXED    
Severity: Normal CC: buildbot, commit-queue, Hironori.Fujii, jfbastien, keith_miller, mark.lam, msaboff, saam, ysuzuki
Priority: P2    
Version: WebKit Local Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
patch none

Description Ting-Wei Lan 2017-04-15 08:26:25 PDT
In JavaScriptCore/runtime/VMTraps.cpp, function findActiveVMAndStackBounds returns a WTF::Expected<std::pair<JSC::VM*, WTF::StackBounds>, JSC::VMTraps::Error>. The parent class of this type is WTF::ExpectedDetail::ConstexprBase<std::pair<JSC::VM*, WTF::StackBounds>, JSC::VMTraps::Error>.

WTF::ExpectedDetail::ConstexprBase doesn't have a user-defined copy constructor, and its implicitly-defined copy constructor is deleted because the default std::pair implementation on FreeBSD has a non-trivial copy constructor. /usr/include/c++/v1/__config says _LIBCPP_TRIVIAL_PAIR_COPY_CTOR is disabled in order to keep ABI compatibility: https://svnweb.freebsd.org/changeset/base/261801.


Error messages showed by the compiler (clang 3.8):

/path/to/WebKit/Source/JavaScriptCore/runtime/VMTraps.cpp:96:9: error: returning object of type 'Expected<std::pair<VM *, StackBounds>, VMTraps::Error>' invokes deleted constructor
        return makeUnexpected(VMTraps::Error::LockUnavailable);
        ^      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../Source/WTF/wtf/Expected.h:262:5: note: explicitly defaulted function was implicitly deleted here
    Expected(const Expected&) = default;
    ^
../../Source/WTF/wtf/Expected.h:248:18: note: copy constructor of 'Expected<std::__1::pair<JSC::VM *, WTF::StackBounds>, JSC::VMTraps::Error>' is implicitly deleted because base class 'ExpectedDetail::BaseSelect<pair<VM *, StackBounds>, Error>' (aka 'WTF::ExpectedDetail::ConstexprBase<std::__1::pair<JSC::VM *, WTF::StackBounds>, JSC::VMTraps::Error>') has a deleted copy constructor
class Expected : private ExpectedDetail::BaseSelect<T, E> {
                 ^
../../Source/WTF/wtf/Expected.h:145:44: note: copy constructor of 'ConstexprBase<std::__1::pair<JSC::VM *, WTF::StackBounds>, JSC::VMTraps::Error>' is implicitly deleted because field 's' has a deleted copy constructor
    ConstexprStorage<ValueType, ErrorType> s;
                                           ^
../../Source/WTF/wtf/Expected.h:87:15: note: copy constructor of 'ConstexprStorage<std::__1::pair<JSC::VM *, WTF::StackBounds>, JSC::VMTraps::Error>' is implicitly deleted because variant field 'val' has a non-trivial copy constructor
    ValueType val;
              ^
Comment 1 JF Bastien 2017-04-19 01:25:59 PDT
It is surprising to see the constexpr version being instantiated here.
Comment 2 Ting-Wei Lan 2017-04-19 08:27:47 PDT
(In reply to JF Bastien from comment #1)
> It is surprising to see the constexpr version being instantiated here.

JSC::VM*, WTF::StackBounds, JSC::VMTraps::Error are all trivially destructible, so WTF::ExpectedDetail::BaseSelect is WTF::ExpectedDetail::ConstexprBase here.
Comment 3 JF Bastien 2017-04-19 09:54:47 PDT
Created attachment 307486 [details]
patch

(In reply to Ting-Wei Lan from comment #2)
> (In reply to JF Bastien from comment #1)
> > It is surprising to see the constexpr version being instantiated here.
> 
> JSC::VM*, WTF::StackBounds, JSC::VMTraps::Error are all trivially
> destructible, so WTF::ExpectedDetail::BaseSelect is
> WTF::ExpectedDetail::ConstexprBase here.

Derp, right you are!

Here's a patch that works around the issue.
Comment 4 Mark Lam 2017-04-19 09:56:53 PDT
Comment on attachment 307486 [details]
patch

r=me if EWS bots build and are happy.
Comment 5 JF Bastien 2017-04-19 10:40:40 PDT
Comment on attachment 307486 [details]
patch

Tests are broken for unrelated reason. Fetch or somesuch.

cq+
Comment 6 WebKit Commit Bot 2017-04-19 11:25:46 PDT
Comment on attachment 307486 [details]
patch

Clearing flags on attachment: 307486

Committed r215522: <http://trac.webkit.org/changeset/215522>
Comment 7 WebKit Commit Bot 2017-04-19 11:25:48 PDT
All reviewed patches have been landed.  Closing bug.