more constraints checks

This commit is contained in:
damirka 2021-05-12 20:47:03 +03:00
parent cb2bd62ea9
commit e2492ba9e4
29 changed files with 168 additions and 154 deletions

View File

@ -18,8 +18,11 @@
#![allow(deprecated)] #![allow(deprecated)]
pub mod canonicalization; // Test framework found in /tests/compiler
#[cfg(test)]
pub mod test; pub mod test;
pub mod canonicalization;
pub mod type_inference; pub mod type_inference;
use leo_asg::{new_alloc_context, new_context, AsgContext}; use leo_asg::{new_alloc_context, new_context, AsgContext};

View File

@ -1,6 +1,7 @@
/* /*
namespace: Compile namespace: Compile
expectation: Pass expectation: Pass
input_file: input/dummy.in
*/ */
circuit Foo { circuit Foo {
@ -11,8 +12,8 @@ circuit Foo {
} }
} }
function main() { function main(y: bool) -> bool {
let f = Foo { a: 0u8 }; let f = Foo { a: 0u8 };
console.assert(1u8 == f.use_a()); return 1u8 == f.use_a() == true;
} }

View File

@ -1,6 +1,7 @@
/* /*
namespace: Compile namespace: Compile
expectation: Pass expectation: Pass
input_file: input/dummy.in
*/ */
circuit Bar { circuit Bar {
@ -11,8 +12,10 @@ circuit Bar {
} }
} }
function main () { function main(y: bool) -> bool {
const Bar = 66u32; const Bar = 66u32;
const k1 = Bar { b2: 30u32 }; const k1 = Bar { b2: 30u32 };
const k2 = Bar::add_five(55u32); const k2 = Bar::add_five(55u32);
return y == true;
} }

View File

@ -0,0 +1,6 @@
[main]
y: bool = true;
x: bool = false;
[registers]
r0: bool = true;

View File

@ -1,10 +1,7 @@
/* /*
namespace: Compile namespace: Compile
expectation: Pass expectation: Pass
inputs: input_file: input/dummy.in
- member.in: |
[registers]
r0: bool = false;
*/ */
circuit Foo { circuit Foo {
@ -15,8 +12,8 @@ circuit Foo {
} }
} }
function main() -> bool { function main(y: bool) -> bool {
const a = Foo { x: 1u32 }; const a = Foo { x: 1u32 };
return a.echo() == 1u32; return a.echo() == 1u32 == true;
} }

View File

@ -1,10 +1,7 @@
/* /*
namespace: Compile namespace: Compile
expectation: Pass expectation: Pass
inputs: input_file: input/dummy.in
- static.in: |
[registers]
r0: bool = false;
*/ */
circuit Foo { circuit Foo {
@ -13,8 +10,8 @@ circuit Foo {
} }
} }
function main() -> bool { function main(y: bool) -> bool {
const a = Foo::echo(1u32); const a = Foo::echo(1u32);
return a == 1u32; return a == 1u32 == y;
} }

View File

@ -1,6 +1,7 @@
/* /*
namespace: Compile namespace: Compile
expectation: Pass expectation: Pass
input_file: input/dummy.in
*/ */
circuit Foo { circuit Foo {
@ -15,6 +16,8 @@ circuit Foo {
} }
} }
function main() { function main(y: bool) -> bool {
Foo::baz(); Foo::baz();
return y == true;
} }

View File

@ -1,18 +1,15 @@
/* /*
namespace: Compile namespace: Compile
expectation: Pass expectation: Pass
inputs: input_file: input/dummy.in
- member.in: |
[registers]
r0: bool = false;
*/ */
circuit Foo { circuit Foo {
x: u32, x: u32,
} }
function main() -> bool { function main(y: bool) -> bool {
const a = Foo { x: 1u32 }; const a = Foo { x: 1u32 };
return a.x == 1u32; return a.x == 1u32 == y;
} }

View File

@ -1,10 +1,7 @@
/* /*
namespace: Compile namespace: Compile
expectation: Pass expectation: Pass
inputs: input_file: input/dummy.in
- member.in: |
[registers]
r0: bool = false;
*/ */
circuit Foo { circuit Foo {
@ -15,9 +12,9 @@ circuit Foo {
} }
} }
function main() -> bool { function main(y: bool) -> bool {
const a = Foo { foo: 1 }; const a = Foo { foo: 1 };
const b = a.foo + Foo::bar(); const b = a.foo + Foo::bar();
return b == 2u32; return b == 2u32 == y;
} }

View File

