Reimplementing constraint solver

Discussion about the development of the Assembly workbench.
abdullah
Posts: 3894
Joined: Sun May 04, 2014 3:16 pm

Re: Reimplementing constraint solver

Postby abdullah » Fri Apr 24, 2020 5:53 am

DeepSOIC wrote:
Tue Apr 21, 2020 2:56 pm
You're right, and there probably is a way to convince it, but i think it is just not worth the fight. + the problem might come up again as the code is modified.
What is your compiler version?

Code: Select all

#include <stdio.h>

int main()
{
    printf("_MSC_VER : %d \n", _MSC_VER);
    printf("_MSC_FULL_VER : %d \n", _MSC_FULL_VER);
    printf("_MSC_BUILD : %d \n", _MSC_BUILD);

    #ifdef _MSVC_LANG
        printf("_MSVC_LANG : C++%d \n", (_MSVC_LANG/100)%2000);
    #endif

    return 0;
}
I have put the offending code here:
https://godbolt.org/z/8ENcfu

It compiles with with what they call "MSVC 2015" "MSVC v19.0".

I have also tried (Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x64):
https://rextester.com/JRZQB66350

This MSVC year + IDE version + MSVC version is highly misleading.

In the case MSVC is trying to use copy assignment for what should be a move-assignment operation, as the push_back() is taking an rvalue. This happens even when the copy assignment is explicitly deleted and the move assignment explicitly enabled and even declared noexcept.

Code: Select all

    struct GeoDef {
        GeoDef() : geo(nullptr),type(GeoType::None),external(false),index(-1),
                   startPointId(-1),midPointId(-1),endPointId(-1) {}
                   
        GeoDef(const GeoDef &) = delete;
        GeoDef & operator=(const GeoDef &) = delete;
        
        GeoDef(GeoDef &&) noexcept = default;
        GeoDef & operator=(GeoDef &&) noexcept = default;
        
        std::unique_ptr<Part::Geometry>     geo;            // pointer to the geometry
        GeoType                             type;           // type of the geometry
        bool                                external;       // flag for external geometries
        int                                 index;          // index in the corresponding storage vector (Lines, Arcs, Circles, ...)
        int                                 startPointId;   // index in Points of the start point of this geometry
        int                                 midPointId;     // index in Points of the start point of this geometry
        int                                 endPointId;     // index in Points of the end point of this geometry
    };
It appears to me that the implementation of the standard library of MS is enforcing that the type is copiable for an operation where it should enforce that it is movable. This appears to me like a very restrictive bug, as it means that move only types cannot be inserted in a STL container such as std::vector.

Apparently it is possible to upgrade Travis to the 2019 version of MSVC via chocolatey:
https://travis-ci.community/t/vs-2019-and-cmake/3796/5

But this is something I do not like much for these reasons: a) it is not preinstalled (so I wonder how stable it will be), b) there are developers out there using the 2015 version, c) I am not even sure that this would "fix" the issue.

When I have some time, I am going to review this bottom-up and maybe post in stackoverflow.
User avatar
DeepSOIC
Posts: 7832
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: Reimplementing constraint solver

Postby DeepSOIC » Fri Apr 24, 2020 10:06 am

abdullah wrote:
Fri Apr 24, 2020 5:53 am
What is your compiler version?
CMake reports:
Compiler: MSVC, version: 19.20.27508.1
In Qt creator, the version is different, but it should be the same compiler:
Microsoft Visual C++ Compiler 16.0.28803.202 (amd64)
Path is:
C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.20.27508/bin/HostX64/x64/cl.exe
So I suppose it is 2019.
abdullah
Posts: 3894
Joined: Sun May 04, 2014 3:16 pm

Re: Reimplementing constraint solver

Postby abdullah » Fri Apr 24, 2020 4:02 pm

DeepSOIC wrote:
Fri Apr 24, 2020 10:06 am
CMake reports:
Compiler: MSVC, version: 19.20.27508.1
In Qt creator, the version is different, but it should be the same compiler:
Microsoft Visual C++ Compiler 16.0.28803.202 (amd64)
Path is:
C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.20.27508/bin/HostX64/x64/cl.exe
So I suppose it is 2019.
This is why I provided the code. According to Stackoverflow it is very difficult to know what exactly is being used.

