cli: restrict source scope names to lexical task operands
This commit is contained in:
1 parent
364eb57bbc
commit
9001e56325
32 files changed
+307
-6
No files matched your search
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §7
|
||||
module scope_cases.array
|
||||
|
||||
fn main() -> u64 effects [] { scope s { let values = [move s]; } 0u64 }
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §7
|
||||
module scope_cases.assignment
|
||||
|
||||
fn main() -> u64 effects [] { scope s { s = 0u64; } 0u64 }
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §7
|
||||
module scope_cases.bare_alias
|
||||
|
||||
fn main() -> u64 effects [] { scope s { let alias = s; } 0u64 }
|
||||
@@ -0,0 +1,5 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §7
|
||||
module scope_cases.bare_array
|
||||
fn main() -> u64 effects [] { scope s { let values = [s]; } 0u64 }
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §7
|
||||
module scope_cases.block_yield
|
||||
|
||||
fn main() -> u64 effects [] { scope s { let alias = { s }; } 0u64 }
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §7
|
||||
module scope_cases.borrow
|
||||
|
||||
fn main() -> u64 effects [] { scope s { ref r = s; } 0u64 }
|
||||
@@ -0,0 +1,7 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §7
|
||||
module scope_cases.call_argument
|
||||
|
||||
fn identity(x: u64) -> u64 effects [] { x }
|
||||
fn main() -> u64 effects [] { scope s { let n = identity(s); } 0u64 }
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §7
|
||||
module scope_cases.discard
|
||||
|
||||
fn main() -> u64 effects [] { scope s { s; } 0u64 }
|
||||
@@ -0,0 +1,5 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §7
|
||||
module scope_cases.equality
|
||||
fn main() -> u64 effects [] { scope s { let same = s == s; } 0u64 }
|
||||
@@ -0,0 +1,10 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §7
|
||||
module scope_cases.generic_alias
|
||||
|
||||
fn identity<T: Copy>(x: T) -> T effects [] {
|
||||
scope s { let alias = move s; }
|
||||
move x
|
||||
}
|
||||
fn main() -> u64 effects [] { identity::<u64>(42u64) }
|
||||
@@ -0,0 +1,8 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §7
|
||||
module scope_cases.if_yield
|
||||
fn main() -> u64 effects [] {
|
||||
scope s { let alias = if true { s } else { s }; }
|
||||
0u64
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §7
|
||||
module scope_cases.match_yield
|
||||
fn main() -> u64 effects [] {
|
||||
scope s { let alias = match 0u64 { 0 => { s }, _ => { s } }; }
|
||||
0u64
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §7
|
||||
module scope_cases.move_alias
|
||||
|
||||
fn main() -> u64 effects [] { scope s { let alias = move s; } 0u64 }
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §7
|
||||
module scope_cases.move_discard
|
||||
|
||||
fn main() -> u64 effects [] { scope s { move s; } 0u64 }
|
||||
@@ -0,0 +1,10 @@
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §7
|
||||
module scope_cases.moved_spawn
|
||||
|
||||
fn work() -> u64 effects [] { 42u64 }
|
||||
fn main() -> u64 effects [task.spawn, task.wait] {
|
||||
scope s { let t = task.spawn(move s, work); let n = task.join(move t); }
|
||||
0u64
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// schedules: 8
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §7
|
||||
module scope_cases.nested_same_name
|
||||
|
||||
fn work(x: u64) -> u64 effects [] { x }
|
||||
fn main() -> u64 effects [task.spawn, task.wait] {
|
||||
var total: u64 = 0;
|
||||
scope s {
|
||||
let first = task.spawn(s, work, 20u64);
|
||||
scope s {
|
||||
let second = task.spawn(s, work, 22u64);
|
||||
let s = 0u64;
|
||||
total = task.join(move second) + s;
|
||||
}
|
||||
total = total + task.join(move first);
|
||||
}
|
||||
total
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// schedules: 8
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §7
|
||||
module scope_cases.normal_exits
|
||||
|
||||
fn work(x: mut<u64>) -> void effects [] { *x = *x + 7u64; }
|
||||
fn read(x: ref<u64>) -> u64 effects [] { *x }
|
||||
fn main() -> u64 effects [task.spawn, task.wait] {
|
||||
var data: u64 = 0;
|
||||
for i in 0usize..8usize {
|
||||
scope s {
|
||||
mut part = data;
|
||||
let t = task.spawn(s, work, part);
|
||||
task.join(move t);
|
||||
let s = i;
|
||||
if s < 5 { continue; }
|
||||
break;
|
||||
}
|
||||
}
|
||||
scope s {
|
||||
ref part = data;
|
||||
let t = task.spawn(s, read, part);
|
||||
let s = task.join(move t);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §7
|
||||
module scope_cases.out_of_block
|
||||
|
||||
fn main() -> u64 effects [] { scope s {} s }
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §7
|
||||
module scope_cases.return
|
||||
|
||||
fn main() -> u64 effects [] { scope s { return move s; } 0u64 }
|
||||
@@ -0,0 +1,5 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §7
|
||||
module scope_cases.scope_tail
|
||||
fn main() -> u64 effects [] { scope s { s } 0u64 }
|
||||
@@ -0,0 +1,15 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// schedules: 8
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §7
|
||||
module scope_cases.shadow_value
|
||||
|
||||
fn main() -> u64 effects [] {
|
||||
scope s {
|
||||
let s = 20u64;
|
||||
{ var s: u64 = 21; s = s + 1u64; }
|
||||
let n = s + 22u64;
|
||||
return n;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §7
|
||||
module scope_cases.spawn_shadow
|
||||
|
||||
fn work() -> u64 effects [] { 42u64 }
|
||||
fn main() -> u64 effects [task.spawn, task.wait] {
|
||||
scope s { let s = 0u64; let t = task.spawn(s, work); let n = task.join(move t); }
|
||||
0u64
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// expect: reject E4301
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §7
|
||||
module scope_cases.unjoined_shadow
|
||||
|
||||
fn work() -> u64 effects [] { 42u64 }
|
||||
fn main() -> u64 effects [task.spawn] {
|
||||
scope s { let t = task.spawn(s, work); let s = 0u64; }
|
||||
0u64
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// schedules: 8
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §7
|
||||
module scope_cases.visible_outer
|
||||
|
||||
fn work() -> u64 effects [] { 42u64 }
|
||||
fn main() -> u64 effects [task.spawn, task.wait] {
|
||||
var result: u64 = 0;
|
||||
scope outer {
|
||||
scope inner {
|
||||
let t = task.spawn(outer, work);
|
||||
result = task.join(move t);
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
@@ -100,4 +100,49 @@ with tempfile.TemporaryDirectory(prefix='aji-reasons-') as d:
|
||||
ordinary.write_text('module ordinary fn main()->u64 effects [] {return true;}')
|
||||
error = json.loads(invoke('check', ordinary, code=1))
|
||||
assert error['code'] == 'E7005' and 'reason' not in error
|
||||
|
||||
# A scope name never reaches ordinary value lowering, including generic
|
||||
# bodies and branch/block yields. No misleading move-repair is emitted.
|
||||
scope_cases = REPO / 'tests/conformance/source/scopes'
|
||||
for name in ('array', 'bare_array', 'bare_alias', 'block_yield', 'call_argument',
|
||||
'discard', 'equality', 'generic_alias', 'if_yield', 'match_yield',
|
||||
'move_alias', 'move_discard', 'return', 'scope_tail'):
|
||||
path = scope_cases / f'{name}.aji'
|
||||
error = json.loads(invoke('check', path, code=1))
|
||||
assert (error['code'], error['reason'], error['name'], error['type']) == (
|
||||
'E7006', 'invalid_expression', 's', 'scope'), error
|
||||
assert 'suggestion' not in error, error
|
||||
line = path.read_text().splitlines()[error['line'] - 1]
|
||||
assert line[error['col'] - 1:].startswith(('s', 'move s')), (path, error)
|
||||
assert json.loads(invoke('lower', path, code=1)) == error
|
||||
|
||||
for name, code, reason in (('borrow', 'E7006', 'invalid_place'),
|
||||
('assignment', 'E7006', 'invalid_assignment'),
|
||||
('moved_spawn', 'E7005', None),
|
||||
('spawn_shadow', 'E7005', None),
|
||||
('out_of_block', 'E7002', None),
|
||||
('unjoined_shadow', 'E4301', None)):
|
||||
error = json.loads(invoke('check', scope_cases / f'{name}.aji', code=1))
|
||||
assert error['code'] == code and error.get('reason') == reason, error
|
||||
|
||||
# Imported specialized bodies retain the location of their forbidden
|
||||
# scope use, rather than the call or the generated AIR.
|
||||
entry.write_text('module app import dep; fn main()->u64 effects [] {dep.f::<u64>(42u64)}')
|
||||
dep.write_text('module dep\nfn f<T:Copy>(x:T)->T effects [] {\n'
|
||||
'scope s { let alias = move s; }\nmove x\n}\n')
|
||||
error = json.loads(invoke('check', '--manifest', manifest, code=1))
|
||||
assert (error['code'], error['reason'], error['file'], error['line'], error['col']) == (
|
||||
'E7006', 'invalid_expression', dep.name, 3, 23), error
|
||||
assert json.loads(invoke('lower', '--manifest', manifest, code=1)) == error
|
||||
|
||||
# Lexical completion and task/borrow cleanup are identical under both
|
||||
# profiles and independent scheduler choices, even with shadowed names.
|
||||
for name in ('nested_same_name', 'normal_exits', 'visible_outer', 'shadow_value'):
|
||||
path = scope_cases / f'{name}.aji'
|
||||
for quantum in (1, 5, 16):
|
||||
args = ['--fuel', '10000', '--quantum', str(quantum), '--schedule-seed', '7']
|
||||
assert json.loads(invoke('run', *args, path))['value'] == 42
|
||||
result_file = root / 'scope-result.json'
|
||||
invoke('run', '--profile', 'hosted', '--result-file', result_file, *args, path)
|
||||
assert json.loads(result_file.read_text())['value'] == 42
|
||||
print(f'source diagnostic reasons passed ({checks} checks; {fixtures} public E7006 fixtures)')
|
||||
Reference in new issue
Block a user