Skip to content

Commit 3df53dd

Browse files
powerboat9philberty
authored andcommitted
Avoid including rust-parse-impl.h in rust-parse.h
This should reduce incremental compile times when modifying rust-parse-impl.h and not rust-parse.h. gcc/rust/ChangeLog: * Make-lang.in (GRS_OBJS): Add entries. * parse/rust-parse-impl.h: Adjust header comment. (Parser::parse_lifetime_params_objs): Fix bug and add comment. (Parser::unexpected_token): Likewise. * parse/rust-parse.h: Remove inclusion of "rust-parse-impl.h". * parse/rust-parse-impl-lexer.cc: New file. * parse/rust-parse-impl-macro.cc: New file. * parse/rust-parse-impl-proc-macro.cc: New file. Signed-off-by: Owen Avery <[email protected]>
1 parent fb5649c commit 3df53dd

File tree

6 files changed

+95
-7
lines changed

6 files changed

+95
-7
lines changed

gcc/rust/Make-lang.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ GRS_OBJS = \
7373
rust/rust-lex.o \
7474
rust/rust-cfg-parser.o \
7575
rust/rust-parse.o \
76+
rust/rust-parse-impl-proc-macro.o \
77+
rust/rust-parse-impl-macro.o \
78+
rust/rust-parse-impl-lexer.o \
7679
rust/rust-ast.o \
7780
rust/rust-ast-formatting.o \
7881
rust/rust-path.o \
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (C) 2025 Free Software Foundation, Inc.
2+
3+
// This file is part of GCC.
4+
5+
// GCC is free software; you can redistribute it and/or modify it under
6+
// the terms of the GNU General Public License as published by the Free
7+
// Software Foundation; either version 3, or (at your option) any later
8+
// version.
9+
10+
// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11+
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
// for more details.
14+
15+
// You should have received a copy of the GNU General Public License
16+
// along with GCC; see the file COPYING3. If not see
17+
// <http://www.gnu.org/licenses/>.
18+
19+
#include "rust-parse-impl.h"
20+
21+
namespace Rust {
22+
23+
template class Parser<Lexer>;
24+
25+
} // namespace Rust
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (C) 2025 Free Software Foundation, Inc.
2+
3+
// This file is part of GCC.
4+
5+
// GCC is free software; you can redistribute it and/or modify it under
6+
// the terms of the GNU General Public License as published by the Free
7+
// Software Foundation; either version 3, or (at your option) any later
8+
// version.
9+
10+
// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11+
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
// for more details.
14+
15+
// You should have received a copy of the GNU General Public License
16+
// along with GCC; see the file COPYING3. If not see
17+
// <http://www.gnu.org/licenses/>.
18+
19+
#include "rust-parse-impl.h"
20+
#include "rust-macro-invoc-lexer.h"
21+
22+
namespace Rust {
23+
24+
template class Parser<MacroInvocLexer>;
25+
26+
} // namespace Rust
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (C) 2025 Free Software Foundation, Inc.
2+
3+
// This file is part of GCC.
4+
5+
// GCC is free software; you can redistribute it and/or modify it under
6+
// the terms of the GNU General Public License as published by the Free
7+
// Software Foundation; either version 3, or (at your option) any later
8+
// version.
9+
10+
// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11+
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
// for more details.
14+
15+
// You should have received a copy of the GNU General Public License
16+
// along with GCC; see the file COPYING3. If not see
17+
// <http://www.gnu.org/licenses/>.
18+
19+
#include "rust-parse-impl.h"
20+
#include "rust-proc-macro-invoc-lexer.h"
21+
22+
namespace Rust {
23+
24+
template std::unique_ptr<AST::Item>
25+
Parser<ProcMacroInvocLexer>::parse_item (bool);
26+
27+
template std::unique_ptr<AST::Stmt>
28+
Parser<ProcMacroInvocLexer>::parse_stmt (ParseRestrictions);
29+
30+
// instantiate entire class (or just more functions) if necessary
31+
32+
// template class Parser<ProcMacroInvocLexer>;
33+
34+
} // namespace Rust

gcc/rust/parse/rust-parse-impl.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
/* Template implementation for Rust::Parser. Previously in rust-parse.cc (before
2020
* Parser was template). Separated from rust-parse.h for readability. */
2121

22-
/* DO NOT INCLUDE ANYWHERE - this is automatically included with rust-parse.h
22+
/* DO NOT INCLUDE ANYWHERE - this is automatically included
23+
* by rust-parse-impl-*.cc
2324
* This is also the reason why there are no include guards. */
2425

2526
#include "expected.h"
@@ -3372,7 +3373,8 @@ Parser<ManagedTokenSource>::parse_lifetime_params (EndTokenPred is_end_token)
33723373

33733374
/* Parses lifetime generic parameters (objects). Will also consume any
33743375
* trailing comma. No extra checks for end token.
3375-
* TODO: is this best solution? implements most of the same algorithm. */
3376+
* TODO: is this best solution? implements most of the same algorithm.
3377+
* TODO: seems to be unused, remove? */
33763378
template <typename ManagedTokenSource>
33773379
std::vector<AST::LifetimeParam>
33783380
Parser<ManagedTokenSource>::parse_lifetime_params_objs ()
@@ -3390,7 +3392,7 @@ Parser<ManagedTokenSource>::parse_lifetime_params_objs ()
33903392
break;
33913393
}
33923394

3393-
lifetime_params.push_back (std::move (lifetime_param));
3395+
lifetime_params.push_back (std::move (lifetime_param.value ()));
33943396

33953397
if (lexer.peek_token ()->get_id () != COMMA)
33963398
break;
@@ -11920,11 +11922,12 @@ Parser<ManagedTokenSource>::parse_struct_expr_field ()
1192011922
}
1192111923

1192211924
// "Unexpected token" panic mode - flags gcc error at unexpected token
11925+
// TODO: seems to be unused, remove?
1192311926
template <typename ManagedTokenSource>
1192411927
void
1192511928
Parser<ManagedTokenSource>::unexpected_token (const_TokenPtr t)
1192611929
{
11927-
Error error (t->get_locus (), "unexpected token %qs\n",
11930+
Error error (t->get_locus (), "unexpected token %qs",
1192811931
t->get_token_description ());
1192911932
add_error (std::move (error));
1193011933
}

gcc/rust/parse/rust-parse.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,4 @@ bool is_match_compatible (const AST::MacroMatch &last_match,
797797
const AST::MacroMatch &current_match);
798798
} // namespace Rust
799799

800-
// as now template, include implementations of all methods
801-
#include "rust-parse-impl.h"
802-
803800
#endif // RUST_PARSE_H

0 commit comments

Comments
 (0)