I have pushed a commit, which fails in Travis-ci. However, it is what I put in those online compilers. Your version 19.20, compiles the simplified snippet in godbolt.org.

Is there a chance that you could check if the current branch compiles with your setup?
User avatar
DeepSOIC
Posts: 7832
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: Reimplementing constraint solver

Postby DeepSOIC » Fri Apr 24, 2020 4:20 pm

abdullah wrote:
Fri Apr 24, 2020 4:02 pm
Is there a chance that you could check if the current branch compiles with your setup?
it doesn't.

Code: Select all

[2/7 0.3/sec] Building CXX object src\Mod\Sketcher\App\CMakeFiles\Sketcher.dir\FCSSketch.cpp.obj
FAILED: src/Mod/Sketcher/App/CMakeFiles/Sketcher.dir/FCSSketch.cpp.obj 
C:\PROGRA~2\MICROS~2\2019\BUILDT~1\VC\Tools\MSVC\1420~1.275\bin\HostX64\x64\cl.exe  /nologo /TP -DFCAppSketcher -DHAVE_ACOSH -DHAVE_ASINH -DHAVE_ATANH -DHAVE_SNPRINTF -DQT_CORE_LIB -DQT_XML_LIB -DSketcher_EXPORTS -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_OCC64 -D_UNICODE -Isrc -IS:\_vt\dev\PC\Qt\FreeCAD\FreeCAD-ellipse\src -I. -IS:\_vt\dev\PC\Qt\FreeCAD\FreeCAD-ellipse\src\Mod\Sketcher\App -Isrc\Mod\Sketcher\App -IS:\_vt\dev\PC\Qt\FreeCAD\FreeCAD-ellipse\src\Mod\Sketcher\App\.. -Isrc\Mod\Sketcher\App\.. -IS:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include -IS:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\inc -IS:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\bin\Include -IS:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include\eigen3 -IS:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include\QtCore -IS:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\.\mkspecs\win32-msvc -IS:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include\QtXml /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1 -DFC_DEBUG /Zm150 /bigobj /showIncludes /Fosrc\Mod\Sketcher\App\CMakeFiles\Sketcher.dir\FCSSketch.cpp.obj /Fdsrc\Mod\Sketcher\App\CMakeFiles\Sketcher.dir\ /FS -c S:\_vt\dev\PC\Qt\FreeCAD\FreeCAD-ellipse\src\Mod\Sketcher\App\FCSSketch.cpp
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\include\xutility(1784): error C2280: 'Sketcher::FCSSketch::GeoDef &Sketcher::FCSSketch::GeoDef::operator =(const Sketcher::FCSSketch::GeoDef &)': attempting to reference a deleted function
S:\_vt\dev\PC\Qt\FreeCAD\FreeCAD-ellipse\src\Mod\Sketcher\App\FCSSketch.h(130): note: see declaration of 'Sketcher::FCSSketch::GeoDef::operator ='
S:\_vt\dev\PC\Qt\FreeCAD\FreeCAD-ellipse\src\Mod\Sketcher\App\FCSSketch.h(130): note: 'Sketcher::FCSSketch::GeoDef &Sketcher::FCSSketch::GeoDef::operator =(const Sketcher::FCSSketch::GeoDef &)': function was explicitly deleted
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\include\vector(1021): note: see reference to function template instantiation '_OutIt *std::_Copy_unchecked<_Iter,Sketcher::FCSSketch::GeoDef*>(_InIt,_InIt,_OutIt)' being compiled
        with
        [
            _OutIt=Sketcher::FCSSketch::GeoDef *,
            _Iter=Sketcher::FCSSketch::GeoDef *,
            _InIt=Sketcher::FCSSketch::GeoDef *
        ]
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\include\vector(1036): note: see reference to function template instantiation 'void std::vector<Sketcher::FCSSketch::GeoDef,std::allocator<_Ty>>::_Assign_range<_Ty*>(_Iter,_Iter,std::forward_iterator_tag)' being compiled
        with
        [
            _Ty=Sketcher::FCSSketch::GeoDef,
            _Iter=Sketcher::FCSSketch::GeoDef *
        ]
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\include\vector(1036): note: see reference to function template instantiation 'void std::vector<Sketcher::FCSSketch::GeoDef,std::allocator<_Ty>>::_Assign_range<_Ty*>(_Iter,_Iter,std::forward_iterator_tag)' being compiled
        with
        [
            _Ty=Sketcher::FCSSketch::GeoDef,
            _Iter=Sketcher::FCSSketch::GeoDef *
        ]
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\include\vector(1046): note: see reference to function template instantiation 'void std::vector<Sketcher::FCSSketch::GeoDef,std::allocator<_Ty>>::assign<Sketcher::FCSSketch::GeoDef*,void>(_Iter,_Iter)' being compiled
        with
        [
            _Ty=Sketcher::FCSSketch::GeoDef,
            _Iter=Sketcher::FCSSketch::GeoDef *
        ]
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\include\vector(1046): note: see reference to function template instantiation 'void std::vector<Sketcher::FCSSketch::GeoDef,std::allocator<_Ty>>::assign<Sketcher::FCSSketch::GeoDef*,void>(_Iter,_Iter)' being compiled
        with
        [
            _Ty=Sketcher::FCSSketch::GeoDef,
            _Iter=Sketcher::FCSSketch::GeoDef *
        ]
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\include\vector(1044): note: while compiling class template member function 'void std::vector<Sketcher::FCSSketch::GeoDef,std::allocator<_Ty>>::_Copy_assign(const std::vector<_Ty,std::allocator<_Ty>> &,std::false_type)'
        with
        [
            _Ty=Sketcher::FCSSketch::GeoDef
        ]
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\include\vector(1062): note: see reference to function template instantiation 'void std::vector<Sketcher::FCSSketch::GeoDef,std::allocator<_Ty>>::_Copy_assign(const std::vector<_Ty,std::allocator<_Ty>> &,std::false_type)' being compiled
        with
        [
            _Ty=Sketcher::FCSSketch::GeoDef
        ]
