Skip to content

Commit eff7800

Browse files
committed
session-manager: Add all desugars to fixed point
gcc/rust/ChangeLog: * ast/rust-desugar-apit.cc: Mark as clean when starting a desugar, and as dirty when actually doing a desugar. * ast/rust-expression-yeast.cc (ExpressionYeast::go): Likewise. * ast/rust-desugar-apit.h: Add dirty flag. * ast/rust-expression-yeast.h: Likewise. * rust-session-manager.cc (Session::expansion): Move desugars to fixed point.
1 parent 5c38744 commit eff7800

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

gcc/rust/ast/rust-desugar-apit.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,8 @@ DesugarApit::DesugarApit () {}
489489
void
490490
DesugarApit::go (AST::Crate &crate)
491491
{
492+
dirty = false;
493+
492494
DefaultASTVisitor::visit (crate);
493495
}
494496

@@ -523,6 +525,7 @@ DesugarApit::visit (AST::Function &function)
523525
ApitBoundProcessor processor (function.get_where_clause (),
524526
function.get_generic_params ());
525527
processor.go (implicit_generics);
528+
dirty = true;
526529
}
527530
}
528531

gcc/rust/ast/rust-desugar-apit.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ class DesugarApit : public DefaultASTVisitor
3232
DesugarApit ();
3333
void go (AST::Crate &);
3434

35+
bool has_changed () const { return dirty; }
36+
3537
private:
3638
void visit (AST::Function &) override;
39+
40+
bool dirty = false;
3741
};
3842

3943
} // namespace AST

gcc/rust/ast/rust-expression-yeast.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ namespace AST {
3232
void
3333
ExpressionYeast::go (AST::Crate &crate)
3434
{
35+
dirty = false;
36+
3537
DefaultASTVisitor::visit (crate);
3638
}
3739

@@ -69,8 +71,10 @@ ExpressionYeast::dispatch (std::unique_ptr<Expr> &expr)
6971
break;
7072

7173
default:
72-
break;
74+
return;
7375
}
76+
77+
dirty = true;
7478
}
7579

7680
void

gcc/rust/ast/rust-expression-yeast.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class ExpressionYeast : public AST::DefaultASTVisitor
3535
public:
3636
void go (AST::Crate &);
3737

38+
bool has_changed () const { return dirty; }
39+
3840
private:
3941
// Dispatch to the proper desugar
4042
void dispatch (std::unique_ptr<Expr> &expr);
@@ -44,6 +46,8 @@ class ExpressionYeast : public AST::DefaultASTVisitor
4446
void visit (AST::CallExpr &) override;
4547
void visit (AST::LetStmt &) override;
4648
void visit (AST::BlockExpr &) override;
49+
50+
bool dirty = false;
4751
};
4852

4953
} // namespace AST

gcc/rust/rust-session-manager.cc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,9 @@ Session::expansion (AST::Crate &crate, Resolver2_0::NameResolutionContext &ctx)
936936
MacroExpander expander (crate, cfg, *this);
937937
std::vector<Error> macro_errors;
938938

939+
auto yeast = AST::ExpressionYeast ();
940+
auto desugar_apit = AST::DesugarApit ();
941+
939942
while (!fixed_point_reached && iterations < cfg.recursion_limit)
940943
{
941944
CfgStrip (cfg).go (crate);
@@ -955,9 +958,15 @@ Session::expansion (AST::Crate &crate, Resolver2_0::NameResolutionContext &ctx)
955958
if (saw_errors ())
956959
break;
957960

961+
yeast.go (crate);
962+
desugar_apit.go (crate);
963+
958964
ExpandVisitor (expander).go (crate);
959965

960-
fixed_point_reached = !expander.has_changed () && !visitor_dirty;
966+
fixed_point_reached = !expander.has_changed () && !visitor_dirty
967+
&& !yeast.has_changed ()
968+
&& !desugar_apit.has_changed ();
969+
961970
expander.reset_changed_state ();
962971
iterations++;
963972

@@ -985,10 +994,6 @@ Session::expansion (AST::Crate &crate, Resolver2_0::NameResolutionContext &ctx)
985994
// handle AST desugaring
986995
if (!saw_errors ())
987996
{
988-
AST::ExpressionYeast ().go (crate);
989-
990-
AST::DesugarApit ().go (crate);
991-
992997
// HACK: we may need a final TopLevel pass
993998
// however, this should not count towards the recursion limit
994999
// and we don't need a full Early pass

0 commit comments

Comments
 (0)