Skip to content
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

Check there are no side effects before optimizing away compile time e… #9934

Merged
merged 1 commit into from Dec 31, 2018
Merged

Check there are no side effects before optimizing away compile time e… #9934

merged 1 commit into from Dec 31, 2018

Conversation

deech
Copy link
Contributor

@deech deech commented Dec 11, 2018

…xpressions.

Fixes #9817.

@deech
Copy link
Contributor Author

deech commented Dec 12, 2018

I'm seeing the following test failure on Travis:

lib/system.nim(4360, 23) Hint: 'exc' is declared but not used [XDeclaredButNotUsed]
megatest.nim(296, 8) Error: cannot open file: tcompiletimesideeffects.nim
megatest compilation failed

This is the test file I added as part of the PR. Running ./koch test didn't get this error, is there something else I need to do?

@Araq
Copy link
Member

Araq commented Dec 12, 2018

You should be able to reproduce this with testament/tester cat megatest

if result.isNil:
localError(c.config, n.info, errCannotInterpretNodeX % renderTree(call))
else: result = fixupTypeAfterEval(c, result, n)
if c.inStaticContext == 0: evalNow()
Copy link
Member

Choose a reason for hiding this comment

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

  1. This doesn't require a template as the condition can use an or operator.
  2. The condition should be c.inStaticContext > 0, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Fixed
  2. No, the idea is that if this expression is part of a larger compile time construct like block or when etc. evaluating it now in the presence of compile time side effects will cause the reported problem.

runNTimes(3, fill())
echo C3

# invoke fill() at runtime.
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment is wrong. Fill is compile time only. It may not be called at runtime, and it isn't. The expression fill() is substituted by it's result during compilation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@deech
Copy link
Contributor Author

deech commented Dec 28, 2018

@Araq The comments have been addressed, any chance this can be merged in?

@Araq Araq merged commit e879101 into nim-lang:devel Dec 31, 2018
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.

None yet

3 participants