@ -1,6 +1,7 @@
/* /*
namespace: Compile namespace: Compile
expectation: Pass expectation: Pass
input_file: input/dummy.in
*/ */
circuit Foo { circuit Foo {
@ -8,20 +9,14 @@ circuit Foo {
function set_a(mut self, new: u8) { function set_a(mut self, new: u8) {
self.a = new; self.a = new;
console.assert(self.a == new);
} }
} }
function main() { function main(y: bool) -> bool {
let f = Foo { a: 0u8 }; let f = Foo { a: 0u8 };
console.assert(f.a == 0u8);
f.set_a(1u8); f.set_a(1u8);
console.assert(f.a == 1u8);
f.set_a(2u8); f.set_a(2u8);
console.assert(f.a == 2u8); return f.a == 2u8 == y;
} }

View File

@ -1,6 +1,7 @@
/* /*
namespace: Compile namespace: Compile
expectation: Pass expectation: Pass
input_file: input/dummy.in
*/ */
circuit Foo { circuit Foo {
@ -9,29 +10,17 @@ circuit Foo {
function set_a(mut self, condition: bool, new: u8) { function set_a(mut self, condition: bool, new: u8) {
if condition { if condition {
self.a = new; self.a = new;
console.assert(self.a == new);
} }
} }
} }
function main() { function main(y: bool) -> bool {
let f = Foo { a: 0u8 }; let f = Foo { a: 0u8 };
console.assert(f.a == 0u8);
f.set_a(false, 1u8); f.set_a(false, 1u8);
console.assert(f.a == 0u8);
f.set_a(true, 1u8); f.set_a(true, 1u8);
console.assert(f.a == 1u8);
f.set_a(false, 2u8); f.set_a(false, 2u8);
console.assert(f.a == 1u8);
f.set_a(true, 2u8); f.set_a(true, 2u8);
console.assert(f.a == 2u8); return f.a == 2u8 == y;
} }

View File

@ -1,12 +1,15 @@
/* /*
namespace: Compile namespace: Compile
expectation: Pass expectation: Pass
input_file: input/dummy.in
*/ */
function main() { function main(y: bool) -> bool {
let f = Foo { a: 0u32 }; let f = Foo { a: 0u32 };
f.bar(); f.bar();
return y == true;
} }
circuit Foo { circuit Foo {

View File

@ -1,22 +1,18 @@
/* /*
namespace: Compile namespace: Compile
expectation: Pass expectation: Pass
input_file: input/dummy.in
*/ */
circuit Foo { circuit Foo {
a: u8; a: u8;
} }
function main() { function main(y: bool) -> bool {
let f = Foo { a: 0u8 }; let f = Foo { a: 0u8 };
console.assert(f.a == 0u8);
f.a = 1u8; f.a = 1u8;
console.assert(f.a == 1u8);
f.a = 2u8; f.a = 2u8;
console.assert(f.a == 2u8); return f.a == 2u8 == true;
} }

View File

@ -1,6 +1,7 @@
/* /*
namespace: Compile namespace: Compile
expectation: Pass expectation: Pass
input_file: input/dummy.in
*/ */
circuit TestMe { circuit TestMe {
@ -20,11 +21,9 @@ function my_fn() -> TestMe {
return TestMe { x: 0u8 }; return TestMe { x: 0u8 };
} }
function main () { function main(y: bool) -> bool {
const t = TestMe {x: 6u8}.test_me(); const t = TestMe {x: 6u8}.test_me();
console.assert(t == 7u8);
const u = my_fn().test_me(); const u = my_fn().test_me();
console.assert(u == 1u8);
const v = TestMe::new().test_me(); const v = TestMe::new().test_me();
console.assert(v == 2u8); return v == 2u8 == y;
} }

View File

@ -12,4 +12,4 @@ circuit Foo {
function main() { function main() {
const a = Foo::new(); const a = Foo::new();
} }

View File

@ -1,6 +1,7 @@
/* /*
namespace: Compile namespace: Compile
expectation: Pass expectation: Pass
input_file: input/dummy.in
*/ */
circuit Foo { circuit Foo {
@ -11,9 +12,9 @@ circuit Foo {
} }
} }
function main() { function main(y: bool) -> bool {
const a = Foo { f: 1u32 }; const a = Foo { f: 1u32 };
const b = a.bar(); const b = a.bar();
console.assert(b == 1u32); return b == 1u32 == y;
} }

View File

@ -4,12 +4,15 @@ expectation: Pass
outputs: outputs:
- circuit: - circuit:
num_public_variables: 0 num_public_variables: 0
num_private_variables: 0 num_private_variables: 1
num_constraints: 0 num_constraints: 1
at: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output: output:
- input_file: empty - input_file: input/dummy.in
output: output:
registers: {} registers:
r0:
type: bool
value: "true"

View File

@ -4,12 +4,15 @@ expectation: Pass
outputs: outputs:
- circuit: - circuit:
num_public_variables: 0 num_public_variables: 0
num_private_variables: 0 num_private_variables: 1
num_constraints: 0 num_constraints: 1
at: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output: output:
- input_file: empty - input_file: input/dummy.in
output: output:
registers: {} registers:
r0:
type: bool
value: "true"

View File

@ -4,13 +4,13 @@ expectation: Pass
outputs: outputs:
- circuit: - circuit:
num_public_variables: 0 num_public_variables: 0
num_private_variables: 0 num_private_variables: 1
num_constraints: 0 num_constraints: 1
at: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output: output:
- input_file: member.in - input_file: input/dummy.in
output: output:
registers: registers:
r0: r0:

View File

@ -4,13 +4,13 @@ expectation: Pass
outputs: outputs:
- circuit: - circuit:
num_public_variables: 0 num_public_variables: 0
num_private_variables: 0 num_private_variables: 1
num_constraints: 0 num_constraints: 1
at: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output: output:
- input_file: static.in - input_file: input/dummy.in
output: output:
registers: registers:
r0: r0:

View File

@ -4,12 +4,15 @@ expectation: Pass
outputs: outputs:
- circuit: - circuit:
num_public_variables: 0 num_public_variables: 0
num_private_variables: 0 num_private_variables: 1
num_constraints: 0 num_constraints: 1
at: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output: output:
- input_file: empty - input_file: input/dummy.in
output: output:
registers: {} registers:
r0:
type: bool
value: "true"

View File

@ -4,13 +4,13 @@ expectation: Pass
outputs: outputs:
- circuit: - circuit:
num_public_variables: 0 num_public_variables: 0
num_private_variables: 0 num_private_variables: 1
num_constraints: 0 num_constraints: 1
at: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output: output:
- input_file: member.in - input_file: input/dummy.in
output: output:
registers: registers:
r0: r0:

View File

@ -4,13 +4,13 @@ expectation: Pass
outputs: outputs:
- circuit: - circuit:
num_public_variables: 0 num_public_variables: 0
num_private_variables: 0 num_private_variables: 1
num_constraints: 0 num_constraints: 1
at: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output: output:
- input_file: member.in - input_file: input/dummy.in
output: output:
registers: registers:
r0: r0:

View File

@ -4,12 +4,15 @@ expectation: Pass
outputs: outputs:
- circuit: - circuit:
num_public_variables: 0 num_public_variables: 0
num_private_variables: 0 num_private_variables: 1
num_constraints: 0 num_constraints: 1
at: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output: output:
- input_file: empty - input_file: input/dummy.in
output: output:
registers: {} registers:
r0:
type: bool
value: "true"

View File

@ -4,12 +4,15 @@ expectation: Pass
outputs: outputs:
- circuit: - circuit:
num_public_variables: 0 num_public_variables: 0
num_private_variables: 0 num_private_variables: 1
num_constraints: 0 num_constraints: 1
at: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output: output:
- input_file: empty - input_file: input/dummy.in
output: output:
registers: {} registers:
r0:
type: bool
value: "true"

View File

@ -4,12 +4,15 @@ expectation: Pass
outputs: outputs:
- circuit: - circuit:
num_public_variables: 0 num_public_variables: 0
num_private_variables: 0 num_private_variables: 1
num_constraints: 0 num_constraints: 1
at: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output: output:
- input_file: empty - input_file: input/dummy.in
output: output:
registers: {} registers:
r0:
type: bool
value: "true"

View File

@ -4,12 +4,15 @@ expectation: Pass
outputs: outputs:
- circuit: - circuit:
num_public_variables: 0 num_public_variables: 0
num_private_variables: 0 num_private_variables: 1
num_constraints: 0 num_constraints: 1
at: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output: output:
- input_file: empty - input_file: input/dummy.in
output: output:
registers: {} registers:
r0:
type: bool
value: "true"

View File

@ -4,12 +4,15 @@ expectation: Pass
outputs: outputs:
- circuit: - circuit:
num_public_variables: 0 num_public_variables: 0
num_private_variables: 0 num_private_variables: 1
num_constraints: 0 num_constraints: 1
at: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output: output:
- input_file: empty - input_file: input/dummy.in
output: output:
registers: {} registers:
r0:
type: bool
value: "true"

View File

@ -4,12 +4,15 @@ expectation: Pass
outputs: outputs:
- circuit: - circuit:
num_public_variables: 0 num_public_variables: 0
num_private_variables: 0 num_private_variables: 1
num_constraints: 0 num_constraints: 1
at: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945 ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output: output:
- input_file: empty - input_file: input/dummy.in
output: output:
registers: {} registers:
r0:
type: bool
value: "true"