Skip to content

fix: simplify.resolve detects reference loop and throws error#2405

Merged
josdejong merged 8 commits into
josdejong:developfrom
gwhitney:resolve_loop
Feb 28, 2022
Merged

fix: simplify.resolve detects reference loop and throws error#2405
josdejong merged 8 commits into
josdejong:developfrom
gwhitney:resolve_loop

Conversation

@gwhitney
Copy link
Copy Markdown
Collaborator

@gwhitney gwhitney commented Feb 3, 2022

Also adds reference documentation and embedded documentation for simplify.resolve (with docs for simplify.simplifyCore coming along for the ride). Making these additions involved extending both doc facilities to handle functions "one level down" from the top level, and to support descriptions of what errors a function might throw (which were already present in the reference docs for several other functions, and so will now be displayed).

Also extends simplify.resolve to perform variable substitution within all node types (formerly it would be blocked by, e.g., an ArrayNode and not perform variable resolution within).

Adds tests for all new behaviors, including simplify.resolve throwing ReferenceErrors.

Resolves #2383.

Copy link
Copy Markdown
Owner

@josdejong josdejong left a comment

Choose a reason for hiding this comment

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

Really nice Job @gwhitney , thanks. I like that you took the time to improve on the automatically generated docs too.

I made a few minor inline remarks, and have one thought: shall we can flatten the function names simplify.simplifyCore and simplify.resolve into simplifyCore and simplifyResolve? So far the library doesn't have nested functions, and that is just of simple and straightforward :).

scope = createMap(scope)
}
if (isSymbolNode(node)) {
if (within.indexOf(node.name) !== -1) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Generally I prefer not to mutate function input arguments, but here with within (and only internally) it makes sense.

Would it make sense for performance to change make within a Set instead of an Array?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ah I was not thinking of a case with 100s of variables, but I suppose someone may want to use mathjs for such a case. Will change.

@@ -17,3 +17,39 @@ export const simplifyDocs = {
'derivative', 'parse', 'evaluate'
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can you add refrences to simplify.resolve and simplify.simplifyCore in simplify?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Will do, to their new top-level names.

Comment thread tools/docgenerator.js
'\n\n\n'
}

if (doc.mayThrow) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Nice improvements documenting the exceptions that a function may throw!

@gwhitney
Copy link
Copy Markdown
Collaborator Author

I made a few minor inline remarks, and have one thought: shall we can flatten the function names simplify.simplifyCore and simplify.resolve into simplifyCore and simplifyResolve? So far the library doesn't have nested functions, and that is just of simple and straightforward :).

I think naming should be entirely at your judgment and I can see in this comment and elsewhere that you favor a single layer of public names in mathJS. So I will revert the portions of this that track documentation down to a second layer, and move these two functions to the top layer. As for their names there, I'd suggest simplifyCore and resolve; the latter has a clear meaning and purpose on its own, independent of simplify, and the name does not conflict.

  For example, prior to this commit, docgenerator.js would miss
  simplify.resolve because it is not a direct key of the math
  object.

  Also incorporates any "throws" attributes in the comments into
  the generated documentation, and uses this to document the
  new error-case behavior of simplify.resolve to be added in the next
  commit.
  Also extends resolve to work inside all node types. Adds tests
  for both changes.
  To support finding the embedded doc from the `math.simplify.resolve`
  function itself, required extending the search for objects with
  documentation one level deeper in the `help()` function. Added test for
  this search.

  Also added support for documenting throws in embedded docs.
  Also reverts changes searching for docs and embedded docs one level
  down in the naming hierarchy.
  Also splits tests for resolve and simplifyCore into their own files,
  reflecting their new top-level status.
  Also removed a stray blank line inadvertently introduced in
  docgenerator.js
@gwhitney
Copy link
Copy Markdown
Collaborator Author

OK, I think that should take care of all of the feedback. Thanks.

@josdejong
Copy link
Copy Markdown
Owner

Thanks

As for their names there, I'd suggest simplifyCore and resolve

That sounds good 👍 . I do not see a conflict with some other function that we would want to call resolve.

@gwhitney
Copy link
Copy Markdown
Collaborator Author

Oh, I just realized that now that resolve and simplifyCore are at the top level, simplify should just register them as dependencies. Give me a minute and I will fix.

  ... rather than explicitly loading them, which is unnecessary now that they
  are at top level.
  Also register simplifyCore as a dependency to rationalize
@gwhitney
Copy link
Copy Markdown
Collaborator Author

Oh and I have to do the same for rationalize, and then add the dependencies to factoriesNumber so the build won't fail. Now it should be OK to merge.

Copy link
Copy Markdown
Owner

@josdejong josdejong left a comment

Choose a reason for hiding this comment

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

Thanks, looks good!

@josdejong
Copy link
Copy Markdown
Owner

This is published now in v10.2.0. Thanks Glen!

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.

simplify.resolve blows up call stack in case of recursive references

2 participants