S:\_vt\dev\PC\Qt\FreeCAD\FreeCAD-ellipse\src\Mod\Sketcher\App\FCSSketch.h(192): note: see reference to class template instantiation 'std::vector<Sketcher::FCSSketch::GeoDef,std::allocator<_Ty>>' being compiled
        with
        [
            _Ty=Sketcher::FCSSketch::GeoDef
        ]
[3/7 0.3/sec] Building CXX object src\Mod\Sketcher\App\CMakeFiles\Sketcher.dir\AppSketcher.cpp.obj
FAILED: src/Mod/Sketcher/App/CMakeFiles/Sketcher.dir/AppSketcher.cpp.obj 
C:\PROGRA~2\MICROS~2\2019\BUILDT~1\VC\Tools\MSVC\1420~1.275\bin\HostX64\x64\cl.exe  /nologo /TP -DFCAppSketcher -DHAVE_ACOSH -DHAVE_ASINH -DHAVE_ATANH -DHAVE_SNPRINTF -DQT_CORE_LIB -DQT_XML_LIB -DSketcher_EXPORTS -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_OCC64 -D_UNICODE -Isrc -IS:\_vt\dev\PC\Qt\FreeCAD\FreeCAD-ellipse\src -I. -IS:\_vt\dev\PC\Qt\FreeCAD\FreeCAD-ellipse\src\Mod\Sketcher\App -Isrc\Mod\Sketcher\App -IS:\_vt\dev\PC\Qt\FreeCAD\FreeCAD-ellipse\src\Mod\Sketcher\App\.. -Isrc\Mod\Sketcher\App\.. -IS:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include -IS:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\inc -IS:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\bin\Include -IS:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include\eigen3 -IS:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include\QtCore -IS:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\.\mkspecs\win32-msvc -IS:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include\QtXml /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1 -DFC_DEBUG /Zm150 /bigobj /showIncludes /Fosrc\Mod\Sketcher\App\CMakeFiles\Sketcher.dir\AppSketcher.cpp.obj /Fdsrc\Mod\Sketcher\App\CMakeFiles\Sketcher.dir\ /FS -c S:\_vt\dev\PC\Qt\FreeCAD\FreeCAD-ellipse\src\Mod\Sketcher\App\AppSketcher.cpp
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\include\xutility(1784): error C2280: 'Sketcher::FCSSketch::GeoDef &Sketcher::FCSSketch::GeoDef::operator =(const Sketcher::FCSSketch::GeoDef &)': attempting to reference a deleted function
S:\_vt\dev\PC\Qt\FreeCAD\FreeCAD-ellipse\src\Mod\Sketcher\App\FCSSketch.h(130): note: see declaration of 'Sketcher::FCSSketch::GeoDef::operator ='
S:\_vt\dev\PC\Qt\FreeCAD\FreeCAD-ellipse\src\Mod\Sketcher\App\FCSSketch.h(130): note: 'Sketcher::FCSSketch::GeoDef &Sketcher::FCSSketch::GeoDef::operator =(const Sketcher::FCSSketch::GeoDef &)': function was explicitly deleted
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\include\vector(1021): note: see reference to function template instantiation '_OutIt *std::_Copy_unchecked<_Iter,Sketcher::FCSSketch::GeoDef*>(_InIt,_InIt,_OutIt)' being compiled
        with
        [
            _OutIt=Sketcher::FCSSketch::GeoDef *,
            _Iter=Sketcher::FCSSketch::GeoDef *,
            _InIt=Sketcher::FCSSketch::GeoDef *
        ]
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\include\vector(1036): note: see reference to function template instantiation 'void std::vector<Sketcher::FCSSketch::GeoDef,std::allocator<_Ty>>::_Assign_range<_Ty*>(_Iter,_Iter,std::forward_iterator_tag)' being compiled
        with
        [
            _Ty=Sketcher::FCSSketch::GeoDef,
            _Iter=Sketcher::FCSSketch::GeoDef *
        ]
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\include\vector(1036): note: see reference to function template instantiation 'void std::vector<Sketcher::FCSSketch::GeoDef,std::allocator<_Ty>>::_Assign_range<_Ty*>(_Iter,_Iter,std::forward_iterator_tag)' being compiled
        with
        [
            _Ty=Sketcher::FCSSketch::GeoDef,
            _Iter=Sketcher::FCSSketch::GeoDef *
        ]
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\include\vector(1046): note: see reference to function template instantiation 'void std::vector<Sketcher::FCSSketch::GeoDef,std::allocator<_Ty>>::assign<Sketcher::FCSSketch::GeoDef*,void>(_Iter,_Iter)' being compiled
        with
        [
            _Ty=Sketcher::FCSSketch::GeoDef,
            _Iter=Sketcher::FCSSketch::GeoDef *
        ]
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\include\vector(1046): note: see reference to function template instantiation 'void std::vector<Sketcher::FCSSketch::GeoDef,std::allocator<_Ty>>::assign<Sketcher::FCSSketch::GeoDef*,void>(_Iter,_Iter)' being compiled
        with
        [
            _Ty=Sketcher::FCSSketch::GeoDef,
            _Iter=Sketcher::FCSSketch::GeoDef *
        ]
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\include\vector(1044): note: while compiling class template member function 'void std::vector<Sketcher::FCSSketch::GeoDef,std::allocator<_Ty>>::_Copy_assign(const std::vector<_Ty,std::allocator<_Ty>> &,std::false_type)'
        with
        [
            _Ty=Sketcher::FCSSketch::GeoDef
        ]
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\include\vector(1062): note: see reference to function template instantiation 'void std::vector<Sketcher::FCSSketch::GeoDef,std::allocator<_Ty>>::_Copy_assign(const std::vector<_Ty,std::allocator<_Ty>> &,std::false_type)' being compiled
        with
        [
            _Ty=Sketcher::FCSSketch::GeoDef
        ]
