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

fix(compiler): can't reuse inflight closures #5483

Merged
merged 15 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
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
12 changes: 12 additions & 0 deletions examples/tests/valid/inflight_closure_autoid.test.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
let var inflights = MutArray<inflight ():num>[];
for i in 0..5 {
inflights.push(inflight ():num => {
return i;
});
}

test "inflight closure auto id" {
for i in 0..5 {
assert(inflights.at(i)() == i);
}
}
1 change: 1 addition & 0 deletions libs/wingc/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ pub struct Class {
pub implements: Vec<UserDefinedType>,
pub phase: Phase,
pub access: AccessModifier,
pub auto_id: bool,
}

impl Class {
Expand Down
1 change: 1 addition & 0 deletions libs/wingc/src/closure_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ impl Fold for ClosureTransformer {
access: AccessModifier::Public,
},
access: AccessModifier::Private,
auto_id: true,
}),
idx: self.nearest_stmt_idx,
span: WingSpan::for_file(file_id),
Expand Down
1 change: 1 addition & 0 deletions libs/wingc/src/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ where
phase: node.phase,
inflight_initializer: f.fold_function_definition(node.inflight_initializer),
access: node.access,
auto_id: node.auto_id,
}
}

Expand Down
15 changes: 12 additions & 3 deletions libs/wingc/src/jsify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ use crate::{
ClassLike, Type, TypeRef, Types, VariableKind, CLASS_INFLIGHT_INIT_NAME,
},
visit_context::{VisitContext, VisitorWithContext},
MACRO_REPLACE_ARGS, MACRO_REPLACE_ARGS_TEXT, MACRO_REPLACE_SELF, WINGSDK_ASSEMBLY_NAME, WINGSDK_RESOURCE,
WINGSDK_STD_MODULE,
MACRO_REPLACE_ARGS, MACRO_REPLACE_ARGS_TEXT, MACRO_REPLACE_SELF, WINGSDK_ASSEMBLY_NAME, WINGSDK_AUTOID_RESOURCE,
WINGSDK_RESOURCE, WINGSDK_STD_MODULE,
};

use self::codemaker::CodeMaker;
Expand All @@ -40,6 +40,7 @@ const PREFLIGHT_FILE_NAME: &str = "preflight.js";
const STDLIB: &str = "$stdlib";
const STDLIB_CORE: &str = formatcp!("{STDLIB}.core");
const STDLIB_CORE_RESOURCE: &str = formatcp!("{}.{}", STDLIB, WINGSDK_RESOURCE);
const STDLIB_CORE_AUTOID_RESOURCE: &str = formatcp!("{}.{}", STDLIB, WINGSDK_AUTOID_RESOURCE);
const STDLIB_MODULE: &str = WINGSDK_ASSEMBLY_NAME;

const ENV_WING_IS_TEST: &str = "$wing_is_test";
Expand Down Expand Up @@ -1450,7 +1451,15 @@ impl<'a> JSifier<'a> {
}
} else {
// default base class for preflight classes is `core.Resource`
code.append(new_code!(&class.name.span, " extends ", STDLIB_CORE_RESOURCE));
code.append(new_code!(
&class.name.span,
" extends ",
if class.auto_id {
STDLIB_CORE_AUTOID_RESOURCE
} else {
STDLIB_CORE_RESOURCE
}
));
};

