Skip to content

Commit

Permalink
fix(compiler): remove some dead capturing code (#3799)
Browse files Browse the repository at this point in the history
This is a tiny fix removing dead capturing code. For some reason there's code that tries to capture the parent class of a inflight class in the irrelevant case that we're inside an inflight context. In this case the code is dead because an inflight class within an inflight class generates inlined code.

The PR also adds some coloring improvements to the env printing I used to debug this and fixed a comment related to parent class capturing.

## 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
- [ ] 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 Aug 14, 2023
1 parent 024225b commit fc4e195
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 13 deletions.
2 changes: 1 addition & 1 deletion libs/wingc/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ impl Expr {
Self { id, kind, span }
}

/// Returns true if the expression is a reference to a type.
/// Returns the user defined type if the expression is a reference to a type.
pub fn as_type_reference(&self) -> Option<&UserDefinedType> {
match &self.kind {
ExprKind::Reference(Reference::TypeReference(t)) => Some(t),
Expand Down
10 changes: 0 additions & 10 deletions libs/wingc/src/lifting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,16 +285,6 @@ impl<'a> Visit<'a> for LiftVisitor<'a> {
None
};

if self.ctx.current_phase() == Phase::Inflight {
if let Some(parent) = &node.parent {
if self.should_capture_expr(parent) {
let mut lifts = self.lifts_stack.pop().unwrap();
lifts.capture(&parent.id, &self.jsify_expr(&parent, Phase::Inflight));
self.lifts_stack.push(lifts);
}
}
}

let udt = UserDefinedType {
root: node.name.clone(),
fields: vec![],
Expand Down
4 changes: 2 additions & 2 deletions libs/wingc/src/type_check/symbol_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ impl Display for SymbolEnv {
let mut level = 0;
let mut env = self;
loop {
write!(f, "level {}: {{ ", level)?;
write!(f, "level {}: {{ ", level.to_string().bold())?;
let mut items = vec![];
for (name, (_, kind)) in &env.symbol_map {
let repr = match kind {
SymbolKind::Type(t) => format!("{} [type]", t).red(),
SymbolKind::Variable(v) => format!("{}", v.type_).blue(),
SymbolKind::Namespace(ns) => format!("{} [namespace]", ns.name).green(),
};
items.push(format!("{} => {}", name, repr));
items.push(format!("{} => {}", name.bold(), repr));
}
write!(f, "{} }}", items.join(", "))?;

Expand Down

0 comments on commit fc4e195

Please sign in to comment.