Skip to content

Add basic symbol table functionality (towards #201)#293

Merged
rupertford merged 33 commits intomasterfrom
201_symbol_table
Dec 8, 2021
Merged

Add basic symbol table functionality (towards #201)#293
rupertford merged 33 commits intomasterfrom
201_symbol_table

Conversation

@arporter
Copy link
Member

No description provided.

@arporter arporter marked this pull request as draft February 23, 2021 16:03
@codecov
Copy link

codecov bot commented Feb 23, 2021

Codecov Report

Merging #293 (4d8228a) into master (6558244) will increase coverage by 0.13%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #293      +/-   ##
==========================================
+ Coverage   90.95%   91.09%   +0.13%     
==========================================
  Files          35       36       +1     
  Lines       12917    13107     +190     
==========================================
+ Hits        11749    11940     +191     
+ Misses       1168     1167       -1     
Impacted Files Coverage Δ
src/fparser/two/Fortran2003.py 92.92% <100.00%> (-0.02%) ⬇️
src/fparser/two/parser.py 92.55% <100.00%> (+0.24%) ⬆️
src/fparser/two/symbol_table.py 100.00% <100.00%> (ø)
src/fparser/two/utils.py 95.38% <100.00%> (+0.50%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6558244...4d8228a. Read the comment docs.

@arporter
Copy link
Member Author

Hi @rupertford, this isn't finished yet but would you mind having a glance over it just to confirm you're happy with the direction?

@rupertford
Copy link
Collaborator

Hi @rupertford, this isn't finished yet but would you mind having a glance over it just to confirm you're happy with the direction?

Hi @arporter. It looks great. I really like the scoping, symbol tables singleton and symbol table hierarchy. My only comments/questions are

  1. I presume we will have to support different types of symbols. I see that you capture module use separately, which is nice and simple but shouldn't the module name be added as a symbol (in a future PR)?
  2. is capture_matched_symbol the best way to go? It is very nice but its interface is generic so it means that the context needs to be determined within the function and given that the context will be known when matching (as the classes are specific) it seems like it would be easier to have the logic associated with the class itself. I think this will become more true as we support more symbol types (assuming that is what we do).
  3. Would it be useful to have a str for SymbolTables as well as SymbolTable?
  4. Do we need a singleton for SymbolTables, i.e can we always create one instance at the "start" and just use it? We would then not need to do .get() all the time.
  5. It seems a shame to have to add so many symbol table decorators around tests, but I guess that is just the way it is as there is no scoping information.
  6. Do we need a "full name" for a symbol table given that they are in a hierarchy?

@arporter
Copy link
Member Author

re. your question 6., not unless we want only the top-level symbol tables to by stored in SymbolTables. Otherwise we would get a clash, e.g. if two different modules contained a subroutine with the same name. I'm not sure what the best approach is although I'm tempted to say that perhaps we should only store the top-level tables. Should we ever need to look at all symbols (and I can't think why we would), we could go through each of these and then down the hierarchy that they contain.

@rupertford
Copy link
Collaborator

re. your question 6., not unless we want only the top-level symbol tables to by stored in SymbolTables. Otherwise we would get a clash, e.g. if two different modules contained a subroutine with the same name. I'm not sure what the best approach is although I'm tempted to say that perhaps we should only store the top-level tables. Should we ever need to look at all symbols (and I can't think why we would), we could go through each of these and then down the hierarchy that they contain.

Yes, that is what I was wondering. If we store the tables in a hierarchy and don't have a dictionary lookup then we would not need a "full name".

@arporter
Copy link
Member Author

re. your question/comment 5. I think it would be possible to silently ignore the symbol table functionality if ever current_scope came back as None. However, that's letting the implementation be twisted so as to fix a testing issue and that's often not a good thing.

@arporter
Copy link
Member Author

arporter commented Mar 4, 2021

This is now ready for a proper review. Note that although use statements are captured, any symbols named in 'only' clauses are not currently captured as symbols. Probably we will need a class to represent Symbols and this could have a module property if the symbol is imported from a module. That would then be the key for the symbol table containing the symbol definition. Anyway, that's something for the next PR.

Copy link
Collaborator

@rupertford rupertford left a comment

Choose a reason for hiding this comment

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

This is a really nice implementation of a key piece of functionality. There are lots of comments (sorry) but only a few major issues/questions 1) what about programs without the program keyword, 2) what about the robustness of creating a symbol table (might we need to remove one if there is not match in BlockBase and 3) should different symbol types be added and stored in different lists/dictionaries, or in one place.

@rupertford rupertford added reviewed with actions PR has been reviewed and is back with developer and removed under review labels Apr 19, 2021
@arporter arporter marked this pull request as ready for review November 11, 2021 16:30
@arporter
Copy link
Member Author

This is ready for another look now @rupertford.

@arporter arporter added ready for review and removed reviewed with actions PR has been reviewed and is back with developer labels Nov 11, 2021
Copy link
Collaborator

@rupertford rupertford left a comment

Choose a reason for hiding this comment

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

All issues have been addressed. However, the diff coverage is not 100%. Could you please take a look and add appropriate tests if possible.

@rupertford rupertford added reviewed with actions PR has been reviewed and is back with developer and removed under review labels Dec 2, 2021
@arporter
Copy link
Member Author

arporter commented Dec 6, 2021

I'm not sure what to do about one of the diff coverage problems (L595-596 in utils.py) - it is code that I've touched in that I've now surrounded that block of code with a try, although I've not altered the code itself (apart from indentation, obviously). I've run the parser over the whole of NEMO and the un-covered condition is never triggered, I think because Label_Do_Stmt never raises a NoMatchError - it just returns None if there's no match. Therefore, I could remove the try...except around the match but I feel a bit uneasy about that. What do you think?

@arporter
Copy link
Member Author

arporter commented Dec 7, 2021

In running this branch on the NEMOVAR code base I discovered an error that occurs when trying to remove a symbol table after a syntax error has occurred - I was only looking at the list of top-level tables and not looking within the current scope. I've updated the code to do this and now I think all syntax errors are related to overridden intrinsics.

@arporter
Copy link
Member Author

arporter commented Dec 7, 2021

OK, ready for another round. I've decided I don't understand the BlockBase.match() method but have succeeded in removing a couple of flags that don't appear to do anything useful. I've tested with NEMO and NEMOVAR and it all seems fine. That said, I'll try using PSyclone with this version of fparser and see what happens.

@arporter arporter added ready for review and removed reviewed with actions PR has been reviewed and is back with developer labels Dec 7, 2021
@arporter
Copy link
Member Author

arporter commented Dec 7, 2021

I can confirm that I can process and then compile NEMO using this version of fparser and master of PSyclone.

@rupertford rupertford added ready for merge PR is waiting on final CI checks before being merged. and removed under review labels Dec 8, 2021
Copy link
Collaborator

@rupertford rupertford left a comment

Choose a reason for hiding this comment

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

All issues have been addressed. I took the liberty of fixing a typo and a missing copyright date update. This is a significant new piece of functionality. It's all very exciting.

@rupertford rupertford merged commit e0b14f8 into master Dec 8, 2021
@rupertford rupertford deleted the 201_symbol_table branch December 8, 2021 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for merge PR is waiting on final CI checks before being merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants