Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(compiler): minimal capturing from inflight methods #1682

Merged
merged 45 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
a9e6407
feat(compiler): infer inflight field references
eladb Feb 28, 2023
0999e06
only allow capturable fields to be referenced
eladb Mar 1, 2023
f85913f
deduplicate ops
eladb Mar 1, 2023
f952603
add test - array of resources
eladb Mar 1, 2023
88cd136
update snapshots
eladb Mar 1, 2023
bac962b
tweaks
eladb Mar 1, 2023
ea6e583
add a comment about bailing our before jsification
eladb Mar 1, 2023
66e3291
fix test
eladb Mar 1, 2023
93c8581
Merge remote-tracking branch 'origin/main' into eladb/infer-refs
eladb Mar 1, 2023
6808e8b
updates
eladb Mar 1, 2023
afd285b
add a few more tests
eladb Mar 1, 2023
234047c
update snapshots
eladb Mar 1, 2023
a790c83
Merge remote-tracking branch 'origin/main' into eladb/infer-refs
eladb Mar 1, 2023
ee1be61
update snapshots
eladb Mar 1, 2023
855a6e5
only allow accessing inflight methods
eladb Mar 1, 2023
e4211a7
Merge remote-tracking branch 'origin/main' into eladb/infer-refs
eladb Mar 1, 2023
01975ac
update snapshots
eladb Mar 1, 2023
4e133d8
update snapshots
eladb Mar 1, 2023
dd62852
fix indentation
eladb Mar 2, 2023
17fa765
add inflight_ref_external.w
eladb Mar 2, 2023
526c9b9
rust refactoring
eladb Mar 2, 2023
1a023da
another rust refactor
eladb Mar 2, 2023
d811569
Merge remote-tracking branch 'origin/main' into eladb/infer-refs
eladb Mar 2, 2023
57136fd
snapshots
eladb Mar 2, 2023
7f8bc0b
update snapshots
eladb Mar 2, 2023
0406678
tweaks
eladb Mar 2, 2023
7963c5d
add test for inflight field reference
eladb Mar 3, 2023
e499f5e
tweaks
eladb Mar 3, 2023
335b6c1
update snaps
eladb Mar 3, 2023
8786750
rewrite
eladb Mar 3, 2023
8abc88e
Merge branch 'main' into eladb/infer-refs
eladb Mar 3, 2023
d50930d
chore: self mutation
Mar 3, 2023
c10a068
chore: self mutation
Mar 3, 2023
ea411ea
Merge remote-tracking branch 'origin/main' into eladb/infer-refs
eladb Mar 3, 2023
05e5c6a
use class.get_method
eladb Mar 3, 2023
d5b7df7
Update inflight_ref_resource_collection.w
eladb Mar 3, 2023
b56ad4b
Merge remote-tracking branch 'origin/main' into eladb/infer-refs
eladb Mar 5, 2023
38d3984
merge
eladb Mar 5, 2023
b4a30ff
add a test for calling a method on a resource that returns another re…
eladb Mar 5, 2023
56b8d6f
update snapshots
eladb Mar 5, 2023
a26de00
Update libs/wingc/src/jsify.rs
eladb Mar 5, 2023
9195918
cr cleanups
yoav-steinberg Mar 6, 2023
6fd8477
never nester
eladb Mar 6, 2023
6afde9a
Merge remote-tracking branch 'origin/main' into eladb/infer-refs
eladb Mar 6, 2023
8cfa845
clippy
eladb Mar 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions examples/tests/invalid/inflight_ref_invalid.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
resource Foo {
mut_array: MutArray<str>;
var reassignable: num;
eladb marked this conversation as resolved.
Show resolved Hide resolved

init() {
this.mut_array = MutArray<str>[];
this.mut_array.push("hello");
this.reassignable = 42;
}

inflight test() {
print("${this.reassignable}");
// ^^^^^^^^^^^^ Unable to reference "this.reassignable" from inflight method "test" because it is reassignable ("var")
print(this.mut_array.at(0));
// ^^^^^^^^^ Unable to reference "this.mut_array" from inflight method "test" because type MutArray<str> is not capturable
}
}
32 changes: 32 additions & 0 deletions examples/tests/invalid/inflight_ref_resource_sub_field.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
bring cloud;

resource Another {
my_field: str;
my_queue: cloud.Queue;

init () {
this.my_field = "hello";
this.my_queue = new cloud.Queue();
}

inflight func(): str {
return this.my_field;
}
}

resource Test {
another: Another;

init() {
this.another = new Another();
}

inflight test() {
let res = this.another.func();
this.another.my_queue.push("message");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment to the code? (It seems like this should be valid, no?)

assert(res == "hello");
}
}

let f = new Test();
new cloud.Function(inflight () => { f.test(); }) as "test";
24 changes: 24 additions & 0 deletions examples/tests/valid/inflight_ref_primitive.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
bring cloud;

resource Test {
my_str: str;
my_num: num;
my_arr: Array<str>;

init() {
this.my_str = "hello";
this.my_num = 123;
this.my_arr = ["bang", "bing"];
}

inflight test() {
let y = this.my_num + 456;
assert(y == 579);
assert(this.my_str == "hello");
assert(this.my_arr.at(1) == "bing");
assert(this.my_arr.length == 2);
}
}

let f = new Test();
new cloud.Function(inflight () => { f.test(); }) as "test";
16 changes: 16 additions & 0 deletions examples/tests/valid/inflight_ref_resource.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
bring cloud;

resource Test {
b: cloud.Bucket;

init() {
this.b = new cloud.Bucket();
}
eladb marked this conversation as resolved.
Show resolved Hide resolved

inflight test() {
this.b.put("hello", "world");
}
}

let f = new Test();
new cloud.Function(inflight () => { f.test(); }) as "test";
16 changes: 16 additions & 0 deletions examples/tests/valid/inflight_ref_resource_collection.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
bring cloud;

resource Test {
array: Array<cloud.Bucket>;

init() {
this.array = [new cloud.Bucket()];
}

inflight test() {
assert(this.array.at(0).list().length == 0);
eladb marked this conversation as resolved.
Show resolved Hide resolved
}
}

let f = new Test();
new cloud.Function(inflight () => { f.test(); }) as "test";
28 changes: 28 additions & 0 deletions examples/tests/valid/inflight_ref_resource_field.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
bring cloud;

resource Another {
my_field: str;
init () {
this.my_field = "hello";
}

inflight func(): str {
return this.my_field;
}
}

resource Test {
another: Another;

init() {
this.another = new Another();
}

inflight test() {
let res = this.another.func();
assert(res == "hello");
}
}

let f = new Test();
new cloud.Function(inflight () => { f.test(); }) as "test";
Loading