Skip to content

Support external imports in functions#271

Merged
egparedes merged 7 commits intoGridTools:masterfrom
jdahm:support-imports-functions
Dec 3, 2020
Merged

Support external imports in functions#271
egparedes merged 7 commits intoGridTools:masterfrom
jdahm:support-imports-functions

Conversation

@jdahm
Copy link
Contributor

@jdahm jdahm commented Dec 1, 2020

Description

Support external imports in functions uniformly. These were already supported if the functions were called inline, however if the functions were an external, they were not resolved.

This contains a small fix for the frontend, as well as a terribly pathological test.

Requirements

Before submitting this PR, please make sure:

  • The code builds cleanly without new errors or warnings
  • The code passes all the existing tests
  • If this PR adds a new feature, new tests have been added to test these
    new features
  • All relevant documentation has been updated or added

Additionally, if this PR contains code authored by new contributors:

  • All the authors are covered by a valid contributor assignment agreement,
    signed by the employer if needed, provided to ETH Zurich
  • The names of all the new contributors have been added to an updated
    version of the AUTHORS.rst file included in the PR

@jdahm jdahm requested a review from egparedes December 1, 2020 05:51
Copy link
Contributor

@egparedes egparedes left a comment

Choose a reason for hiding this comment

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

Thanks for finding and fixing this bug. The PR looks fine but there is a typo in the code that should make the test fail. Please fix the typo and verify that the added tests is well defined and covers all the corner cases.

jdahm and others added 2 commits December 1, 2020 08:34
Co-authored-by: Enrique G. Paredes <18477+egparedes@users.noreply.github.com>
@jdahm
Copy link
Contributor Author

jdahm commented Dec 1, 2020

GitHub Actions failed here. There is no issue with formatting. I'll try to push a minor commit so that it rebuilds after ensuring there is full test coverage.

Comment on lines +178 to +201
def test_function_import(self, id_version):
module = f"TestInlinedExternals_test_recursive_imports_{id_version}"

def some_function():
from __externals__ import const

return const

def definition_func(inout_field: gtscript.Field[float]):
from __externals__ import some_call

with computation(PARALLEL), interval(...):
inout_field = some_call()

stencil_id, def_ir = compile_definition(
definition_func,
"test_recursive_imports",
module,
externals={"some_call": some_function, "const": GLOBAL_CONSTANT},
)
assert set(def_ir.externals.keys()) == {
"some_call",
"const",
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For reasons that still elude me, this test is necessary. I thought this was covered below, but this uncovered the need for the additional annotate call at gtscript_frontend.py:1477.

"const",
"other",
"func_nest1",
"tests.test_unittest.test_gtscript_frontend.func_nest1.func_nest2",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Externals captured implicitly get the fully qualified name.

Copy link
Contributor

@egparedes egparedes left a comment

Choose a reason for hiding this comment

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

The code looks correct although it's hard to say if all the corner cases are covered. Probably the cause of all the weird cases is allowing calls to undecorated functions, which I still think feels like the wrong pattern. Anyway, if you think this PR is done, we can merge it.

@jdahm
Copy link
Contributor Author

jdahm commented Dec 2, 2020

Yes, I believe this PR is ready, but should have a follow-up that cleans up the annotation system.

@egparedes egparedes merged commit 709da77 into GridTools:master Dec 3, 2020
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.

2 participants