Skip to content

Commit 5e75c76

Browse files
author
Zak Kent
committed
[Test] Add tests for lazy immediate mode
1 parent 289b812 commit 5e75c76

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// RUN: %target-jit-run %s -enable-experimental-feature LazyImmediate | %FileCheck %s
2+
3+
// Tests that parsing of function bodies is deferred
4+
// to runtime when the interpreter is invoked using
5+
// experimental lazy compilation. Syntax errors in
6+
// functions not executed at runtime should be ignored.
7+
8+
public func foo() {
9+
3 +
10+
}
11+
12+
// Syntax error in `foo` should be ignored
13+
14+
// CHECK: hello
15+
print("hello")
16+
17+
public func bar(_ b: Bool) {
18+
if b {
19+
print("bar")
20+
} else {
21+
foo()
22+
}
23+
}
24+
25+
// Function `foo` with syntax error is not executed
26+
// by bar, so the type error should again be ignored
27+
28+
// CHECK: bar
29+
bar(true)
30+
31+
public func add(_ x: Int, _ y: Int, _ z: Int) -> Int {
32+
return x + y + z
33+
}
34+
35+
public func sub(_ x: Int, _ y: Int) -> Int {
36+
return add(x,
37+
}
38+
39+
// CHECK: 6
40+
print(add(1, 2, 3))
41+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// RUN: %target-jit-run %s -enable-experimental-feature LazyImmediate | %FileCheck %s
2+
3+
// Tests that type checking of function bodies is
4+
// deferred to runtime when the interpreter is invoked
5+
// using experimental lazy compilation. Type errors in
6+
// functions not executed at runtime should be ignored.
7+
8+
public func foo() {
9+
3 + true
10+
}
11+
12+
// Type error in `foo` should be ignored
13+
14+
// CHECK: hello
15+
print("hello")
16+
17+
public func bar(_ b: Bool) {
18+
if b {
19+
print("bar")
20+
} else {
21+
foo()
22+
}
23+
}
24+
25+
// Function `foo` with type error is not executed
26+
// by bar, so the type error should again be ignored
27+
28+
// CHECK: bar
29+
bar(true)
30+
31+
public func add(_ x: Int, _ y: Int, _ z: Int) -> Int {
32+
return x + y + z
33+
}
34+
35+
public func sub(_ x: Int, _ y: Int) -> Int {
36+
return add(x, -y)
37+
}
38+
39+
// CHECK: 6
40+
print(add(1, 2, 3))

0 commit comments

Comments
 (0)