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

Add DeclareGlobalName; together with BindGlobal it can be used to replace uses of DeclareGlobalVariable & InstallValue (which are not thread safe and have other dangers) #3858

Merged
merged 2 commits into from
Apr 28, 2020

Conversation

fingolfin
Copy link
Member

@fingolfin fingolfin commented Jan 17, 2020

With DeclareGlobalName one can mark the name of a global variable as "will be defined". The only effect this has is that it suppresses "Unbound Global Variable" warnings.

This can be used in many cases to replace uses of DeclareGlobalVariable & InstallValue respectively DeclareGlobalFunction & InstallGlobalFunction by DeclareGlobalName & BindGlobal.

This PR complements PR #3857.

TODO:

  • add documentation for DeclareGlobalName (didn't want to spend work on that before I had any feedback on this design)
  • bikeshed^H^H^ decide the name: DeclareGlobalName? DeclareName? DeclareGlobal? Something else?

@fingolfin fingolfin added the release notes: not needed PRs introducing changes that are wholly irrelevant to the release notes label Jan 17, 2020
@ChrisJefferson
Copy link
Contributor

So, my only thought is that unlike the old DeclareGlobalVariable / InstallName, we don't "check" the two are in sync, so I can do DeclareGlobalName("nameA");, then BindGlobal("nameB", [1,2,3]), and nothing there is no warning I've used "nameA" in one place, and "nameB" in another.

This can't be fixed without introducing something like BindGlobalName (which is definitely a horrible name) which will only bind things previously defined with DeclareGlobalName.

We might decide this isn't a significant concern, but I just wanted to mention it.

@fingolfin
Copy link
Member Author

If that happens, then one of these happens:

  • if any code tries to use nameA, it will immediately run into an error, and the issue is discovered;
  • otherwise, if only nameB is used and no "unbound global variable" is shown, then the call to DeclareGlobalName was redundant and can be removed. Of course nobody might notice -- but there seems no harm in this, other than perhaps confusing somebody (e.g. because nameA appears in the documentation) -- but once they try to use it, they'll immediately get an error (and hopefully report it to us / to the author of the code in question).

So all in all, it seems there is not much we loose there?

@coveralls
Copy link

coveralls commented Jan 17, 2020

Coverage Status

Coverage decreased (-0.0008%) to 84.33% when pulling 5eabdf1 on fingolfin:mh/DeclareGlobalName into 8e10d8a on gap-system:master.

Copy link
Contributor

@ChrisJefferson ChrisJefferson left a comment

Choose a reason for hiding this comment

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

I'm happy with this. I'm going to give it another few days for anyone who wants to comment on design / names.

@fingolfin
Copy link
Member Author

But this still lacks documentation...

@fingolfin fingolfin force-pushed the mh/DeclareGlobalName branch 2 times, most recently from b140284 to 348814b Compare January 29, 2020 00:32
Copy link
Member

@wilfwilson wilfwilson left a comment

Choose a reason for hiding this comment

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

I think the setup is fine. I’d perhaps prefer just DeclareGlobal, but as you say - bikeshedding, and DeclareGlobalName is totally clear and appropriate.

Would approve with doc.

@ssiccha
Copy link
Contributor

ssiccha commented Apr 6, 2020

I like the idea. 👍

@fingolfin fingolfin force-pushed the mh/DeclareGlobalName branch 2 times, most recently from a9c3a19 to 6b61da9 Compare April 6, 2020 22:48
@@ -180,8 +180,7 @@ DeclareGlobalFunction( "CharValueSymmetric" );
## </Description>
## </ManSection>
##
DeclareGlobalVariable( "CharTableSymmetric",
"generic character table of symmetric groups" );
DeclareGlobalName( "CharTableSymmetric" );
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that the second argument to DeclareGlobalVariable always was ignored, so it's safe to discard it here and elsewhere.

@fingolfin
Copy link
Member Author

I've now added some documentation, so this could potentially be merged, after a fresh round of reviews.

@fingolfin
Copy link
Member Author

Note that I only added docs for DeclareGlobalName, but I did not adjust the docs for DeclareGlobalVariable and DeclareGlobalFunction to reference it; I guess I should, though, and explain there that DeclareGlobalName usually is preferable? Argh. Anybody here like writing docs more than I do? sigh

@ssiccha ssiccha self-assigned this Apr 7, 2020
@ssiccha
Copy link
Contributor

ssiccha commented Apr 9, 2020

I've updated and slightly tweaked the documentation of DeclareGlobalVariable and DeclareGlobalFunction and I've fixed typos in the doc of DeclareGlobalName. What do all of you think?

Copy link
Contributor

@ChrisJefferson ChrisJefferson left a comment

Choose a reason for hiding this comment

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

one tiny comment

doc/ref/create.xml Outdated Show resolved Hide resolved
@fingolfin fingolfin added kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements release notes: to be added PRs introducing changes that should be (but have not yet been) mentioned in the release notes topic: library and removed release notes: not needed PRs introducing changes that are wholly irrelevant to the release notes labels Apr 11, 2020
@fingolfin
Copy link
Member Author

@ssiccha thanks! I've now squashed this, split the commit differently, and edited the documentation further. Please have a look again.

@fingolfin
Copy link
Member Author

I split the actual changes which replace uses of DeclareGlobalVariable by DeclareGlobalName into a second commit, so that it's easier tor review the core changes by just looking at the first commit.

I should note that one could (should?) also treat most uses of DeclareGlobalFunction this way, also it is less important, because we "only" modify function objects here, and that's a bit less critical... although in the HPC-GAP context it could still be serious problem. I just didn't have time for it and it wasn't a priority, but a future PR could take care of many of them.

And once this release in GAP 4.12, we could of course start changing packages to use this, but I expect this to be a slow process

Copy link
Contributor

@ssiccha ssiccha left a comment

Choose a reason for hiding this comment

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

LGTM, apart from the typo.

lib/variable.g Outdated Show resolved Hide resolved
hpcgap/lib/variable.g Outdated Show resolved Hide resolved
fingolfin and others added 2 commits April 11, 2020 12:58
With DeclareGlobalName one can mark the name of a global
variable as "will be defined". The only effect this has is that
it suppresses "Unbound Global Variable" warnings.

This can be used in many cases to replace uses of `DeclareGlobalVariable` &
`InstallValue` respectively `DeclareGlobalFunction` & `InstallGlobalFunction`
by `DeclareGlobalName` & `BindGlobal`.

Co-authored-by: Sergio Siccha <sergio.siccha@gmail.com>
@fingolfin
Copy link
Member Author

@ChrisJefferson OK to approve/merge?

@ChrisJefferson
Copy link
Contributor

Yes, I'm happy. Thanks all!

@ChrisJefferson ChrisJefferson merged commit 552d635 into gap-system:master Apr 28, 2020
@fingolfin fingolfin deleted the mh/DeclareGlobalName branch April 28, 2020 13:30
@ThomasBreuer ThomasBreuer self-assigned this Feb 17, 2021
@ThomasBreuer ThomasBreuer added release notes: added PRs introducing changes that have since been mentioned in the release notes and removed release notes: to be added PRs introducing changes that should be (but have not yet been) mentioned in the release notes labels Feb 17, 2021
@ThomasBreuer ThomasBreuer removed their assignment Feb 17, 2021
@fingolfin fingolfin changed the title Add DeclareGlobalName to get rid of more uses of InstallValue Add DeclareGlobalName; together with BindGlobal it can be used to replace uses of DeclareGlobalVariable & InstallValue (which are not thread safe and have other dangers) Aug 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements kind: new feature release notes: added PRs introducing changes that have since been mentioned in the release notes topic: library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants