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

Extended side effect error messages #18418

Merged
merged 11 commits into from
Jul 15, 2021

Conversation

quantimnot
Copy link
Contributor

@quantimnot quantimnot commented Jul 2, 2021

Fixes #4210
Fixes #10712

Is this the right approach?
Any desired changes to make the messages clearer?
All feedback is welcome.

compiler/sempass2.nim Outdated Show resolved Hide resolved
compiler/sempass2.nim Outdated Show resolved Hide resolved
compiler/sempass2.nim Outdated Show resolved Hide resolved
compiler/sempass2.nim Outdated Show resolved Hide resolved
- refactored `markSideEffect`
- refactored string interpolations
- single message
- skip diagnostics in `system.compiles` context

Other:
- started a test of diagnostic messages

[ci skip] Tests aren't updated yet because messaging isn't nailed down.
@quantimnot
Copy link
Contributor Author

I just found nim-lang/RFCs#323 and nim-lang/RFCs#324.

I'm not sure what to apply from those discussions.

bung87 pushed a commit to bung87/Nim that referenced this pull request Jul 4, 2021
* added float32 schubfach algorithm; wip

* fixes nim-lang#18418
@quantimnot
Copy link
Contributor Author

tests/effects/tdiagnostic_messages.nim:

var globalVar = 0
proc indirectCallViaVarParam(call: var proc(): int {.nimcall.}): int =
  call()
proc indirectCallViaPointer(call: pointer): int =
  cast[ptr proc(): int](call)[]()
proc callWithSideEffects(): int =
  var p = proc (): int {.nimcall.} = 0
  discard indirectCallViaVarParam(p)
  discard indirectCallViaPointer(addr p)
  echo ""
  globalVar

func a: int =
  discard callWithSideEffects()

Here is the current state of rendering:

Terminal:

tdiagnostic_messages.nim(31, 6) Error: 'a' has side effects
  tdiagnostic_messages.nim(32, 30) Hint: 'a' calls 'callWithSideEffects' which has side effects
    tdiagnostic_messages.nim(24, 6) Hint: 'callWithSideEffects' called by a `noSideEffect` routine, but has side effects
      tdiagnostic_messages.nim(26, 34) Hint: 'callWithSideEffects' calls 'indirectCallViaVarParam' which has side effects
        tdiagnostic_messages.nim(20, 6) Hint: 'indirectCallViaVarParam' called by a `noSideEffect` routine, but has side effects
          tdiagnostic_messages.nim(21, 7) Hint: 'indirectCallViaVarParam' calls a routine with side effects via hidden pointer indirection
      tdiagnostic_messages.nim(27, 33) Hint: 'callWithSideEffects' calls 'indirectCallViaPointer' which has side effects
        tdiagnostic_messages.nim(22, 6) Hint: 'indirectCallViaPointer' called by a `noSideEffect` routine, but has side effects
          tdiagnostic_messages.nim(23, 32) Hint: 'indirectCallViaPointer' calls a routine with side effects via pointer indirection
      tdiagnostic_messages.nim(28, 8) Hint: 'callWithSideEffects' calls 'echo' which has side effects
        ../../lib/system.nim(2004, 6) Hint: 'echo' called by a `noSideEffect` routine, but has side effects
      tdiagnostic_messages.nim(29, 3) Hint: 'callWithSideEffects' accesses global state 'globalVar'
        tdiagnostic_messages.nim(19, 5) Hint: 'globalVar' accessed by a `noSideEffect` routine

VSCode:

vscode

compiler/ast.nim Outdated Show resolved Hide resolved
compiler/sempass2.nim Outdated Show resolved Hide resolved
compiler/sempass2.nim Outdated Show resolved Hide resolved
compiler/sempass2.nim Outdated Show resolved Hide resolved
compiler/sempass2.nim Outdated Show resolved Hide resolved
compiler/sempass2.nim Outdated Show resolved Hide resolved
@quantimnot
Copy link
Contributor Author

The terminal rendering's structure gives context to the hints about what noSideEffect routine is trying to use routines with side effects.
The VSCode hints don't provide that context. Should I change them to someting like:
Hint: 'indirectCallViaVarParam' called by `a`

  - moved collection of side effects from TSym to TContext
  - used pragma shorthand form `.sideEffect` and `.noSideEffect` in messages
  - added leading '>' to structured messages for readability
  - changed `sempass2.markSideEffect` to a proc
  - replaced `system.echo` in the test to make the test compatible with Windows
Copy link
Member

@timotheecour timotheecour left a comment

Choose a reason for hiding this comment

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

LGTM, excellent addition

@RSDuck
Copy link
Contributor

RSDuck commented Jul 5, 2021

please rather look at https://github.com/saem/vscode-nim as it's error parsing code has gotten some fixes (and also feature additions). https://github.com/pragmagic/vscode-nim is somewhat dead.

@quantimnot quantimnot marked this pull request as ready for review July 6, 2021 00:03
@quantimnot
Copy link
Contributor Author

Don't merge. I just notice a small bug. Give me a minute.

@quantimnot
Copy link
Contributor Author

@timotheecour
Please take another look at the message changes I just made. I'm exhausted and my mind isn't working.
Ready to merge if it's ok.

@RSDuck
I just submitted a PR to support the leading '>' in the diagnostic messages.

@quantimnot
Copy link
Contributor Author

Current rendering with saem/vscode-nim:
msg

@quantimnot
Copy link
Contributor Author

I don't know why the checks failed:

cmd: git -C csources_v1 checkout a8a5241f9475099c823cfe1a5e0ca4022ac201ff
fatal: reference is not a tree: a8a5241f9475099c823cfe1a5e0ca4022ac201ff

@Araq
Copy link
Member

Araq commented Jul 6, 2021

I don't know why the checks failed

Me neither, I'm investigating...

@timotheecour
Copy link
Member

I don't know why the checks failed

retry now that #18427 was merged

@Araq Araq closed this Jul 6, 2021
@Araq Araq reopened this Jul 6, 2021
@quantimnot
Copy link
Contributor Author

Don't merge. I getting an exception while using nimsuggest:

/Volumes/origin/ws/ports/rdn/org.nim-lang.nim/origin.src/compiler/sempass2.nim(292) listSideEffects
/Volumes/origin/ws/ports/rdn/org.nim-lang.nim/origin.src/lib/pure/strutils.nim(2698) addf
/Volumes/origin/ws/ports/rdn/org.nim-lang.nim/origin.src/lib/pure/strutils.nim(2638) invalidFormatString
Error: unhandled exception: invalid format string [ValueError]

@timotheecour
Copy link
Member

timotheecour commented Jul 15, 2021

@Araq is there anything else blocking this PR to be merged? there has been no pending review comment since 8 days ago

Leaving PRs open for a long time guarantees bitrot and eventual demotivation from PR author, eventually joining the train of the 200+ open abandoned PRs where original author gave up, despite being in a mergeable state at some point.

the concern regarding "how costly is this" was answered in #18418 (comment)

@Araq
Copy link
Member

Araq commented Jul 15, 2021

Sorry, it said

Don't merge. I getting an exception while using nimsuggest:

Will test it on my machine wrt memory consumption and then merge it.

@timotheecour
Copy link
Member

Sorry, it said [...]

that was fixed in the "fixed double string formatting bug" commit;
if anything, this proves that the "PTAL" label is a good idea (author can add it when ready for next round/merge, anyone can remove it when comments are added / some action is needed on the PR author part)

@Araq Araq merged commit a9701f6 into nim-lang:devel Jul 15, 2021
@Araq
Copy link
Member

Araq commented Jul 15, 2021

Can confirm that the memory and CPU consumption is acceptable.

@Araq
Copy link
Member

Araq commented Jul 15, 2021

Btw this needs a changelog entry.

@quantimnot quantimnot deleted the extended_side_effect_error_msgs branch September 9, 2021 23:44
PMunch pushed a commit to PMunch/Nim that referenced this pull request Mar 28, 2022
* added float32 schubfach algorithm; wip

* fixes nim-lang#18418
PMunch pushed a commit to PMunch/Nim that referenced this pull request Mar 28, 2022
* Extended side effect error messages

* Applied feedback:
- refactored `markSideEffect`
- refactored string interpolations
- single message
- skip diagnostics in `system.compiles` context

Other:
- started a test of diagnostic messages

[ci skip] Tests aren't updated yet because messaging isn't nailed down.

* - Added hints of where for side effect call locations.
- Tried to clarify the reasons.

* fix tests

* Applied PR review feedback:
  - moved collection of side effects from TSym to TContext
  - used pragma shorthand form `.sideEffect` and `.noSideEffect` in messages
  - added leading '>' to structured messages for readability
  - changed `sempass2.markSideEffect` to a proc
  - replaced `system.echo` in the test to make the test compatible with Windows

* Applied NEP1 formatting suggestion

Co-authored-by: quantimnot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants