Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(compiler): capture and lifting cleanups and fixes (#3899)
* Types aren't expressions anymore. This reverts a change in #3213. Back then we turned all user defined types into expressions so we can lift/capture them the same way we handle expressions. The downside was that the type system didn't make sense anymore (we added a type variable kind and the symbol env wasn't normalized). A side effect is better error spans on unknown type errors. * To handle capturing/lifting of Types I created a `Liftable` enum that represents AST elements that can be lifted. A lift token now points to a `Liftable` and not to an expression. Currently a `Liftable` can be either an expression or a `UserDefinedType`. * Simplified and normalized the `Lifts` data structure stored per class. It now contains: * `lifts_qualifications` - Stores information for each class inflight method which preflight code it lifts and for that code which ops are performed on it. It's a map of map: "method" -> "preflight js code" -> "set of ops". This data structure is used for generating the lift bindings. * `captures` - Stores capture tokens and for each token the preflight js code used for capture and also whether this is a free capture or an object field. This is used to initialize the tokens in preflight. * `token_for_liftable` - Maps capturable AST elements (`Liftable`s) to a capture token. This is used for generating inflight code when we encounter a captured type or expression during jsification. * Fixed a bug where a type referencing itself but calling an inflight static method wasn't properly lifted. No bindings were generated for it leading to potential permission issues. Added a snapshot test. * Fixed bug parsing static method calls on json `Json.something()` generated a wrong AST expression where we wrapped a `TypeMember` reference inside a `InstanceMemeber` reference (instead of just being a `TypeMemeber` reference). So the end jsification result was `Json.something().something()`?? * Fixed visitor type annotation's default implementation to call `visit_user_defined_type` for user defined types. ## 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