Skip to content

Replace assertion errors on IR assumption violation - #7223

Merged
sklam merged 12 commits into
numba:masterfrom
sklam:fix/iss7217
Jul 30, 2021
Merged

sklam merged 12 commits into
numba:masterfrom
sklam:fix/iss7217

Conversation

@sklam

@sklam sklam commented Jul 20, 2021

Copy link
Copy Markdown
Member

with pedantic warnings.

Closes #7217

@sklam sklam added this to the Numba 0.54 RC3 milestone Jul 20, 2021
Comment thread numba/core/ssa.py Outdated
Comment on lines +270 to +275
if newtarget.name not in scope.localvars:
wmsg = (
f"variable name {newtarget.name!r} not in scope "
f"in {assign} on line {assign.loc}",
)
warnings.warn(errors.NumbaIRAssumptionWarning(wmsg))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
if newtarget.name not in scope.localvars:
wmsg = (
f"variable name {newtarget.name!r} not in scope "
f"in {assign} on line {assign.loc}",
)
warnings.warn(errors.NumbaIRAssumptionWarning(wmsg))
if newtarget.name not in scope.localvars:
wmsg = f"variable name {newtarget.name!r} not in scope"
warnings.warn(errors.NumbaIRAssumptionWarning(wmsg, loc=assign.loc))

Does it help to use Numba's error message loc handling here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

oh, i forgot that it has that

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

changed in ec01acd

@sklam
sklam marked this pull request as ready for review July 21, 2021 15:01
@sklam
sklam requested a review from esc as a code owner July 21, 2021 15:01
@stuartarchibald

Copy link
Copy Markdown
Contributor

Note: verified behaviour in ec01acd against #7217 (comment)

@stuartarchibald stuartarchibald left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the patch. There's a few minor things to resolve but looks good else.

Comment thread numba/core/ssa.py Outdated
Comment thread numba/tests/test_ir.py Outdated
Comment thread numba/tests/test_ir.py Outdated
Comment thread numba/tests/test_ir.py Outdated
Comment thread numba/tests/test_ir.py Outdated
Comment thread numba/tests/test_ir.py Outdated
Comment on lines +533 to +534
# import logging
# logging.basicConfig(level=logging.DEBUG)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Dead comments

Comment thread numba/core/errors.py Outdated
@stuartarchibald stuartarchibald added 4 - Waiting on author Waiting for author to respond to review Effort - short Short size effort needed and removed 3 - Ready for Review labels Jul 21, 2021
sklam and others added 2 commits July 21, 2021 15:40
Co-authored-by: stuartarchibald <stuartarchibald@users.noreply.github.com>

@stuartarchibald stuartarchibald left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Couple of suggestions to hopefully fix the build.

Comment thread numba/tests/test_ir.py Outdated
Comment on lines +534 to +535
# import logging
# logging.basicConfig(level=logging.DEBUG)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
# import logging
# logging.basicConfig(level=logging.DEBUG)

Comment thread numba/tests/test_ir.py Outdated
# Verify the error message
self.assertRegex(
str(raises.exception),
r"variable name '[a-z]' not in scope",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
r"variable name '[a-z]' not in scope",
r"variable '[a-z]' is not in scope",

@sklam

sklam commented Jul 21, 2021 •

Copy link
Copy Markdown
Member Author

Btw, i'm trying out if the warning message should suggest users to report.

Currently, the warning looks like:

/path/to/numba/core/ssa.py:272: NumbaIRAssumptionWarning: variable 'a' is not in scope.
  warnings.warn(errors.NumbaIRAssumptionWarning(wmsg,
/path/to/numba/core/ssa.py:272: NumbaIRAssumptionWarning: variable 'b' is not in scope.
  warnings.warn(errors.NumbaIRAssumptionWarning(wmsg,

With the suggestion:

/path/to/numba/core/ssa.py:272: NumbaIRAssumptionWarning: variable 'b' is not in scope.
This error came from an internal pedantic check. Please report the error message
and traceback, along with a minimal reproducer at:
https://github.com/numba/numba/issues/new

  warnings.warn(errors.NumbaIRAssumptionWarning(wmsg,
/path/to/numba/core/ssa.py:272: NumbaIRAssumptionWarning: variable 'a' is not in scope.
This error came from an internal pedantic check. Please report the error message
and traceback, along with a minimal reproducer at:
https://github.com/numba/numba/issues/new

  warnings.warn(errors.NumbaIRAssumptionWarning(wmsg,

The long message can be very annoying.

@stuartarchibald

Copy link
Copy Markdown
Contributor

RE #7223 (comment) Whilst the long messages are not great, I'd hope that the frequency at which this is hit is really small else it indicates a lot more problems. I guess this comes down to our confidence around having got Numba's internals sufficiently fixed up for this to be a rarity and definitely something that should be reported vs. an annoyance?

Comment thread numba/tests/test_ir.py Outdated

def run_pass(self, state):
# This is unreachable. SSA pass should have raised before this
# pass when run with `error.NumbaPedanicWarning`s raised as

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
# pass when run with `error.NumbaPedanicWarning`s raised as
# pass when run with `error.NumbaPedanticWarning`s raised as

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed

@sklam sklam added 4 - Waiting on reviewer Waiting for reviewer to respond to author and removed 4 - Waiting on author Waiting for author to respond to review labels Jul 22, 2021
Comment thread numba/core/errors.py Outdated


pedantic_warning_info = """
This error came from an internal pedantic check. Please report the error message

@stuartarchibald stuartarchibald Jul 22, 2021 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
This error came from an internal pedantic check. Please report the error message
This warning came from an internal pedantic check. Please report the warning message

(this will need a line wrap)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed

@sklam sklam added 4 - Waiting on author Waiting for author to respond to review and removed 4 - Waiting on reviewer Waiting for reviewer to respond to author 4 - Waiting on author Waiting for author to respond to review labels Jul 22, 2021
@sklam sklam added the 4 - Waiting on reviewer Waiting for reviewer to respond to author label Jul 22, 2021
@sklam

sklam commented Jul 27, 2021

Copy link
Copy Markdown
Member Author

@esc, can you review this? It's just need a last look.

@esc esc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A few minor things to edit, ready to merge after that.

Comment thread numba/core/errors.py Outdated
Comment thread numba/tests/test_ir.py
return [pm]

@njit(pipeline_class=MyCompiler)
def dummy(x):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Perhaps add a comment explaining why this dummy is needed: multiple assignments to the same variable name are needed to trigger SSA.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done in 3d6fb07

sklam and others added 2 commits July 29, 2021 11:45
@sklam
sklam requested a review from esc July 29, 2021 16:50
Comment thread numba/core/errors.py

feedback_details = """
Please report the error message and traceback, along with a minimal reproducer
at: https://github.com/numba/numba/issues/new

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you want to update this URL too, while there?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Let's do this in a future PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

i've made a task issue for it: #7261

@esc esc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Changes are fine, I left one comment but that is perhaps something for a future PR.

@esc esc added 5 - Ready to merge Review and testing done, is ready to merge and removed 4 - Waiting on reviewer Waiting for reviewer to respond to author labels Jul 30, 2021
@sklam
sklam merged commit 01dc3b4 into numba:master Jul 30, 2021
@sklam
sklam deleted the fix/iss7217 branch July 30, 2021 19:30
sklam added a commit to sklam/numba that referenced this pull request Aug 4, 2021
Replace assertion errors on IR assumption violation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5 - Ready to merge Review and testing done, is ready to merge Effort - short Short size effort needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: SSA scope check assertion error

3 participants