Error Message Improvement for Host Variables (#116) #168

Merged
sb10q merged 1 commits from err_msg_host_var into master 2024-08-17 17:37:19 +08:00
Collaborator

Program1 with error:

from numpy import int32, int64
from min_artiq import *

@nac3
class Demo:
    core: KernelInvariant[Core]
    y: Kernel[int32]

    def __init__(self):
        self.core = Core()
        self.y = int64(0)

    @kernel
    def run(self):
        pass


if __name__ == "__main__":
    Demo().run()

previous error msg:

RuntimeError: nac3 compilation failure: unknown identifier base (use before def?) at unknown: line 2 column 5

now error msg (location will just be the cpython error location):

RuntimeError: type error of object launching kernel: error when getting type of field `y` (Cannot unify int64 with int32)

Program2 with error:

from numpy import int32, int64
from min_artiq import *

l = [1, 2, 3.1]

@nac3
class Demo:
    core: KernelInvariant[Core]
    y: Kernel[int32]

    def __init__(self):
        self.core = Core()
        self.y = 0

    @kernel
    def run(self):
        for i in l:
            pass

if __name__ == "__main__":
    Demo().run()

previous err msg:

RuntimeError: nac3 compilation failure: unknown identifier l (use before def?) at /home/cresc/code/nac3/work1/nac3/my_expr/artiq/host_var_err.py: line 53 column 18

now err msg:

RuntimeError: nac3 compilation failure: type error of identifier `l` (inhomogeneous type (Cannot unify int32 with float) of 2-th element of the list) at /home/cresc/code/nac3/work1/nac3/my_expr/artiq/host_var_err.py: line 53 column 18

Program3 with error:

from numpy import int32, int64
from min_artiq import *

@nac3
class Demo:
    core: KernelInvariant[Core]
    y: Kernel[int32]

    def __init__(self):
        self.core = Core()
        self.y = 0

    @kernel
    def run(self, a: int32):
        pass


if __name__ == "__main__":
    Demo().run([1, 2.3])

previous err msg:

RuntimeError: nac3 compilation failure: unknown identifier tmp0 (use before def?) at unknown: line 2 column 14

now err msg:

RuntimeError: type error of the 0-th parameter when calling kernel function (inhomogeneous type (Cannot unify int32 with float) of 1-th element of the list)
Program1 with error: ```python from numpy import int32, int64 from min_artiq import * @nac3 class Demo: core: KernelInvariant[Core] y: Kernel[int32] def __init__(self): self.core = Core() self.y = int64(0) @kernel def run(self): pass if __name__ == "__main__": Demo().run() ``` previous error msg: ``` RuntimeError: nac3 compilation failure: unknown identifier base (use before def?) at unknown: line 2 column 5 ``` now error msg (location will just be the cpython error location): ``` RuntimeError: type error of object launching kernel: error when getting type of field `y` (Cannot unify int64 with int32) ``` --- Program2 with error: ```python from numpy import int32, int64 from min_artiq import * l = [1, 2, 3.1] @nac3 class Demo: core: KernelInvariant[Core] y: Kernel[int32] def __init__(self): self.core = Core() self.y = 0 @kernel def run(self): for i in l: pass if __name__ == "__main__": Demo().run() ``` previous err msg: ``` RuntimeError: nac3 compilation failure: unknown identifier l (use before def?) at /home/cresc/code/nac3/work1/nac3/my_expr/artiq/host_var_err.py: line 53 column 18 ``` now err msg: ``` RuntimeError: nac3 compilation failure: type error of identifier `l` (inhomogeneous type (Cannot unify int32 with float) of 2-th element of the list) at /home/cresc/code/nac3/work1/nac3/my_expr/artiq/host_var_err.py: line 53 column 18 ``` --- Program3 with error: ```python from numpy import int32, int64 from min_artiq import * @nac3 class Demo: core: KernelInvariant[Core] y: Kernel[int32] def __init__(self): self.core = Core() self.y = 0 @kernel def run(self, a: int32): pass if __name__ == "__main__": Demo().run([1, 2.3]) ``` previous err msg: ``` RuntimeError: nac3 compilation failure: unknown identifier tmp0 (use before def?) at unknown: line 2 column 14 ``` now err msg: ``` RuntimeError: type error of the 0-th parameter when calling kernel function (inhomogeneous type (Cannot unify int32 with float) of 1-th element of the list) ```
sb10q reviewed 2022-01-14 12:13:42 +08:00
@ -178,0 +229,4 @@
) {
Ok(t) => t,
Err(e) => return Some(format!(
"type error of the {}-th parameter when calling kernel function ({})", i, e
Owner

Use "parameter #xxx" to avoid problems with "1st", "2nd" and "3rd".

Use "parameter #xxx" to avoid problems with "1st", "2nd" and "3rd".
Owner

I think it should also say "at parameter #xx" instead of "of..."

I think it should also say "at parameter #xx" instead of "of..."
sb10q reviewed 2022-01-14 12:14:26 +08:00
@ -162,0 +159,4 @@
let mut ty = match self.get_obj_type(py, list.get_item(0)?, unifier, defs, primitives)? {
Ok(t) => t,
Err(e) => return Ok(Err(format!(
"type error ({}) of the first element of the list", e
Owner

"element #1" for consistency

"element #1" for consistency
sb10q requested review from pca006132 2022-01-14 12:15:28 +08:00
sb10q reviewed 2022-01-14 12:25:16 +08:00
@ -178,0 +234,4 @@
};
if let Err(e) = unifier.unify(in_ty, *ty) {
return Some(format!(
"type error of {}-th parameter when calling kernel function ({})", i, e
Owner

same - "at parameter #..."

same - "at parameter #..."
Contributor

LGTM. Btw can we also make codegen return results? When I add RPC later, I will have to return an error if the RPC parameter type is not something that we support. Thanks.

LGTM. Btw can we also make codegen return results? When I add RPC later, I will have to return an error if the RPC parameter type is not something that we support. Thanks.
Author
Collaborator

LGTM. Btw can we also make codegen return results? When I add RPC later, I will have to return an error if the RPC parameter type is not something that we support. Thanks.

Sure, I am now also looking into this issue #152 about debug information. So by debug information it mainly means codegen returning Result instead of panic?

> LGTM. Btw can we also make codegen return results? When I add RPC later, I will have to return an error if the RPC parameter type is not something that we support. Thanks. Sure, I am now also looking into this [issue #152 about debug information](https://git.m-labs.hk/M-Labs/nac3/issues/152). So by debug information it mainly means codegen returning `Result` instead of panic?
Contributor

LGTM. Btw can we also make codegen return results? When I add RPC later, I will have to return an error if the RPC parameter type is not something that we support. Thanks.

Sure, I am now also looking into this issue #152 about debug information. So by debug information it mainly means codegen returning Result instead of panic?

No. Debug information means this: https://thedan64.github.io/inkwell/inkwell/debug_info/index.html

> > LGTM. Btw can we also make codegen return results? When I add RPC later, I will have to return an error if the RPC parameter type is not something that we support. Thanks. > > Sure, I am now also looking into this [issue #152 about debug information](https://git.m-labs.hk/M-Labs/nac3/issues/152). So by debug information it mainly means codegen returning `Result` instead of panic? No. Debug information means this: https://thedan64.github.io/inkwell/inkwell/debug_info/index.html
Author
Collaborator

No. Debug information means this: https://thedan64.github.io/inkwell/inkwell/debug_info/index.html

Oh ok thanks, I will look into this.

> No. Debug information means this: https://thedan64.github.io/inkwell/inkwell/debug_info/index.html Oh ok thanks, I will look into this.
ychenfo force-pushed err_msg_host_var from 223769b8bc to 157a423e3b 2022-01-14 16:12:42 +08:00 Compare
ychenfo force-pushed err_msg_host_var from 157a423e3b to 9d342d9f0f 2022-01-14 16:30:08 +08:00 Compare
Author
Collaborator

Rebased on the current master branch and modified the message to element #XXX and parameter #XXX

Rebased on the current master branch and modified the message to `element #XXX` and `parameter #XXX`
sb10q merged commit 9d342d9f0f into master 2022-01-14 16:40:51 +08:00
sb10q deleted branch err_msg_host_var 2022-01-14 16:40:51 +08:00
Sign in to join this conversation.
No reviewers
No Milestone
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/nac3#168
No description provided.