cli: add explicit built-in error values
Add the error_values feature and error.const through specification, AIR, verification, interpretation and source lowering. Error values are Copy data with no allocation, effects or authority. Keep enum.make semantics frozen. Cover all registered tags, feature negotiation, payload/type errors and authority rejection in AIR/source; verify canonical and hosted CLI behavior. Record reference-bundle costs and the map preflight-validation prerequisite.
This commit is contained in:
1 parent
89c63c306b
commit
1eaf968f4f
56 files changed
+823
-4
No files matched your search
@@ -0,0 +1,14 @@
|
||||
; expect: run
|
||||
; result: {"variant":"budget_exceeded","payload":[]}
|
||||
; phase: 6
|
||||
; spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
air 0
|
||||
lang 0.1
|
||||
features [capabilities, effects, error_values, heap, ownership, resources]
|
||||
fn @main() -> alloc_error
|
||||
effects []
|
||||
entry:
|
||||
%e = error.const alloc_error.budget_exceeded
|
||||
%copy = copy %e
|
||||
ret %copy
|
||||
@@ -0,0 +1,14 @@
|
||||
; expect: run
|
||||
; result: {"variant":"out_of_memory","payload":[]}
|
||||
; phase: 6
|
||||
; spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
air 0
|
||||
lang 0.1
|
||||
features [capabilities, effects, error_values, heap, ownership, resources]
|
||||
fn @main() -> alloc_error
|
||||
effects []
|
||||
entry:
|
||||
%e = error.const alloc_error.out_of_memory
|
||||
%copy = copy %e
|
||||
ret %copy
|
||||
@@ -0,0 +1,14 @@
|
||||
; expect: run
|
||||
; result: {"variant":"invalid_restriction","payload":[]}
|
||||
; phase: 6
|
||||
; spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
air 0
|
||||
lang 0.1
|
||||
features [capabilities, effects, error_values, heap, ownership, resources]
|
||||
fn @main() -> cap_error
|
||||
effects []
|
||||
entry:
|
||||
%e = error.const cap_error.invalid_restriction
|
||||
%copy = copy %e
|
||||
ret %copy
|
||||
@@ -0,0 +1,14 @@
|
||||
; expect: run
|
||||
; result: {"variant":"not_subset","payload":[]}
|
||||
; phase: 6
|
||||
; spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
air 0
|
||||
lang 0.1
|
||||
features [capabilities, effects, error_values, heap, ownership, resources]
|
||||
fn @main() -> cap_error
|
||||
effects []
|
||||
entry:
|
||||
%e = error.const cap_error.not_subset
|
||||
%copy = copy %e
|
||||
ret %copy
|
||||
@@ -0,0 +1,14 @@
|
||||
; expect: run
|
||||
; result: {"variant":"unsupported_restriction","payload":[]}
|
||||
; phase: 6
|
||||
; spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
air 0
|
||||
lang 0.1
|
||||
features [capabilities, effects, error_values, heap, ownership, resources]
|
||||
fn @main() -> cap_error
|
||||
effects []
|
||||
entry:
|
||||
%e = error.const cap_error.unsupported_restriction
|
||||
%copy = copy %e
|
||||
ret %copy
|
||||
@@ -0,0 +1,12 @@
|
||||
; expect: reject E0006
|
||||
; phase: 6
|
||||
; spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
air 0
|
||||
lang 0.1
|
||||
features [error_values]
|
||||
fn @main() -> u64
|
||||
effects []
|
||||
entry:
|
||||
%x = const.u64 42
|
||||
ret %x
|
||||
@@ -0,0 +1,12 @@
|
||||
; expect: reject E0001
|
||||
; phase: 6
|
||||
; spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
air 0
|
||||
lang 0.1
|
||||
features [capabilities, effects, error_values, heap, ownership, resources]
|
||||
fn @main() -> alloc_error
|
||||
effects []
|
||||
entry:
|
||||
%e = enum.make alloc_error.budget_exceeded()
|
||||
ret %e
|
||||
@@ -0,0 +1,14 @@
|
||||
; expect: run
|
||||
; result: {"variant":"address_in_use","payload":[]}
|
||||
; phase: 6
|
||||
; spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
air 0
|
||||
lang 0.1
|
||||
features [capabilities, effects, error_values, heap, ownership, resources]
|
||||
fn @main() -> io_error
|
||||
effects []
|
||||
entry:
|
||||
%e = error.const io_error.address_in_use
|
||||
%copy = copy %e
|
||||
ret %copy
|
||||
@@ -0,0 +1,14 @@
|
||||
; expect: run
|
||||
; result: {"variant":"address_unavailable","payload":[]}
|
||||
; phase: 6
|
||||
; spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
air 0
|
||||
lang 0.1
|
||||
features [capabilities, effects, error_values, heap, ownership, resources]
|
||||
fn @main() -> io_error
|
||||
effects []
|
||||
entry:
|
||||
%e = error.const io_error.address_unavailable
|
||||
%copy = copy %e
|
||||
ret %copy
|
||||
@@ -0,0 +1,14 @@
|
||||
; expect: run
|
||||
; result: {"variant":"already_exists","payload":[]}
|
||||
; phase: 6
|
||||
; spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
air 0
|
||||
lang 0.1
|
||||
features [capabilities, effects, error_values, heap, ownership, resources]
|
||||
fn @main() -> io_error
|
||||
effects []
|
||||
entry:
|
||||
%e = error.const io_error.already_exists
|
||||
%copy = copy %e
|
||||
ret %copy
|
||||
@@ -0,0 +1,14 @@
|
||||
; expect: run
|
||||
; result: {"variant":"broken_pipe","payload":[]}
|
||||
; phase: 6
|
||||
; spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
air 0
|
||||
lang 0.1
|
||||
features [capabilities, effects, error_values, heap, ownership, resources]
|
||||
fn @main() -> io_error
|
||||
effects []
|
||||
entry:
|
||||
%e = error.const io_error.broken_pipe
|
||||
%copy = copy %e
|
||||
ret %copy
|
||||
@@ -0,0 +1,14 @@
|
||||
; expect: run
|
||||
; result: {"variant":"connection_refused","payload":[]}
|
||||
; phase: 6
|
||||
; spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
air 0
|
||||
lang 0.1
|
||||
features [capabilities, effects, error_values, heap, ownership, resources]
|
||||
fn @main() -> io_error
|
||||
effects []
|
||||
entry:
|
||||
%e = error.const io_error.connection_refused
|
||||
%copy = copy %e
|
||||
ret %copy
|
||||
@@ -0,0 +1,14 @@
|
||||
; expect: run
|
||||
; result: {"variant":"connection_reset","payload":[]}
|
||||
; phase: 6
|
||||
; spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
air 0
|
||||
lang 0.1
|
||||
features [capabilities, effects, error_values, heap, ownership, resources]
|
||||
fn @main() -> io_error
|
||||
effects []
|
||||
entry:
|
||||
%e = error.const io_error.connection_reset
|
||||
%copy = copy %e
|
||||
ret %copy
|
||||
@@ -0,0 +1,14 @@
|
||||
; expect: run
|
||||
; result: {"variant":"invalid_input","payload":[]}
|
||||
; phase: 6
|
||||
; spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
air 0
|
||||
lang 0.1
|
||||
features [capabilities, effects, error_values, heap, ownership, resources]
|
||||
fn @main() -> io_error
|
||||
effects []
|
||||
entry:
|
||||
%e = error.const io_error.invalid_input
|
||||
%copy = copy %e
|
||||
ret %copy
|
||||
@@ -0,0 +1,14 @@
|
||||
; expect: run
|
||||
; result: {"variant":"no_space","payload":[]}
|
||||
; phase: 6
|
||||
; spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
air 0
|
||||
lang 0.1
|
||||
features [capabilities, effects, error_values, heap, ownership, resources]
|
||||
fn @main() -> io_error
|
||||
effects []
|
||||
entry:
|
||||
%e = error.const io_error.no_space
|
||||
%copy = copy %e
|
||||
ret %copy
|
||||
@@ -0,0 +1,14 @@
|
||||
; expect: run
|
||||
; result: {"variant":"not_found","payload":[]}
|
||||
; phase: 6
|
||||
; spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
air 0
|
||||
lang 0.1
|
||||
features [capabilities, effects, error_values, heap, ownership, resources]
|
||||
fn @main() -> io_error
|
||||
effects []
|
||||
entry:
|
||||
%e = error.const io_error.not_found
|
||||
%copy = copy %e
|
||||
ret %copy
|
||||
@@ -0,0 +1,14 @@
|
||||
; expect: run
|
||||
; result: {"variant":"other","payload":[]}
|
||||
; phase: 6
|
||||
; spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
air 0
|
||||
lang 0.1
|
||||
features [capabilities, effects, error_values, heap, ownership, resources]
|
||||
fn @main() -> io_error
|
||||
effects []
|
||||
entry:
|
||||
%e = error.const io_error.other
|
||||
%copy = copy %e
|
||||
ret %copy
|
||||
@@ -0,0 +1,14 @@
|
||||
; expect: run
|
||||
; result: {"variant":"permission_denied","payload":[]}
|
||||
; phase: 6
|
||||
; spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
air 0
|
||||
lang 0.1
|
||||
features [capabilities, effects, error_values, heap, ownership, resources]
|
||||
fn @main() -> io_error
|
||||
effects []
|
||||
entry:
|
||||
%e = error.const io_error.permission_denied
|
||||
%copy = copy %e
|
||||
ret %copy
|
||||
@@ -0,0 +1,14 @@
|
||||
; expect: run
|
||||
; result: {"variant":"timed_out","payload":[]}
|
||||
; phase: 6
|
||||
; spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
air 0
|
||||
lang 0.1
|
||||
features [capabilities, effects, error_values, heap, ownership, resources]
|
||||
fn @main() -> io_error
|
||||
effects []
|
||||
entry:
|
||||
%e = error.const io_error.timed_out
|
||||
%copy = copy %e
|
||||
ret %copy
|
||||
@@ -0,0 +1,12 @@
|
||||
; expect: reject E1001
|
||||
; phase: 6
|
||||
; spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
air 0
|
||||
lang 0.1
|
||||
features [capabilities, effects, error_values, heap, ownership, resources]
|
||||
fn @main() -> cap<mem.alloc>
|
||||
effects []
|
||||
entry:
|
||||
%e = error.const alloc_error.budget_exceeded
|
||||
ret %e
|
||||
@@ -0,0 +1,12 @@
|
||||
; expect: reject E0001
|
||||
; phase: 6
|
||||
; spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
air 0
|
||||
lang 0.1
|
||||
features [capabilities, effects, error_values, heap, ownership, resources]
|
||||
fn @main() -> alloc_error
|
||||
effects []
|
||||
entry:
|
||||
%e = error.const alloc_error.budget_exceeded()
|
||||
ret %e
|
||||
@@ -0,0 +1,12 @@
|
||||
; expect: reject E0006
|
||||
; phase: 6
|
||||
; spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
air 0
|
||||
lang 0.1
|
||||
features [capabilities, effects, heap, ownership, resources]
|
||||
fn @main() -> alloc_error
|
||||
effects []
|
||||
entry:
|
||||
%e = error.const alloc_error.budget_exceeded
|
||||
ret %e
|
||||
@@ -0,0 +1,12 @@
|
||||
; expect: reject E0004
|
||||
; phase: 6
|
||||
; spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
air 0
|
||||
lang 0.1
|
||||
features [capabilities, effects, error_values, heap, ownership, resources]
|
||||
fn @main() -> void
|
||||
effects []
|
||||
entry:
|
||||
%e = error.const user_error.invalid
|
||||
ret
|
||||
@@ -0,0 +1,12 @@
|
||||
; expect: reject E0004
|
||||
; phase: 6
|
||||
; spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
air 0
|
||||
lang 0.1
|
||||
features [capabilities, effects, error_values, heap, ownership, resources]
|
||||
fn @main() -> alloc_error
|
||||
effects []
|
||||
entry:
|
||||
%e = error.const alloc_error.invalid
|
||||
ret %e
|
||||
@@ -0,0 +1,12 @@
|
||||
; expect: reject E1001
|
||||
; phase: 6
|
||||
; spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
air 0
|
||||
lang 0.1
|
||||
features [capabilities, effects, error_values, heap, ownership, resources]
|
||||
fn @main() -> io_error
|
||||
effects []
|
||||
entry:
|
||||
%e = error.const alloc_error.budget_exceeded
|
||||
ret %e
|
||||
@@ -0,0 +1,20 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
fn v0() -> alloc_error effects [] { return alloc_error::budget_exceeded; }
|
||||
fn v1() -> alloc_error effects [] { return alloc_error::out_of_memory; }
|
||||
fn main() -> u64 effects [] {
|
||||
let e0 = v0();
|
||||
match e0 {
|
||||
alloc_error::budget_exceeded => {}
|
||||
alloc_error::out_of_memory => { trap; }
|
||||
}
|
||||
let e1 = v1();
|
||||
match e1 {
|
||||
alloc_error::budget_exceeded => { trap; }
|
||||
alloc_error::out_of_memory => {}
|
||||
}
|
||||
return 42u64;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
fn v0() -> cap_error effects [] { return cap_error::invalid_restriction; }
|
||||
fn v1() -> cap_error effects [] { return cap_error::not_subset; }
|
||||
fn v2() -> cap_error effects [] { return cap_error::unsupported_restriction; }
|
||||
fn main() -> u64 effects [] {
|
||||
let e0 = v0();
|
||||
match e0 {
|
||||
cap_error::invalid_restriction => {}
|
||||
cap_error::not_subset => { trap; }
|
||||
cap_error::unsupported_restriction => { trap; }
|
||||
}
|
||||
let e1 = v1();
|
||||
match e1 {
|
||||
cap_error::invalid_restriction => { trap; }
|
||||
cap_error::not_subset => {}
|
||||
cap_error::unsupported_restriction => { trap; }
|
||||
}
|
||||
let e2 = v2();
|
||||
match e2 {
|
||||
cap_error::invalid_restriction => { trap; }
|
||||
cap_error::not_subset => { trap; }
|
||||
cap_error::unsupported_restriction => {}
|
||||
}
|
||||
return 42u64;
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
fn v0() -> io_error effects [] { return io_error::not_found; }
|
||||
fn v1() -> io_error effects [] { return io_error::permission_denied; }
|
||||
fn v2() -> io_error effects [] { return io_error::already_exists; }
|
||||
fn v3() -> io_error effects [] { return io_error::invalid_input; }
|
||||
fn v4() -> io_error effects [] { return io_error::no_space; }
|
||||
fn v5() -> io_error effects [] { return io_error::broken_pipe; }
|
||||
fn v6() -> io_error effects [] { return io_error::connection_refused; }
|
||||
fn v7() -> io_error effects [] { return io_error::connection_reset; }
|
||||
fn v8() -> io_error effects [] { return io_error::address_in_use; }
|
||||
fn v9() -> io_error effects [] { return io_error::address_unavailable; }
|
||||
fn v10() -> io_error effects [] { return io_error::timed_out; }
|
||||
fn v11() -> io_error effects [] { return io_error::other; }
|
||||
fn main() -> u64 effects [] {
|
||||
let e0 = v0();
|
||||
match e0 {
|
||||
io_error::not_found => {}
|
||||
io_error::permission_denied => { trap; }
|
||||
io_error::already_exists => { trap; }
|
||||
io_error::invalid_input => { trap; }
|
||||
io_error::no_space => { trap; }
|
||||
io_error::broken_pipe => { trap; }
|
||||
io_error::connection_refused => { trap; }
|
||||
io_error::connection_reset => { trap; }
|
||||
io_error::address_in_use => { trap; }
|
||||
io_error::address_unavailable => { trap; }
|
||||
io_error::timed_out => { trap; }
|
||||
io_error::other => { trap; }
|
||||
}
|
||||
let e1 = v1();
|
||||
match e1 {
|
||||
io_error::not_found => { trap; }
|
||||
io_error::permission_denied => {}
|
||||
io_error::already_exists => { trap; }
|
||||
io_error::invalid_input => { trap; }
|
||||
io_error::no_space => { trap; }
|
||||
io_error::broken_pipe => { trap; }
|
||||
io_error::connection_refused => { trap; }
|
||||
io_error::connection_reset => { trap; }
|
||||
io_error::address_in_use => { trap; }
|
||||
io_error::address_unavailable => { trap; }
|
||||
io_error::timed_out => { trap; }
|
||||
io_error::other => { trap; }
|
||||
}
|
||||
let e2 = v2();
|
||||
match e2 {
|
||||
io_error::not_found => { trap; }
|
||||
io_error::permission_denied => { trap; }
|
||||
io_error::already_exists => {}
|
||||
io_error::invalid_input => { trap; }
|
||||
io_error::no_space => { trap; }
|
||||
io_error::broken_pipe => { trap; }
|
||||
io_error::connection_refused => { trap; }
|
||||
io_error::connection_reset => { trap; }
|
||||
io_error::address_in_use => { trap; }
|
||||
io_error::address_unavailable => { trap; }
|
||||
io_error::timed_out => { trap; }
|
||||
io_error::other => { trap; }
|
||||
}
|
||||
let e3 = v3();
|
||||
match e3 {
|
||||
io_error::not_found => { trap; }
|
||||
io_error::permission_denied => { trap; }
|
||||
io_error::already_exists => { trap; }
|
||||
io_error::invalid_input => {}
|
||||
io_error::no_space => { trap; }
|
||||
io_error::broken_pipe => { trap; }
|
||||
io_error::connection_refused => { trap; }
|
||||
io_error::connection_reset => { trap; }
|
||||
io_error::address_in_use => { trap; }
|
||||
io_error::address_unavailable => { trap; }
|
||||
io_error::timed_out => { trap; }
|
||||
io_error::other => { trap; }
|
||||
}
|
||||
let e4 = v4();
|
||||
match e4 {
|
||||
io_error::not_found => { trap; }
|
||||
io_error::permission_denied => { trap; }
|
||||
io_error::already_exists => { trap; }
|
||||
io_error::invalid_input => { trap; }
|
||||
io_error::no_space => {}
|
||||
io_error::broken_pipe => { trap; }
|
||||
io_error::connection_refused => { trap; }
|
||||
io_error::connection_reset => { trap; }
|
||||
io_error::address_in_use => { trap; }
|
||||
io_error::address_unavailable => { trap; }
|
||||
io_error::timed_out => { trap; }
|
||||
io_error::other => { trap; }
|
||||
}
|
||||
let e5 = v5();
|
||||
match e5 {
|
||||
io_error::not_found => { trap; }
|
||||
io_error::permission_denied => { trap; }
|
||||
io_error::already_exists => { trap; }
|
||||
io_error::invalid_input => { trap; }
|
||||
io_error::no_space => { trap; }
|
||||
io_error::broken_pipe => {}
|
||||
io_error::connection_refused => { trap; }
|
||||
io_error::connection_reset => { trap; }
|
||||
io_error::address_in_use => { trap; }
|
||||
io_error::address_unavailable => { trap; }
|
||||
io_error::timed_out => { trap; }
|
||||
io_error::other => { trap; }
|
||||
}
|
||||
let e6 = v6();
|
||||
match e6 {
|
||||
io_error::not_found => { trap; }
|
||||
io_error::permission_denied => { trap; }
|
||||
io_error::already_exists => { trap; }
|
||||
io_error::invalid_input => { trap; }
|
||||
io_error::no_space => { trap; }
|
||||
io_error::broken_pipe => { trap; }
|
||||
io_error::connection_refused => {}
|
||||
io_error::connection_reset => { trap; }
|
||||
io_error::address_in_use => { trap; }
|
||||
io_error::address_unavailable => { trap; }
|
||||
io_error::timed_out => { trap; }
|
||||
io_error::other => { trap; }
|
||||
}
|
||||
let e7 = v7();
|
||||
match e7 {
|
||||
io_error::not_found => { trap; }
|
||||
io_error::permission_denied => { trap; }
|
||||
io_error::already_exists => { trap; }
|
||||
io_error::invalid_input => { trap; }
|
||||
io_error::no_space => { trap; }
|
||||
io_error::broken_pipe => { trap; }
|
||||
io_error::connection_refused => { trap; }
|
||||
io_error::connection_reset => {}
|
||||
io_error::address_in_use => { trap; }
|
||||
io_error::address_unavailable => { trap; }
|
||||
io_error::timed_out => { trap; }
|
||||
io_error::other => { trap; }
|
||||
}
|
||||
let e8 = v8();
|
||||
match e8 {
|
||||
io_error::not_found => { trap; }
|
||||
io_error::permission_denied => { trap; }
|
||||
io_error::already_exists => { trap; }
|
||||
io_error::invalid_input => { trap; }
|
||||
io_error::no_space => { trap; }
|
||||
io_error::broken_pipe => { trap; }
|
||||
io_error::connection_refused => { trap; }
|
||||
io_error::connection_reset => { trap; }
|
||||
io_error::address_in_use => {}
|
||||
io_error::address_unavailable => { trap; }
|
||||
io_error::timed_out => { trap; }
|
||||
io_error::other => { trap; }
|
||||
}
|
||||
let e9 = v9();
|
||||
match e9 {
|
||||
io_error::not_found => { trap; }
|
||||
io_error::permission_denied => { trap; }
|
||||
io_error::already_exists => { trap; }
|
||||
io_error::invalid_input => { trap; }
|
||||
io_error::no_space => { trap; }
|
||||
io_error::broken_pipe => { trap; }
|
||||
io_error::connection_refused => { trap; }
|
||||
io_error::connection_reset => { trap; }
|
||||
io_error::address_in_use => { trap; }
|
||||
io_error::address_unavailable => {}
|
||||
io_error::timed_out => { trap; }
|
||||
io_error::other => { trap; }
|
||||
}
|
||||
let e10 = v10();
|
||||
match e10 {
|
||||
io_error::not_found => { trap; }
|
||||
io_error::permission_denied => { trap; }
|
||||
io_error::already_exists => { trap; }
|
||||
io_error::invalid_input => { trap; }
|
||||
io_error::no_space => { trap; }
|
||||
io_error::broken_pipe => { trap; }
|
||||
io_error::connection_refused => { trap; }
|
||||
io_error::connection_reset => { trap; }
|
||||
io_error::address_in_use => { trap; }
|
||||
io_error::address_unavailable => { trap; }
|
||||
io_error::timed_out => {}
|
||||
io_error::other => { trap; }
|
||||
}
|
||||
let e11 = v11();
|
||||
match e11 {
|
||||
io_error::not_found => { trap; }
|
||||
io_error::permission_denied => { trap; }
|
||||
io_error::already_exists => { trap; }
|
||||
io_error::invalid_input => { trap; }
|
||||
io_error::no_space => { trap; }
|
||||
io_error::broken_pipe => { trap; }
|
||||
io_error::connection_refused => { trap; }
|
||||
io_error::connection_reset => { trap; }
|
||||
io_error::address_in_use => { trap; }
|
||||
io_error::address_unavailable => { trap; }
|
||||
io_error::timed_out => { trap; }
|
||||
io_error::other => {}
|
||||
}
|
||||
return 42u64;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
fn main() -> cap<mem.alloc> effects [] { return alloc_error::budget_exceeded; }
|
||||
@@ -0,0 +1,5 @@
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
fn main() -> alloc_error effects [] { return alloc_error::budget_exceeded(1u64); }
|
||||
@@ -0,0 +1,5 @@
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
fn main() -> alloc_error effects [] { return alloc_error::invalid; }
|
||||
@@ -0,0 +1,5 @@
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/05-effects-and-capabilities.md §14
|
||||
module test.errors
|
||||
fn main() -> io_error effects [] { return alloc_error::budget_exceeded; }
|
||||
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Explicit error values: canonical AIR, pure audit and hosted execution."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
REPO = Path(__file__).resolve().parents[2]
|
||||
AJI = REPO / "zig-out/bin/aji"
|
||||
FIXTURES = REPO / "tests/conformance/source/error_values"
|
||||
checks = 0
|
||||
|
||||
|
||||
def cli(*args, code=0):
|
||||
global checks
|
||||
result = subprocess.run([str(AJI), *map(str, args)], capture_output=True, text=True)
|
||||
assert result.returncode == code, (args, result.returncode, result.stdout, result.stderr)
|
||||
checks += 1
|
||||
return result.stdout
|
||||
|
||||
|
||||
features = json.loads(cli("features"))
|
||||
assert "error_values" in features["features"], features
|
||||
with tempfile.TemporaryDirectory(prefix="aji-errors-") as directory:
|
||||
root = Path(directory)
|
||||
air = root / "result.air"
|
||||
for family in ("alloc_error", "cap_error", "io_error"):
|
||||
source = FIXTURES / f"{family}.aji"
|
||||
canonical = cli("lower", source)
|
||||
assert cli("lower", source) == canonical
|
||||
assert "error_values" in canonical and f"error.const {family}." in canonical
|
||||
air.write_text(canonical)
|
||||
cli("check", air)
|
||||
assert cli("run", source) == cli("run", air)
|
||||
report = json.loads(cli("report", source))
|
||||
assert report["entry"]["capabilities"] == [], report
|
||||
assert all(function["allocations"] == 0 for function in report["functions"]), report
|
||||
result_file = root / "hosted.json"
|
||||
assert cli("run", "--profile", "hosted", "--result-file", result_file, source) == ""
|
||||
record = json.loads(result_file.read_text())
|
||||
assert record["status"] == "returned" and record["value"] == 42, record
|
||||
for name, code in (("no_authority", "E7005"), ("payload", "E7005"),
|
||||
("unknown_variant", "E7002"), ("wrong_family", "E7005")):
|
||||
diagnostics = cli("check", FIXTURES / f"{name}.aji", code=1)
|
||||
assert [json.loads(line)["code"] for line in diagnostics.splitlines()] == [code]
|
||||
print(f"source errors: {checks} checks passed")
|
||||
Reference in new issue
Block a user