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

feat: support backtrace in runtime #528

Merged
merged 2 commits into from
Apr 24, 2023
Merged

Conversation

NeverRaR
Copy link
Contributor

@NeverRaR NeverRaR commented Apr 24, 2023

1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):

  • N
  • Y

Close #525

2. What is the scope of this PR (e.g. component or file name):

KCLVM/kclvm/runtime
kclvm/compiler/src/codegen/

3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Other

feat: support backtrace in runtime

When a runtime error occurs, if the debug parameter is enabled, the compiler will track the backtrace and display,
e.g. If we try to compile the following kcl file,

import math

schema Fib:
    n1 = n - 1
    n2 = n1 - 1
    n: int
    value: int

    if n <= 1:
        value = math.log()
    elif n == 2:
        value = 1
    else:
        value = Fib {n = n1}.value + Fib {n = n2}.value


fib8 = Fib {n = 8}.value

then, we will get

KCLVM % kclvm_cli run --debug ./samples/hello.k           
error[E3M38]: error[E3M38]: EvaluationError
  --> /Users/neverrar/Projects/github/KCLVM/samples/hello.k:10:1
   |
10 |         value = math.log()
   |  log() takes exactly one argument (0 given)
   |
note: backtrace:
        0: kclvm_math_log
                at hello.k:10
        1: __main__.Fib
                at hello.k:10
        2: __main__.Fib
                at hello.k:14
        3: __main__.Fib
                at hello.k:14
        4: __main__.Fib
                at hello.k:14
        5: __main__.Fib
                at hello.k:14
        6: __main__.Fib
                at hello.k:14
        7: __main__.Fib
                at hello.k:14
        8: kclvm_main
                at hello.k:17

4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):

  • N
  • Y

5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:

  • Unit test
  • Integration test
  • Benchmark (add benchmark stats below)
  • Manual test (add detailed scripts or steps below)
  • Other

6. Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@coveralls
Copy link
Collaborator

coveralls commented Apr 24, 2023

Pull Request Test Coverage Report for Build 4783070781

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 87.988%

Totals Coverage Status
Change from base Build 4751693604: 0.0%
Covered Lines: 2300
Relevant Lines: 2614

💛 - Coveralls

@Peefy Peefy added the runtime Issues or PRs related to kcl runtime including value and value opertions label Apr 24, 2023
@Peefy Peefy added this to the v0.5.0 Release milestone Apr 24, 2023
@Peefy Peefy added the error-handling Issues or PRs related to kcl error handling label Apr 24, 2023
kclvm/runtime/src/value/api.rs Show resolved Hide resolved
kclvm/error/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@Peefy Peefy left a comment

Choose a reason for hiding this comment

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

LGTM

@NeverRaR NeverRaR merged commit b3343bf into kcl-lang:main Apr 24, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Apr 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
error-handling Issues or PRs related to kcl error handling runtime Issues or PRs related to kcl runtime including value and value opertions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] KCL runtime error traceback
3 participants