-
Notifications
You must be signed in to change notification settings - Fork 32
(Closes #3259) shorten generated names for basis/diff-basis arrays #3264
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
base: master
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3264 +/- ##
=======================================
Coverage 99.95% 99.95%
=======================================
Files 376 376
Lines 53485 53495 +10
=======================================
+ Hits 53463 53473 +10
Misses 22 22 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
This PR shortens the generated names used for various variables in order to avoid hitting compiler limitations as reported by Tom in #3259. Since we're no longer basing the names on existing variable names (which must be unique) I've had to increase the use of tags to ensure we cope in the face of name collisions. |
sergisiso
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good @arporter. Its good to see more symbols managed by tags. My only suggestion is to see if we can keep short names still readable, but feel free to ignore if it is to much work.
| self._boundary_dofs.append(self.BoundaryDofs(op_arg, bc_fs)) | ||
|
|
||
| def invoke_declarations(self): | ||
| def invoke_declarations(self) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this is a stylistic choice, but is the "-> None" needed when there is no return? None of my tooling complains with or without
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe some tools do complain - @hiker mentioned this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose this is mypy, I am using ty for typechecking and it does not complain. Anyway, if we need something I suggest NoReturn https://docs.python.org/3/library/typing.html#typing.NoReturn , the method does not return None.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it does. NoReturn indicates that a function never returns while a function without an explicit return does return None (at least, that's what pylint complains about if you ever have a function where it thinks you've missed a return statement).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, I agree
src/psyclone/lfric.py
Outdated
| symbol = self.symtab.find_or_create_tag( | ||
| basis, | ||
| symbol_type=DataSymbol, datatype=UnsupportedFortranType( | ||
| f"real(kind=r_def), allocatable :: {basis}{dims}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you did somewhere else, you will need to do:
new_name = self.symtab.next_available_name(basis)
if you embed the name in the datatype (as it may end up being different)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes, done.
| kind = const.QUADRATURE_TYPE_MAP["gh_quadrature_xyoz"]["kind"] | ||
| for name in self.qr_weight_vars["xyoz"]: | ||
| self.symtab.find_or_create( | ||
| self.symtab.find_or_create_tag( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new_name = self.symtab.next_available_name(...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good spot.
| :returns: a shortened form of the name. | ||
| ''' | ||
| new_parts = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe its a pain to do not that you already changed lots of tests, but some of the generated code is more cryptic now, have you considered doing:
if len(name) < threshold:
return name
to keep already short names descriptive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| # Split name string to find any_*_space ID and create a short name as | ||
| # "<start>" + "spc" + "ID" | ||
| # "<start>" + "s" + "ID" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this function still necessary now?, we could do:
self._shorten_arg_name(self.orig_name + "_" + arg.name)}
But if you decide not to remove the short_name do we really need to keep the _short_name and _mangled_name as state, it may be safer to compute them in the property method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've kept this one but have, as you suggest, removed the internal state in favour of dynamic computation.
| f"space '{self._orig_name}'") | ||
|
|
||
| @staticmethod | ||
| def _shorten_arg_name(name: str) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just "_shorten_name", it doesn't use the fact is an arg.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes.

No description provided.