code.append(" {");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const $helpers = $stdlib.helpers;
class $Root extends $stdlib.std.Resource {
constructor($scope, $id) {
super($scope, $id);
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const $helpers = $stdlib.helpers;
class $Root extends $stdlib.std.Resource {
constructor($scope, $id) {
super($scope, $id);
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const $helpers = $stdlib.helpers;
class $Root extends $stdlib.std.Resource {
constructor($scope, $id) {
super($scope, $id);
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
2 changes: 1 addition & 1 deletion libs/wingc/src/jsify/snapshots/builtins.snap
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const $helpers = $stdlib.helpers;
class $Root extends $stdlib.std.Resource {
constructor($scope, $id) {
super($scope, $id);
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const cloud = $stdlib.cloud;
class $Root extends $stdlib.std.Resource {
constructor($scope, $id) {
super($scope, $id);
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const util = $stdlib.util;
class $Root extends $stdlib.std.Resource {
constructor($scope, $id) {
super($scope, $id);
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const $helpers = $stdlib.helpers;
class $Root extends $stdlib.std.Resource {
constructor($scope, $id) {
super($scope, $id);
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand All @@ -93,7 +93,7 @@ class $Root extends $stdlib.std.Resource {
return [...super._supportedOps(), "handle", "$inflight_init"];
}
}
class $Closure2 extends $stdlib.std.Resource {
class $Closure2 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const $helpers = $stdlib.helpers;
class $Root extends $stdlib.std.Resource {
constructor($scope, $id) {
super($scope, $id);
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class $Root extends $stdlib.std.Resource {
return [...super._supportedOps(), "bar", "$inflight_init"];
}
}
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class $Root extends $stdlib.std.Resource {
return [...super._supportedOps(), "$inflight_init"];
}
}
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const $helpers = $stdlib.helpers;
class $Root extends $stdlib.std.Resource {
constructor($scope, $id) {
super($scope, $id);
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const util = $stdlib.util;
class $Root extends $stdlib.std.Resource {
constructor($scope, $id) {
super($scope, $id);
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const cloud = $stdlib.cloud;
class $Root extends $stdlib.std.Resource {
constructor($scope, $id) {
super($scope, $id);
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
2 changes: 1 addition & 1 deletion libs/wingc/src/jsify/snapshots/capture_token.snap
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const cloud = $stdlib.cloud;
class $Root extends $stdlib.std.Resource {
constructor($scope, $id) {
super($scope, $id);
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const $helpers = $stdlib.helpers;
class $Root extends $stdlib.std.Resource {
constructor($scope, $id) {
super($scope, $id);
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const $helpers = $stdlib.helpers;
class $Root extends $stdlib.std.Resource {
constructor($scope, $id) {
super($scope, $id);
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const $helpers = $stdlib.helpers;
class $Root extends $stdlib.std.Resource {
constructor($scope, $id) {
super($scope, $id);
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class $Root extends $stdlib.std.Resource {
return [...super._supportedOps(), "$inflight_init"];
}
}
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class $Root extends $stdlib.std.Resource {
return [...super._supportedOps(), "bars", "$inflight_init"];
}
}
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class $Root extends $stdlib.std.Resource {
return [...super._supportedOps(), "bar", "$inflight_init"];
}
}
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const $helpers = $stdlib.helpers;
class $Root extends $stdlib.std.Resource {
constructor($scope, $id) {
super($scope, $id);
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class $Root extends $stdlib.std.Resource {
return [...super._supportedOps(), "$inflight_init"];
}
}
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
4 changes: 2 additions & 2 deletions libs/wingc/src/jsify/snapshots/closure_field.snap
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class $Root extends $stdlib.std.Resource {
constructor($scope, $id, ) {
super($scope, $id);
const __parent_this_1 = this;
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down Expand Up @@ -184,7 +184,7 @@ class $Root extends $stdlib.std.Resource {
super.onLift(host, ops);
}
}
class $Closure2 extends $stdlib.std.Resource {
class $Closure2 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
2 changes: 1 addition & 1 deletion libs/wingc/src/jsify/snapshots/enum_value.snap
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const $helpers = $stdlib.helpers;
class $Root extends $stdlib.std.Resource {
constructor($scope, $id) {
super($scope, $id);
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const $helpers = $stdlib.helpers;
class $Root extends $stdlib.std.Resource {
constructor($scope, $id) {
super($scope, $id);
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
2 changes: 1 addition & 1 deletion libs/wingc/src/jsify/snapshots/func_returns_func.snap
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const $helpers = $stdlib.helpers;
class $Root extends $stdlib.std.Resource {
constructor($scope, $id) {
super($scope, $id);
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
2 changes: 1 addition & 1 deletion libs/wingc/src/jsify/snapshots/indirect_capture.snap
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class $Root extends $stdlib.std.Resource {
super.onLift(host, ops);
}
}
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const $helpers = $stdlib.helpers;
class $Root extends $stdlib.std.Resource {
constructor($scope, $id) {
super($scope, $id);
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class $Root extends $stdlib.std.Resource {
this.b = this.node.root.new("@winglang/sdk.cloud.Bucket", cloud.Bucket, this, "cloud.Bucket");
this.q = this.node.root.new("@winglang/sdk.cloud.Queue", cloud.Queue, this, "cloud.Queue");
const __parent_this_1 = this;
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
2 changes: 1 addition & 1 deletion libs/wingc/src/jsify/snapshots/json_object.snap
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const $helpers = $stdlib.helpers;
class $Root extends $stdlib.std.Resource {
constructor($scope, $id) {
super($scope, $id);
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const $helpers = $stdlib.helpers;
class $Root extends $stdlib.std.Resource {
constructor($scope, $id) {
super($scope, $id);
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const $helpers = $stdlib.helpers;
class $Root extends $stdlib.std.Resource {
constructor($scope, $id) {
super($scope, $id);
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const cloud = $stdlib.cloud;
class $Root extends $stdlib.std.Resource {
constructor($scope, $id) {
super($scope, $id);
class $Closure1 extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.AutoIdResource {
_id = $stdlib.core.closureId();
constructor($scope, $id, ) {
super($scope, $id);
Expand Down
Loading
Loading