aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/rust-session-manager.cc
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2023-06-21 11:04:04 -0700
committerIan Lance Taylor <iant@golang.org>2023-06-21 11:04:04 -0700
commit97e31a0a2a2d2273687fcdb4e5416aab1a2186e1 (patch)
treed5c1cae4de436a0fe54a5f0a2a197d309f3d654c /gcc/rust/rust-session-manager.cc
parent6612f4f8cb9b0d5af18ec69ad04e56debc3e6ced (diff)
parent577223aebc7acdd31e62b33c1682fe54a622ae27 (diff)
downloadgcc-97e31a0a2a2d2273687fcdb4e5416aab1a2186e1.zip
gcc-97e31a0a2a2d2273687fcdb4e5416aab1a2186e1.tar.gz
gcc-97e31a0a2a2d2273687fcdb4e5416aab1a2186e1.tar.bz2
Merge from trunk revision 577223aebc7acdd31e62b33c1682fe54a622ae27.
Diffstat (limited to 'gcc/rust/rust-session-manager.cc')
-rw-r--r--gcc/rust/rust-session-manager.cc49
1 files changed, 40 insertions, 9 deletions
diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index 732aabe..074bad9 100644
--- a/gcc/rust/rust-session-manager.cc
+++ b/gcc/rust/rust-session-manager.cc
@@ -27,6 +27,7 @@
#include "rust-hir-type-check.h"
#include "rust-privacy-check.h"
#include "rust-const-checker.h"
+#include "rust-feature-gate.h"
#include "rust-tycheck-dump.h"
#include "rust-compile.h"
#include "rust-cfg-parser.h"
@@ -192,7 +193,7 @@ Session::handle_option (
else
{
rust_assert (!error.message.empty ());
- error.emit_error ();
+ error.emit ();
}
}
else
@@ -390,7 +391,7 @@ Session::handle_crate_name (const AST::Crate &parsed_crate)
if (!validate_crate_name (msg_str, error))
{
error.locus = attr.get_locus ();
- error.emit_error ();
+ error.emit ();
continue;
}
@@ -411,7 +412,7 @@ Session::handle_crate_name (const AST::Crate &parsed_crate)
if (!options.crate_name_set_manually
&& !validate_crate_name (options.crate_name, error))
{
- error.emit_error ();
+ error.emit ();
rust_inform (linemap->get_location (0),
"crate name inferred from this file");
}
@@ -438,9 +439,9 @@ Session::compile_crate (const char *filename)
"manner by passing the following flag:\n\n"
"`-frust-incomplete-and-experimental-compiler-do-not-use`\n\nor by "
"defining the following environment variable (any value will "
- "do)\n\nGCCRS_INCOMPLETE_AND_EXPERIMENTAL_COMPILER_DO_NOT_USE\n\nFor"
+ "do)\n\nGCCRS_INCOMPLETE_AND_EXPERIMENTAL_COMPILER_DO_NOT_USE\n\nFor "
"cargo-gccrs, this means passing\n\n"
- "GCCRS_EXTRA_FLAGS=\"-frust-incomplete-and-experimental-compiler-do-not-"
+ "GCCRS_EXTRA_ARGS=\"-frust-incomplete-and-experimental-compiler-do-not-"
"use\"\n\nas an environment variable.");
RAIIFile file_wrap (filename);
@@ -558,6 +559,9 @@ Session::compile_crate (const char *filename)
rust_debug ("END POST-EXPANSION AST DUMP");
}
+ // feature gating
+ FeatureGate ().check (parsed_crate);
+
if (last_step == CompileOptions::CompileStep::NameResolution)
return;
@@ -817,9 +821,6 @@ Session::injection (AST::Crate &crate)
void
Session::expansion (AST::Crate &crate)
{
- /* We need to name resolve macros and imports here */
- Resolver::EarlyNameResolver ().go (crate);
-
rust_debug ("started expansion");
/* rustc has a modification to windows PATH temporarily here, which may end
@@ -829,11 +830,41 @@ Session::expansion (AST::Crate &crate)
// if not, would at least have to configure recursion_limit
ExpansionCfg cfg;
+ auto fixed_point_reached = false;
+ unsigned iterations = 0;
+
// create extctxt? from parse session, cfg, and resolver?
/* expand by calling cxtctxt object's monotonic_expander's expand_crate
* method. */
MacroExpander expander (crate, cfg, *this);
- expander.expand_crate ();
+
+ while (!fixed_point_reached && iterations < cfg.recursion_limit)
+ {
+ /* We need to name resolve macros and imports here */
+ Resolver::EarlyNameResolver ().go (crate);
+
+ expander.expand_crate ();
+
+ fixed_point_reached = !expander.has_changed ();
+ expander.reset_changed_state ();
+ iterations++;
+
+ if (saw_errors ())
+ break;
+ }
+
+ if (iterations == cfg.recursion_limit)
+ {
+ auto last_invoc = expander.get_last_invocation ();
+ auto last_def = expander.get_last_definition ();
+
+ rust_assert (last_def && last_invoc);
+
+ RichLocation range (last_invoc->get_locus ());
+ range.add_range (last_def->get_locus ());
+
+ rust_error_at (range, "reached recursion limit");
+ }
// error reporting - check unused macros, get missing fragment specifiers