S:\_vt\dev\PC\Qt\FreeCAD\FreeCAD-ellipse\src\Mod\Sketcher\App\FCSSketch.h(192): note: see reference to class template instantiation 'std::vector<Sketcher::FCSSketch::GeoDef,std::allocator<_Ty>>' being compiled
        with
        [
            _Ty=Sketcher::FCSSketch::GeoDef
        ]
S:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include\boost/bind/placeholders.hpp(54): note: see reference to class template instantiation 'boost::arg<9>' being compiled
S:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include\boost/bind/placeholders.hpp(53): note: see reference to class template instantiation 'boost::arg<8>' being compiled
S:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include\boost/bind/placeholders.hpp(52): note: see reference to class template instantiation 'boost::arg<7>' being compiled
S:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include\boost/bind/placeholders.hpp(51): note: see reference to class template instantiation 'boost::arg<6>' being compiled
S:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include\boost/bind/placeholders.hpp(50): note: see reference to class template instantiation 'boost::arg<5>' being compiled
S:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include\boost/bind/placeholders.hpp(49): note: see reference to class template instantiation 'boost::arg<4>' being compiled
S:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include\boost/bind/placeholders.hpp(48): note: see reference to class template instantiation 'boost::arg<3>' being compiled
S:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include\boost/bind/placeholders.hpp(47): note: see reference to class template instantiation 'boost::arg<2>' being compiled
S:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include\boost/bind/placeholders.hpp(46): note: see reference to class template instantiation 'boost::arg<1>' being compiled
[4/7 0.4/sec] Building CXX object src\Mod\Sketcher\App\CMakeFiles\Sketcher.dir\SketchObject.cpp.obj
FAILED: src/Mod/Sketcher/App/CMakeFiles/Sketcher.dir/SketchObject.cpp.obj 
C:\PROGRA~2\MICROS~2\2019\BUILDT~1\VC\Tools\MSVC\1420~1.275\bin\HostX64\x64\cl.exe  /nologo /TP -DFCAppSketcher -DHAVE_ACOSH -DHAVE_ASINH -DHAVE_ATANH -DHAVE_SNPRINTF -DQT_CORE_LIB -DQT_XML_LIB -DSketcher_EXPORTS -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_OCC64 -D_UNICODE -Isrc -IS:\_vt\dev\PC\Qt\FreeCAD\FreeCAD-ellipse\src -I. -IS:\_vt\dev\PC\Qt\FreeCAD\FreeCAD-ellipse\src\Mod\Sketcher\App -Isrc\Mod\Sketcher\App -IS:\_vt\dev\PC\Qt\FreeCAD\FreeCAD-ellipse\src\Mod\Sketcher\App\.. -Isrc\Mod\Sketcher\App\.. -IS:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include -IS:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\inc -IS:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\bin\Include -IS:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include\eigen3 -IS:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include\QtCore -IS:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\.\mkspecs\win32-msvc -IS:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include\QtXml /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1 -DFC_DEBUG /Zm150 /bigobj /showIncludes /Fosrc\Mod\Sketcher\App\CMakeFiles\Sketcher.dir\SketchObject.cpp.obj /Fdsrc\Mod\Sketcher\App\CMakeFiles\Sketcher.dir\ /FS -c S:\_vt\dev\PC\Qt\FreeCAD\FreeCAD-ellipse\src\Mod\Sketcher\App\SketchObject.cpp
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\include\xutility(1784): error C2280: 'Sketcher::FCSSketch::GeoDef &Sketcher::FCSSketch::GeoDef::operator =(const Sketcher::FCSSketch::GeoDef &)': attempting to reference a deleted function
S:\_vt\dev\PC\Qt\FreeCAD\FreeCAD-ellipse\src\Mod\Sketcher\App\FCSSketch.h(130): note: see declaration of 'Sketcher::FCSSketch::GeoDef::operator ='
S:\_vt\dev\PC\Qt\FreeCAD\FreeCAD-ellipse\src\Mod\Sketcher\App\FCSSketch.h(130): note: 'Sketcher::FCSSketch::GeoDef &Sketcher::FCSSketch::GeoDef::operator =(const Sketcher::FCSSketch::GeoDef &)': function was explicitly deleted
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\include\vector(1021): note: see reference to function template instantiation '_OutIt *std::_Copy_unchecked<_Iter,Sketcher::FCSSketch::GeoDef*>(_InIt,_InIt,_OutIt)' being compiled
        with
        [
            _OutIt=Sketcher::FCSSketch::GeoDef *,
            _Iter=Sketcher::FCSSketch::GeoDef *,
            _InIt=Sketcher::FCSSketch::GeoDef *
        ]
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\include\vector(1036): note: see reference to function template instantiation 'void std::vector<Sketcher::FCSSketch::GeoDef,std::allocator<_Ty>>::_Assign_range<_Ty*>(_Iter,_Iter,std::forward_iterator_tag)' being compiled
        with
        [
            _Ty=Sketcher::FCSSketch::GeoDef,
            _Iter=Sketcher::FCSSketch::GeoDef *
        ]
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\include\vector(1036): note: see reference to function template instantiation 'void std::vector<Sketcher::FCSSketch::GeoDef,std::allocator<_Ty>>::_Assign_range<_Ty*>(_Iter,_Iter,std::forward_iterator_tag)' being compiled
        with
        [
            _Ty=Sketcher::FCSSketch::GeoDef,
            _Iter=Sketcher::FCSSketch::GeoDef *
        ]
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\include\vector(1046): note: see reference to function template instantiation 'void std::vector<Sketcher::FCSSketch::GeoDef,std::allocator<_Ty>>::assign<Sketcher::FCSSketch::GeoDef*,void>(_Iter,_Iter)' being compiled
        with
        [
            _Ty=Sketcher::FCSSketch::GeoDef,
            _Iter=Sketcher::FCSSketch::GeoDef *
        ]
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\include\vector(1046): note: see reference to function template instantiation 'void std::vector<Sketcher::FCSSketch::GeoDef,std::allocator<_Ty>>::assign<Sketcher::FCSSketch::GeoDef*,void>(_Iter,_Iter)' being compiled
        with
        [
            _Ty=Sketcher::FCSSketch::GeoDef,
            _Iter=Sketcher::FCSSketch::GeoDef *
        ]
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\include\vector(1044): note: while compiling class template member function 'void std::vector<Sketcher::FCSSketch::GeoDef,std::allocator<_Ty>>::_Copy_assign(const std::vector<_Ty,std::allocator<_Ty>> &,std::false_type)'
        with
        [
            _Ty=Sketcher::FCSSketch::GeoDef
        ]
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\include\vector(1062): note: see reference to function template instantiation 'void std::vector<Sketcher::FCSSketch::GeoDef,std::allocator<_Ty>>::_Copy_assign(const std::vector<_Ty,std::allocator<_Ty>> &,std::false_type)' being compiled
        with
        [
            _Ty=Sketcher::FCSSketch::GeoDef
        ]
