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

Imports revisited #248

Merged
merged 72 commits into from
Aug 15, 2018
Merged

Imports revisited #248

merged 72 commits into from
Aug 15, 2018

Conversation

hsorby
Copy link
Contributor

@hsorby hsorby commented Jul 17, 2018

Moving @nickerso work from outside the library to inside. The added import functionality only works for local on disk imports.

Addresses #238.

This PR supersedes #167, should this PR be merged then #167 should be closed and not merged.

David Nickerson and others added 30 commits August 28, 2017 13:20
Starting work on a test to explore resolving of imports.
Testing that the correct number of imports is detected.
Added a few new methods to the import class to track the source model used to
resolve the import. And then the test code which makes use of this to resolve
the imports in the existing test model.
This seems to have exposed some issues in the parsing of encapsulation hierarchies, so parking
this for now to explore that issue.
The tests are now working as expected (see cellml#171), and all passing.
Models don't all validate successfully, but outstanding issues likely due to cellml#174 and cellml#175.
Minor suggestions in documentation
@nickerso
Copy link
Contributor

The introduction of the enable_share_from_this is giving me the below warning with VS 2017 every time model.h is included.

3>c:\users\...\libcellml\src\api\libcellml\model.h(36): warning C4251: 'std::enable_shared_from_this<libcellml::Model>::_Wptr': class 'std::weak_ptr<_Ty>' needs to have dll-interface to be used by clients of class 'std::enable_shared_from_this<libcellml::Model>'
3>        with
3>        [
3>            _Ty=libcellml::Model
3>        ]
3>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.14.26428\include\memory(2000): note: see declaration of 'std::weak_ptr<_Ty>'
3>        with
3>        [
3>            _Ty=libcellml::Model
3>        ]

src/model.cpp Outdated
libcellml::ModelPtr model = parser.parseModel(buffer.str());
if (model) {
importSource->setModel(model);
model->resolveImports(url);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this cause all imports in the imported model to be resolved, regardless of whether they are needed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so we always try to resolve all imports in all imported models, but the hasUnresolvedImports method only checks the required imports are resolved. I guess this is more an efficiency thing that an actual problem with the code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point was that, from the code in Parser::parseModel(), model will never be equal to nullptr, so no point for the test.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep - the if (model) can be removed.

@agarny
Copy link
Contributor

agarny commented Jul 21, 2018

The introduction of the enable_share_from_this is giving me the below warning with VS 2017 every time model.h is included.

Could you try to add the following and see whether it makes any difference with VS 2017?

...

#include "libcellml/componententity.h"
#include "libcellml/exportdefinitions.h"

#ifndef SWIG
template class LIBCELLML_EXPORT std::enable_shared_from_this<libcellml::Model>;
#endif

//! Everything in libCellML is in this namespace.
namespace libcellml {

...

@agarny
Copy link
Contributor

agarny commented Jul 21, 2018

Ok, my bad, I should have read your warning message properly. My idea was correct, except that it should have read:

#ifndef SWIG
template class LIBCELLML_EXPORT std::weak_ptr<libcellml::Model>;
#endif

So, now, everything should be fine (it is using my local copy of VS 2017).

Copy link
Contributor

@nickerso nickerso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Phew! Everything is back working with no warnings for me. I'm happy with the changes Alan has made, but would be good for someone with a bit more C++ expertise to confirm the new approach for import recursion makes sense.

@MichaelClerx
Copy link
Contributor

Happy to look at the bindings bit for this once you're sure the interface is final!

@nickerso
Copy link
Contributor

pretty sure the interface is final, so would be good to look at the bindings.

@MichaelClerx MichaelClerx self-requested a review August 14, 2018 13:57
Copy link
Contributor

@MichaelClerx MichaelClerx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to merge this now, from a bindings point of view

* @brief Resolve all imports in this model.
*
* Resolve all @c Component and @c Units imports by loading the models
* from local disk through relative urls. The @p baseFile is used to determine
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to replace "urls" with "URLs" to be consistent with the rest of our documentation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On that note, these methods setUrl and getUrl and such, should they be capitalised this way? Or getURL etc.?
(Personally, my left shoulder likes using the shift key as little as possible)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, setUrl() and getUrl() should be left as-is. Indeed, we use lower camel case for class methods (see http://libcellml.readthedocs.io/en/latest/dev_coding_standard.html).


# void setReset(const ResetPtr &reset);
e = Error()
e.setReset(Reset())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely not a blocker, but not sure there is much point in having such a test (and similar ones) since setReset() is effectively tested as part of test_get_reset().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right, but I just wanted to be systematic in having a test for every method!

from libcellml import Model

m = Model()
m.resolveImports('file.txt')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No tests as such?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual functionality is tested by the C++ tests. Here I just want to check that the method exists and doesn't raise any exceptions!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

@agarny
Copy link
Contributor

agarny commented Aug 14, 2018

Apart from a few comments above, it all looks good to me.

@nickerso nickerso merged commit 41d06d9 into cellml:develop Aug 15, 2018
@hsorby hsorby mentioned this pull request Aug 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants