Skip to content

Commit

Permalink
fix(compiler): unused global lifts cause sim to fail (#5720)
Browse files Browse the repository at this point in the history
See #5719
We now add **all** lifts to a class's `$inflight_init`'s bindings. This makes sure the simulator sets up those objects so it can create clients for them.

## Checklist

- [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted)
- [x] Description explains motivation and solution
- [x] Tests added (always)
- [ ] Docs updated (only required for features)
- [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
  • Loading branch information
yoav-steinberg authored Feb 19, 2024
1 parent 5d3b6d1 commit 673ca77
Show file tree
Hide file tree
Showing 135 changed files with 645 additions and 5 deletions.
31 changes: 31 additions & 0 deletions examples/tests/valid/unused_lift.test.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
bring cloud;

let b = new cloud.Bucket();

class Foo {
inflight access_b() {
b.list();
}

pub inflight m() {}
}

let f = new Foo();

test "Use class but not method that access lifted object" {
f.m();
}

class Bar {
static inflight access_b() {
b.list();
}

pub inflight m() {}
}

let bar = new Bar();

test "Use class but not static method that access lifted object" {
bar.m();
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class $Root extends $stdlib.std.Resource {
[x.length, []],
],
"$inflight_init": [
[((arr, index) => { if (index < 0 || index >= arr.length) throw new Error("Index out of bounds"); return arr[index]; })(y, 0), []],
[x.length, []],
],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class $Root extends $stdlib.std.Resource {
[s.length, []],
],
"$inflight_init": [
[s.length, []],
],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class $Root extends $stdlib.std.Resource {
[((obj, key) => { if (!(key in obj)) throw new Error(`Map does not contain key: "${key}"`); return obj[key]; })(s, "hello").length, []],
],
"$inflight_init": [
[((obj, key) => { if (!(key in obj)) throw new Error(`Map does not contain key: "${key}"`); return obj[key]; })(s, "hello").length, []],
],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class $Root extends $stdlib.std.Resource {
[x, []],
],
"$inflight_init": [
[x, []],
],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class $Root extends $stdlib.std.Resource {
get _liftMap() {
return ({
"$inflight_init": [
[A, []],
],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class $Root extends $stdlib.std.Resource {
[b, ["list", "put"]],
],
"$inflight_init": [
[b, []],
],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class $Root extends $stdlib.std.Resource {
[foo, []],
],
"$inflight_init": [
[foo, []],
],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class $Root extends $stdlib.std.Resource {
[foo, ["handle"]],
],
"$inflight_init": [
[foo, []],
],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class $Root extends $stdlib.std.Resource {
[x, []],
],
"$inflight_init": [
[x, []],
],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class $Root extends $stdlib.std.Resource {
[f, ["bar"]],
],
"$inflight_init": [
[f, []],
],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class $Root extends $stdlib.std.Resource {
[f.b, ["put"]],
],
"$inflight_init": [
[f.b, []],
],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class $Root extends $stdlib.std.Resource {
[x.length, []],
],
"$inflight_init": [
[x.length, []],
],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class $Root extends $stdlib.std.Resource {
[x, []],
],
"$inflight_init": [
[x, []],
],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class $Root extends $stdlib.std.Resource {
[bucket_this, ["put"]],
],
"$inflight_init": [
[bucket_this, []],
],
});
}
Expand Down
1 change: 1 addition & 0 deletions libs/wingc/src/jsify/snapshots/capture_token.snap
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class $Root extends $stdlib.std.Resource {
[api.url, []],
],
"$inflight_init": [
[api.url, []],
],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class $Root extends $stdlib.std.Resource {
[Foo, ["bars"]],
],
"$inflight_init": [
[Foo, []],
],
});
}
Expand Down
2 changes: 2 additions & 0 deletions libs/wingc/src/jsify/snapshots/closure_field.snap
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class $Root extends $stdlib.std.Resource {
[globalBucket, ["list"]],
],
"$inflight_init": [
[globalBucket, []],
],
});
}
Expand Down Expand Up @@ -208,6 +209,7 @@ class $Root extends $stdlib.std.Resource {
[x, ["foo"]],
],
"$inflight_init": [
[x, []],
],
});
}
Expand Down
1 change: 1 addition & 0 deletions libs/wingc/src/jsify/snapshots/enum_value.snap
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class $Root extends $stdlib.std.Resource {
[x, []],
],
"$inflight_init": [
[x, []],
],
});
}
Expand Down
2 changes: 2 additions & 0 deletions libs/wingc/src/jsify/snapshots/indirect_capture.snap
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class $Root extends $stdlib.std.Resource {
[this, ["foo"]],
],
"$inflight_init": [
[b, []],
],
});
}
Expand Down Expand Up @@ -150,6 +151,7 @@ class $Root extends $stdlib.std.Resource {
[f, ["goo"]],
],
"$inflight_init": [
[f, []],
],
});
}
Expand Down
1 change: 1 addition & 0 deletions libs/wingc/src/jsify/snapshots/inline_inflight_class.snap
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class $Root extends $stdlib.std.Resource {
[__parent_this_1.b, ["put"]],
],
"$inflight_init": [
[__parent_this_1.b, []],
],
});
}
Expand Down
1 change: 1 addition & 0 deletions libs/wingc/src/jsify/snapshots/json_object.snap
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class $Root extends $stdlib.std.Resource {
[jsonObj1, []],
],
"$inflight_init": [
[jsonObj1, []],
],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class $Root extends $stdlib.std.Resource {
[x, []],
],
"$inflight_init": [
[x, []],
],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class $Root extends $stdlib.std.Resource {
[y, []],
],
"$inflight_init": [
[x, []],
[y, []],
],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class $Root extends $stdlib.std.Resource {
[((arr, index) => { if (index < 0 || index >= arr.length) throw new Error("Index out of bounds"); return arr[index]; })(a, 0), ["put"]],
],
"$inflight_init": [
[((arr, index) => { if (index < 0 || index >= arr.length) throw new Error("Index out of bounds"); return arr[index]; })(a, 0), []],
],
});
}
Expand Down
1 change: 1 addition & 0 deletions libs/wingc/src/jsify/snapshots/lift_inflight_closure.snap
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class $Root extends $stdlib.std.Resource {
[f, ["handle"]],
],
"$inflight_init": [
[f, []],
],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class $Root extends $stdlib.std.Resource {
[b, ["put"]],
],
"$inflight_init": [
[b, []],
],
});
}
Expand Down
1 change: 1 addition & 0 deletions libs/wingc/src/jsify/snapshots/lift_self_reference.snap
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class $Root extends $stdlib.std.Resource {
[Foo, ["static_method"]],
],
"$inflight_init": [
[Foo, []],
],
});
}
Expand Down
1 change: 1 addition & 0 deletions libs/wingc/src/jsify/snapshots/lift_string.snap
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class $Root extends $stdlib.std.Resource {
[b, []],
],
"$inflight_init": [
[b, []],
],
});
}
Expand Down
1 change: 1 addition & 0 deletions libs/wingc/src/jsify/snapshots/lift_this.snap
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class $Root extends $stdlib.std.Resource {
[f, ["foo"]],
],
"$inflight_init": [
[f, []],
],
});
}
Expand Down
2 changes: 2 additions & 0 deletions libs/wingc/src/jsify/snapshots/lift_via_closure.snap
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class $Root extends $stdlib.std.Resource {
[bucket, ["put"]],
],
"$inflight_init": [
[bucket, []],
],
});
}
Expand Down Expand Up @@ -139,6 +140,7 @@ class $Root extends $stdlib.std.Resource {
[fn, ["handle"]],
],
"$inflight_init": [
[fn, []],
],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class $Root extends $stdlib.std.Resource {
[fn, ["handle"]],
],
"$inflight_init": [
[fn, []],
],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class $Root extends $stdlib.std.Resource {
[y, ["b"]],
],
"$inflight_init": [
[y, []],
],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ class $Root extends $stdlib.std.Resource {
[t.y.b, ["put"]],
],
"$inflight_init": [
[t.y.b, []],
],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class $Root extends $stdlib.std.Resource {
[i, []],
],
"$inflight_init": [
[i, []],
],
});
}
Expand Down
2 changes: 2 additions & 0 deletions libs/wingc/src/jsify/snapshots/preflight_collection.snap
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class $Root extends $stdlib.std.Resource {
[a.length, []],
],
"$inflight_init": [
[((arr, index) => { if (index < 0 || index >= arr.length) throw new Error("Index out of bounds"); return arr[index]; })(a, 0), []],
[a.length, []],
],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class $Root extends $stdlib.std.Resource {
[arr.length, []],
],
"$inflight_init": [
[((arr, index) => { if (index < 0 || index >= arr.length) throw new Error("Index out of bounds"); return arr[index]; })(arr, 0), []],
[arr.length, []],
],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class $Root extends $stdlib.std.Resource {
[a.bucky, ["list"]],
],
"$inflight_init": [
[a.bucky, []],
],
});
}
Expand Down
1 change: 1 addition & 0 deletions libs/wingc/src/jsify/snapshots/preflight_object.snap
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class $Root extends $stdlib.std.Resource {
[pf_obj, ["goodbye", "hello"]],
],
"$inflight_init": [
[pf_obj, []],
],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class $Root extends $stdlib.std.Resource {
[t.b, ["put"]],
],
"$inflight_init": [
[t.b, []],
],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class $Root extends $stdlib.std.Resource {
[b, ["list", "put"]],
],
"$inflight_init": [
[b, []],
],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class $Root extends $stdlib.std.Resource {
[b, ["list"]],
],
"$inflight_init": [
[b, []],
],
});
}
Expand Down
3 changes: 3 additions & 0 deletions libs/wingc/src/jsify/snapshots/preflight_value_field.snap
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ class $Root extends $stdlib.std.Resource {
[t.name.length, []],
],
"$inflight_init": [
[t.last, []],
[t.name, []],
[t.name.length, []],
],
});
}
Expand Down
Loading

0 comments on commit 673ca77

Please sign in to comment.