S:\_vt\dev\PC\Qt\FreeCAD\FreeCAD-ellipse\src\Mod\Sketcher\App\FCSSketch.h(192): note: see reference to class template instantiation 'std::vector<Sketcher::FCSSketch::GeoDef,std::allocator<_Ty>>' being compiled
        with
        [
            _Ty=Sketcher::FCSSketch::GeoDef
        ]
S:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include\boost/bind/placeholders.hpp(54): note: see reference to class template instantiation 'boost::arg<9>' being compiled
S:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include\boost/bind/placeholders.hpp(53): note: see reference to class template instantiation 'boost::arg<8>' being compiled
S:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include\boost/bind/placeholders.hpp(52): note: see reference to class template instantiation 'boost::arg<7>' being compiled
S:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include\boost/bind/placeholders.hpp(51): note: see reference to class template instantiation 'boost::arg<6>' being compiled
S:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include\boost/bind/placeholders.hpp(50): note: see reference to class template instantiation 'boost::arg<5>' being compiled
S:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include\boost/bind/placeholders.hpp(49): note: see reference to class template instantiation 'boost::arg<4>' being compiled
S:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include\boost/bind/placeholders.hpp(48): note: see reference to class template instantiation 'boost::arg<3>' being compiled
S:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include\boost/bind/placeholders.hpp(47): note: see reference to class template instantiation 'boost::arg<2>' being compiled
S:\_vt\dev\PC\Qt\FreeCAD\libpack\12.1.2\include\boost/bind/placeholders.hpp(46): note: see reference to class template instantiation 'boost::arg<1>' being compiled
ninja: build stopped: subcommand failed.
19:17:43: The process "S:\Qt\cmake3110\bin\cmake.exe" exited with code 1.
Error while building/deploying project FreeCAD (kit: FC64)
When executing step "CMake Build"
19:17:43: Elapsed time: 00:12.
User avatar
DeepSOIC
Posts: 7832
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: Reimplementing constraint solver

