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

chore(compiler): type references as expressions and phase tracking #3177

Merged
merged 23 commits into from
Jun 30, 2023

Conversation

eladb
Copy link
Contributor

@eladb eladb commented Jun 30, 2023

No functional changes, preparatory pull request as part of the expression lifting escapade.

Type references are expressions that reference type names. It's valuable to model them as expressions because they are needed at runtime. Once they are modeled as expressions, we can treat all expressions equally when it comes to lifting (which is the motivation for this refactor).

We've changed the following places to use type references instead of a UserDefinedType. In all of these cases the types have a runtime presence. The rest of the places are just type annotations that are erased at runtime:

  • The class being instantiated in new expressions
  • Base classes
  • The type component in a Reference::TypeMember (static access).

Furthermore, to support expression lifting, the type checker now records the phase of each expression during type checking and makes it available through get_expr_phase.

Additionally, changed the left-hand-side of an assignment statement to be an Expr and not a Reference. Also in order to be able to lift it.

Turn the variable component of StmtKind::Assignment from a simple Symbol to an Expr in order for it to also hold type and phase information.

The JSII importer accidentally imported structs as preflight while they should be phase-independent.

Misc: strip excess newlines when adding a line to CodeMaker.

Checklist

  • Title matches Winglang's style guide
  • Description explains motivation and solution
  • 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 Monada Contribution License.

No functional changes, preparatory pull request as part of the expression lifting escapade.

To support expression lifting, the type checker now records the phase of each expression during type checking and makes it available through `get_expr_phase`.

Additionally, turn the variable component of `StmtKind::Assignment` from a simple `Symbol` to an `Expr` in order for it to also hold type and phase information.

The JSII importer accidentally imported structs as `preflight` while they should be phase-independent.

Misc: strip excess newlines when adding a line to `CodeMaker`.
@eladb eladb requested a review from a team as a code owner June 30, 2023 05:59
eladb and others added 2 commits June 30, 2023 09:06
@eladb eladb changed the title chore: add phase to each expression during type checking chore(compiler): treat type references as expressions and track phases Jun 30, 2023
Copy link
Contributor

@staycoolcall911 staycoolcall911 left a comment

Choose a reason for hiding this comment

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

Thanks to the detailed PR description reviewing was a breeze...

libs/wingc/src/type_check.rs Show resolved Hide resolved
tools/hangar/__snapshots__/invalid.ts.snap Show resolved Hide resolved
Fixes #2916 by returning exit code 0 when tests fail.

## Misc

Tweaks to a bunch of tests.

## Checklist

- [x] Title matches [Winglang's style guide](https://docs.winglang.io/contributing/pull_requests#how-are-pull-request-titles-formatted)
- [x] Description explains motivation and solution
- [x] Tests added (always)
- [x] Docs updated (only required for features)
- [x] 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 [Monada Contribution License](https://docs.winglang.io/terms-and-policies/contribution-license.html)*.
@eladb
Copy link
Contributor Author

eladb commented Jun 30, 2023

@MarkMcCulloh I'll make sure all the diagnostics around base classes are fixed. If that's all, I'd appreciate an approval so I can be unblocked with my next step.

@eladb eladb changed the title chore(compiler): treat type references as expressions and track phases chore(compiler): type references as expressions and phase tracking Jun 30, 2023
@eladb eladb requested a review from MarkMcCulloh June 30, 2023 14:22
Signed-off-by: monada-bot[bot] <[email protected]>
Copy link
Contributor

@MarkMcCulloh MarkMcCulloh left a comment

Choose a reason for hiding this comment

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

I'll make sure all the diagnostics around base classes are fixed. If that's all, I'd appreciate an approval so I can be unblocked with my next step.

Yeah LGTM as long as the diags are fixed. Luckily the grammar still prevents real expressions into places where types are expected so we might be safe from some new big regressions.

I also think @yoav-steinberg should take a look at this, but I'll leave that to you if you want to wait.

Signed-off-by: monada-bot[bot] <[email protected]>
@eladb
Copy link
Contributor Author

eladb commented Jun 30, 2023

Thanks. I'll check with @yoav-steinberg if he is available

libs/wingc/src/ast.rs Show resolved Hide resolved
libs/wingc/src/type_check.rs Show resolved Hide resolved
libs/wingc/src/type_check.rs Outdated Show resolved Hide resolved
libs/wingc/src/type_check.rs Show resolved Hide resolved
libs/wingc/src/type_check.rs Outdated Show resolved Hide resolved
libs/wingc/src/type_check.rs Show resolved Hide resolved
libs/wingc/src/type_check.rs Outdated Show resolved Hide resolved
examples/tests/invalid/inflight_reassign.w Show resolved Hide resolved
@mergify
Copy link
Contributor

mergify bot commented Jun 30, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify
Copy link
Contributor

mergify bot commented Jun 30, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 9840f37 into main Jun 30, 2023
11 checks passed
@mergify mergify bot deleted the eladb/add-phase-to-typecheck branch June 30, 2023 20:19
@monadabot
Copy link
Contributor

Congrats! 🚀 This was released in Wing 0.23.5.

revitalbarletz pushed a commit that referenced this pull request Jul 3, 2023
…3177)

No functional changes, preparatory pull request as part of the expression lifting escapade.

Type references are expressions that reference type names. It's valuable to model them as expressions because they are needed at runtime. Once they are modeled as expressions, we can treat all expressions equally when it comes to lifting (which is the motivation for this refactor).

We've changed the following places to use type references instead of a `UserDefinedType`. In all of these cases the types have a runtime presence. The rest of the places are just type annotations that are erased at runtime:

- The class being instantiated in `new` expressions
- Base classes
- The type component in a `Reference::TypeMember` (static access).

Furthermore, to support expression lifting, the type checker now records the phase of each expression during type checking and makes it available through `get_expr_phase`.

Additionally, changed the left-hand-side of an assignment statement to be an `Expr` and not a `Reference`. Also in order to be able to lift it.

Turn the variable component of `StmtKind::Assignment` from a simple `Symbol` to an `Expr` in order for it to also hold type and phase information.

The JSII importer accidentally imported structs as `preflight` while they should be phase-independent.

Misc: strip excess newlines when adding a line to `CodeMaker`.

## Checklist

- [x] Title matches [Winglang's style guide](https://docs.winglang.io/contributing/pull_requests#how-are-pull-request-titles-formatted)
- [x] Description explains motivation and solution
- [x] Tests added (always)
- [x] Docs updated (only required for features)
- [x] 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 [Monada Contribution License](https://docs.winglang.io/terms-and-policies/contribution-license.html)*.
@@ -2,8 +2,8 @@ enum SomeEnum {
ONE, TWO, THREE
}

let four = SomeEnum.FOUR;
// ERR ^^^^ enum value does not exist
// let four = SomeEnum.FOUR;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is that commented out on purpose?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants