Separate OpenMP from Pyccel's core functionalities and connect it as a Plugin#2338
Separate OpenMP from Pyccel's core functionalities and connect it as a Plugin#2338
Conversation
the support for exit is limited to calls with integral arguments or without arguments (same as exit(0))
Replace every class in the ast/omp.py with new classes the new classes have the same name as the textx grammar rules because these classes are used as the base classes for the textx instead of the ones found in pyccel/parser/syntax/openmp.py
the version field will be used to store the version of the omp grammer used for a Construct/Clause this is done by making the grammer sets a version field for the Clause/Construct if there are multile versions of the grammer
the grammer is not finished an only supports parallel constructs and its clauses
instead of hardcoding the rules in the syntactic/semantic/printing stages we just delegate the work to the omp class new functions there will be 5 functions _visit_syntatic, _visit_semantic, _cprint, _fprint, _pprint those functions will be called from the syntactic/semantic/printing stages and the omp class will be responsible for checking the if everything is corrent and provide the correct printing
this way we can support multiple version of omp withouth having to duplicate the code and just use inheritance and override the methods to change the behavior of the previous version
- add a version setter for the OmpAnnotatedComment class to be able to check if the syntax is supported by the version of omp - fixing liter errors
|
/bot run linux intel macosx windows |
|
/bot run linux |
|
I can't seem to find your checklist to confirm that you have completed all necessary tasks. Please request one using |
|
/bot run intel macosx windows |
|
/bot run coverage |
|
Here is your checklist. Please tick items off when you have completed them or determined that they are not necessary for this pull request:
|
|
@EmilyBourne I'm not sure about this error, as |
|
/bot run linux |
EmilyBourne
left a comment
There was a problem hiding this comment.
Do you think there is anyway to split this PR? It really is enormous and quite hard to review. I would love to split it into a Plugin part and an OpenMP part but I guess that would be tricky for testing? Could we have fake plugin for the tests in tests/plugin to get round this?
|
|
||
| ## Overview | ||
|
|
||
| The Pyccel plugin system allows Pyccel's functionality to be extended through plugins. Plugins can modify the behaviour of existing classes by patching their methods or adding new methods. This is particularly useful for adding support for new language features, optimisations, or code generation targets without modifying the core codebase. |
There was a problem hiding this comment.
Plugins can modify the behaviour of existing classes by patching their methods or adding new methods
Is this true for all classes or only certain classes (SyntaxParser, SemanticParser, Codegen) ?
|
|
||
| 1. `register(instances)` - Register instances with the plugin. This method should apply patches to the provided instances. | ||
| 2. `refresh()` - Refresh all registered targets. This method should reapply existing patches to registered targets and apply any new patches, if necessary. | ||
| 3. `deregister(instances)` - Deregister instances from the plugin. This method should remove all patches applied to the provided instances. |
There was a problem hiding this comment.
I thought you had decided to remove the deregister functionality given that new class instances are created when we run Pyccel anyway?
| 1. `register(instances)` - Register instances with the plugin. This method should apply patches to the provided instances. | ||
| 2. `refresh()` - Refresh all registered targets. This method should reapply existing patches to registered targets and apply any new patches, if necessary. | ||
| 3. `deregister(instances)` - Deregister instances from the plugin. This method should remove all patches applied to the provided instances. | ||
| 4. `set_options(options)` - Set options for the plugin. This method should update the plugin's behaviour based on the provided options. |
There was a problem hiding this comment.
Should there also be a get_options method? Maybe get_options_kwargs and get_parser_options to handle options passed via epyccel or pyccel?
| def load_plugins(self, plugins_dir=None): | ||
| """Discover and load all plugins from the plugins directory.""" | ||
| # ... |
There was a problem hiding this comment.
Have you timed this? What exactly is loaded here? Will it result in the grammar for all OpenMP versions being calculated? The call to redbaron is usually quite costly so if we can avoid it we probably should
There was a problem hiding this comment.
Is plugins_dir pyccel/plugins/MyPlugin/ or pyccel/plugins/?
| def register(self, registry): | ||
| """Apply patches to the target.""" | ||
| target = registry.target | ||
|
|
||
| # Example: Patch the 'parse' method | ||
| original_method = getattr(target, 'parse', None) | ||
|
|
||
| def parse(self, *args, **kwargs): | ||
| # Do something before the original method | ||
| print("Before parsing") | ||
|
|
||
| # Call the original method | ||
| result = original_method(self, *args, **kwargs) | ||
|
|
||
| # Do something after the original method | ||
| print("After parsing") | ||
|
|
||
| return result | ||
|
|
||
| # Apply the patch |
There was a problem hiding this comment.
Ok. Maybe add a comment stating that functions should usually be defined in the module not the function otherwise people are likely to take this as the best practice example
| OmpTxIntegerExpr: value=InnerContent | ParenthesisContent; | ||
| OmpTxConstantPositiveInteger: value=/[0-9]+/; | ||
| OmpTxList: throw_away+=ID[',']; | ||
| ParenthesizedExpression: (('(' ParenthesizedExpression ')') | /[^()]*/)*; // TODO: find a better way to do this as this will not escape the parenthesis inside of a string |
There was a problem hiding this comment.
Can you elaborate more on this TODO? Maybe I can help? Usually .tx files are designed to handle parsing in a way that is more explicit than regexes to avoid this kind of issue.
There was a problem hiding this comment.
Maybe you are just missing something that matches a string?
| OmpTxList: throw_away+=ID[',']; | ||
| ParenthesizedExpression: (('(' ParenthesizedExpression ')') | /[^()]*/)*; // TODO: find a better way to do this as this will not escape the parenthesis inside of a string | ||
| DataSharingAttribute: ('shared' | 'none' | 'private' | 'firstprivate'); | ||
| ReductionOperator: ('+' | '-' | '*' | '&' | '|' | '^' | '&&' | '||' | 'min' | 'max'); // TODO: those are only the implicitly declared ones for C and C++. Add the others for Fortran and support user-defined ones (see specs https://www.openmp.org/spec-html/5.0/openmpsu107.html#x140-581002) |
| position : tuple | ||
| The start and end positions of the OpenMP syntax in the source code, | ||
| used to print errors. |
There was a problem hiding this comment.
Ok. Please add a comment about this


This PR reintroduces OpenMP in Pyccel as a standalone plugin, interfacing with Pyccel via a plugins utility.
Plugins Utility
The plugins module provides the basic classes from which every plugin should inherit, and it's the main interface to the plugins from Pyccel.
Core Functionality
set_optionsis called; for the changes to take place,set_optionsshould be called withrefreshset toTrueOpenMP Plugin
Plugin Behavior
Classes
OmpTxNode, which itself inherits fromOmpNode; visiting these classes results in instances of their respective classes that inherit fromOmpNode