Postby DeepSOIC » Fri Apr 24, 2020 4:24 pm

I can set up something like TeamViewer and let you play with my ide for a little while if you want
User avatar
tanderson69
Posts: 1545
Joined: Thu Feb 18, 2010 1:07 am

Re: Reimplementing constraint solver

Postby tanderson69 » Fri Apr 24, 2020 5:04 pm

abdullah wrote:
Fri Apr 24, 2020 5:53 am
I have put the offending code here:
https://godbolt.org/z/8ENcfu

Code: Select all

//taken from the godbolt website:
...
int main()
{
    std::vector<GeoDef>                         Geoms;
    
    // create our own copy
    Geometry *p = new GeomPoint;

    // create the definition struct for that geom
    GeoDef def;
    def.geo  = std::move(std::unique_ptr<Geometry>(static_cast<Geometry *>(p)));
    def.type = GeoType::Point;
   
    def.startPointId = 1;
    def.endPointId = 2;
    def.midPointId = 3;
    
    def.index = 0;

    // store complete set
    Geoms.push_back(std::move(def));
}
A vector is guaranteed to be linear in memory. I don't see how a stack declared variable can be moved into a vector. I think you are still calling the copy constructor. Maybe this instead?:

Code: Select all

...
int main()
{
    std::vector<GeoDef>                         Geoms;
    
    // create our own copy
    Geometry *p = new GeomPoint;

    // create the definition struct for that geom
    Geoms.emplace_back<GeoDef>();
    GeoDef &def = Geoms.back();
    def.geo  = std::move(std::unique_ptr<Geometry>(static_cast<Geometry *>(p)));
    def.type = GeoType::Point;
   
    def.startPointId = 1;
    def.endPointId = 2;
    def.midPointId = 3;
    
    def.index = 0;
}
User avatar
DeepSOIC
Posts: 7832
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: Reimplementing constraint solver

Postby DeepSOIC » Fri Apr 24, 2020 10:24 pm

abdullah wrote:
Fri Apr 24, 2020 4:02 pm
I have pushed a commit, which fails in Travis-ci.
I have unrolled the commits to not pollute the history, as they are clearly not helping. Force-pushed.
abdullah
Posts: 3894
Joined: Sun May 04, 2014 3:16 pm

Re: Reimplementing constraint solver

Postby abdullah » Sat Apr 25, 2020 2:14 pm

tanderson69 wrote:
Fri Apr 24, 2020 5:04 pm

A vector is guaranteed to be linear in memory. I don't see how a stack declared variable can be moved into a vector. I think you are still calling the copy constructor.
Thank you very much for taking the time and effort to reply.

Unfortunately, using emplace_back() too leads to the same compilation error:

https://github.com/FreeCAD/FreeCAD/pull ... b5e201681a

https://travis-ci.org/github/FreeCAD/Fr ... /679343937

I still do not understand the underlying reason and I am quite desperate. If you happen to realise which part of my reasoning if flawed, I would appreciate. This is how I reason:

1. I considered that a vector is guaranteed to be linear in memory. I assumed that using void push_back( T&& value ); the corresponding move constructor of class GeoDef would be called.

2. The requirement of that overload is that the T is MoveInsertable. The fact that it is a stack declared variable does not violate this requirement (or I do not see how). In fact, in the example of the push_back documentation:
int main()
{
std::vector<std::string> numbers;

numbers.push_back("abc");
std::string s = "def";
numbers.push_back(std::move(s));

std::cout << "vector holds: ";
for (auto&& i : numbers) std::cout << std::quoted(i) << ' ';
std::cout << "\nMoved-from string holds " << std::quoted(s) << '\n';
}
s with that length is a short string and, if I am not mistaken, no heap memory will be allocated for it, so it should be in the stack (tell me if I am wrong).

3. Even if it would be argued that std::string is not in the stack, GeoDef has one data member that is a heap allocated unique_ptr.

4. The explicitly declared default move constructor should "performs full member-wise move of the object's bases and non-static members, in their initialization order, using direct initialization with an xvalue argument".

GeoDef move constructors are declared noexcept, because std::vector uses

Code: Select all

 std::move_if
.

So I expect that the corresponding move constructor is called member-wise for these types:

Code: Select all

        std::unique_ptr<Part::Geometry>     geo;            // pointer to the geometry
        GeoType                             type;           // type of the geometry
        bool                                external;       // flag for external geometries
        int                                 index;          // index in the corresponding storage vector (Lines, Arcs, Circles, ...)
        int                                 startPointId;   // index in Points of the start point of this geometry
        int                                 midPointId;     // index in Points of the start point of this geometry
        int                                 endPointId;     // index in Points of the end point of this geometry
For std::unique_ptr, the corresponding move constructor should be called, resulting in the unique_ptr of the newly generated item at the end of the std::vector to get the exclusive ownership of the referred heap memory chunk.

For the rest of types, being built-in types, is that the move operation is downgraded to the corresponding copy operation.

5. Thus my understanding is not that magically a chunk of memory from the stack is moved to the heap, rather that a chunk of space will be reserved at the end of the vector and that the allocator of GeoDef will execute the move assignment operator of the unique_ptr and copy assignment of the built-in types.

This is why I still fail to understand is why a copy constructor must be declared for GeoDef.

The code compiles for gcc and clang (with push_back and with emplace_back), it is just MSVC. However, I am not sure I am looking at the right place, because with push_back, in the reduced examples with the only snippets compiles too.

I am going to try to narrow down the problem...


I will try to reduce the e
abdullah
Posts: 3894
Joined: Sun May 04, 2014 3:16 pm

Re: Reimplementing constraint solver

Postby abdullah » Sat Apr 25, 2020 2:15 pm

DeepSOIC wrote:
Fri Apr 24, 2020 10:24 pm
abdullah wrote:
Fri Apr 24, 2020 4:02 pm
I have pushed a commit, which fails in Travis-ci.
I have unrolled the commits to not pollute the history, as they are clearly not helping. Force-pushed.
It is perfectly fine. I take it into account.
abdullah
Posts: 3894
Joined: Sun May 04, 2014 3:16 pm

Re: Reimplementing constraint solver

Postby abdullah » Sat Apr 25, 2020 2:19 pm

tanderson69 wrote:
Fri Apr 24, 2020 5:04 pm

A vector is guaranteed to be linear in memory. I don't see how a stack declared variable can be moved into a vector. I think you are still calling the copy constructor.
Thank you very much for taking the time and effort to reply.

Unfortunately, using emplace_back() too leads to the same compilation error:

https://github.com/FreeCAD/FreeCAD/pull ... b5e201681a

https://travis-ci.org/github/FreeCAD/Fr ... /679343937

I still do not understand the underlying reason and I am quite desperate. If you happen to realise which part of my reasoning if flawed, I would appreciate. This is how I reason:

1. I considered that a vector is guaranteed to be linear in memory. I assumed that using void push_back( T&& value ); the corresponding move constructor of class GeoDef would be called.

2. The requirement of that overload is that the T is MoveInsertable. The fact that it is a stack declared variable does not violate this requirement (or I do not see how). In fact, in the example of the push_back documentation:
int main()
{
std::vector<std::string> numbers;

numbers.push_back("abc");
std::string s = "def";
numbers.push_back(std::move(s));

std::cout << "vector holds: ";
for (auto&& i : numbers) std::cout << std::quoted(i) << ' ';
std::cout << "\nMoved-from string holds " << std::quoted(s) << '\n';
}
s with that length is a short string and, if I am not mistaken, no heap memory will be allocated for it, so it should be in the stack (tell me if I am wrong).

3. Even if it would be argued that std::string is not in the stack, GeoDef has one data member that is a heap allocated unique_ptr.

4. The explicitly declared default move constructor should "performs full member-wise move of the object's bases and non-static members, in their initialization order, using direct initialization with an xvalue argument".

GeoDef move constructors are declared noexcept, because std::vector uses

Code: Select all

 std::move_if
.

So I expect that the corresponding move constructor is called member-wise for these types:

Code: Select all

        std::unique_ptr<Part::Geometry>     geo;            // pointer to the geometry
        GeoType                             type;           // type of the geometry
        bool                                external;       // flag for external geometries
        int                                 index;          // index in the corresponding storage vector (Lines, Arcs, Circles, ...)
        int                                 startPointId;   // index in Points of the start point of this geometry
        int                                 midPointId;     // index in Points of the start point of this geometry
        int                                 endPointId;     // index in Points of the end point of this geometry
For std::unique_ptr, the corresponding move constructor should be called, resulting in the unique_ptr of the newly generated item at the end of the std::vector to get the exclusive ownership of the referred heap memory chunk.

For the rest of types, being built-in types, is that the move operation is downgraded to the corresponding copy operation.

5. Thus my understanding is not that magically a chunk of memory from the stack is moved to the heap, rather that a chunk of space will be reserved at the end of the vector and that the allocator of GeoDef will execute the move assignment operator of the unique_ptr and copy assignment of the built-in types.

This is why I still fail to understand is why a copy constructor must be declared for GeoDef.

The code compiles for gcc and clang (with push_back and with emplace_back), it is just MSVC. However, I am not sure I am looking at the right place, because with push_back, in the reduced examples with the online snippets compiles too.

I am going to try to narrow down the problem...