Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d961371
gccrs: Add wrapper class for automatic node cloning
powerboat9 Jan 3, 2026
64b6273
gccrs: ast: Fix missing location info in derive macros
Pasta-coder Feb 12, 2026
1d1f8db
gccrs: testsuite: Add test case for macro missing body
Harishankar14 Feb 25, 2026
5c3cd15
gccrs: Rename is_builtin and change return type
P-E-P Jan 30, 2026
822ee93
gccrs: Split feature collection from feature gating
P-E-P Jan 30, 2026
6741193
gccrs: Remove unused function
P-E-P Feb 4, 2026
de0e124
gccrs: Add early cfg strip step before feature collection
P-E-P Feb 5, 2026
0052d8c
gccrs: Bump feature definition version
P-E-P Feb 6, 2026
8c8ac84
gccrs: Collect feature gate error at parse time
P-E-P Feb 6, 2026
c065a4d
gccrs: Collect early feature gating errors in a store
P-E-P Feb 7, 2026
1312b5e
gccrs: Move early gate feature store to it's own TU
P-E-P Feb 7, 2026
d1441eb
gccrs: Add crate_name and crate_type to attribute values
P-E-P Feb 10, 2026
42917b0
gccrs: Add multiple missing builtin attribute values
P-E-P Feb 10, 2026
b2ac1c7
gccrs: Make attribute a proper AST node
P-E-P Feb 11, 2026
3c82545
gccrs: Add node id to attribute node.
P-E-P Feb 11, 2026
c1fada7
gccrs: Make Attribute parent class Visitable public
P-E-P Feb 18, 2026
97cd7d4
gccrs: Use Attribute node status for AttributeChecker
P-E-P Feb 19, 2026
10c53d3
gccrs: Add global scope debug function for crate
P-E-P Feb 23, 2026
17b16d9
gccrs: Add AttrInputExpr node
P-E-P Feb 23, 2026
90c4ab4
gccrs: Correctly emit warning on invalid attributes
P-E-P Feb 23, 2026
82b50dd
gccrs: Remove duplicated visit within early name res
P-E-P Feb 24, 2026
877df1d
gccrs: Add no_std attribute
P-E-P Feb 25, 2026
69a01e7
gccrs: ast: Implement reconstruct() logic for Path hierarchy
Pasta-coder Jan 16, 2026
558d460
gccrs: refactor: use MacroInvocation's node id everywhere for consist…
v1bh475u Feb 6, 2026
eb8afe6
gccrs: refactor: update constructor to initialize ExternalItem base c…
v1bh475u Feb 6, 2026
b084f9a
gccrs: expand: Fix ICE on unimplemented RustcEncodable/Decodable derives
Pasta-coder Feb 14, 2026
35922d1
gccrs: Fix match arm scope
powerboat9 Mar 3, 2026
09aa962
gccrs: Prevent error emission with multiple wildcards
P-E-P Feb 25, 2026
ddb2287
gccrs: Change variable underscore detection
P-E-P Mar 3, 2026
5f6d421
gccrs: Use custom error type for enum variants parsing
P-E-P Mar 2, 2026
1989cb9
gccrs: Do not warn on unused function with "_" prefix
P-E-P Mar 4, 2026
8c25d65
gccrs: Remove duplicated error message.
P-E-P Mar 4, 2026
eca3228
gccrs: Add additional test for wildcard special identifier
P-E-P Mar 4, 2026
c25c301
gccrs: Put intrinsics in their own namespace and TU
P-E-P Mar 4, 2026
36b6949
gccrs: Use predefined intrinsic instead of raw values
P-E-P Mar 4, 2026
bfc8bf9
gccrs: resolve: Fix ICE on ambiguous glob re-exports
Harishankar14 Feb 27, 2026
555dabe
gccrs: feat: Implement `no_core` feature gate check
moabo3li Mar 5, 2026
159845e
gccrs: intrinsic: Add bswap intrinsic
nsvke Feb 27, 2026
ef3ef71
gccrs: Add no_std to builtin attributes
P-E-P Mar 6, 2026
ba1fef9
gccrs: Add ability to inject inner attributes from CLI
P-E-P Mar 10, 2026
55008a4
gccrs: Move cli inner attribute injection to injection
P-E-P Mar 11, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions gcc/rust/Make-lang.in
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ GRS_OBJS = \
rust/rust-compile-resolve-path.o \
rust/rust-macro-expand.o \
rust/rust-cfg-strip.o \
rust/rust-early-cfg-strip.o \
rust/rust-expand-visitor.o \
rust/rust-ast-builder.o \
rust/rust-derive.o \
Expand Down Expand Up @@ -205,6 +206,7 @@ GRS_OBJS = \
rust/rust-hir-type-check-path.o \
rust/rust-unsafe-checker.o \
rust/rust-hir-pattern-analysis.o \
rust/rust-intrinsic-handlers.o \
rust/rust-compile-intrinsic.o \
rust/rust-compile-pattern.o \
rust/rust-compile-fnparam.o \
Expand All @@ -229,6 +231,8 @@ GRS_OBJS = \
rust/rust-builtins.o \
rust/rust-feature.o \
rust/rust-feature-gate.o \
rust/rust-feature-store.o \
rust/rust-feature-collector.o \
rust/rust-ast-validation.o \
rust/rust-dir-owner.o \
rust/rust-unicode.o \
Expand Down
12 changes: 12 additions & 0 deletions gcc/rust/ast/rust-ast-collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ TokenCollector::visit (Attribute &attrib)
visit (static_cast<AttrInputMacro &> (attrib.get_attr_input ()));
break;
}
case AST::AttrInput::AttrInputType::EXPR:
{
visit (static_cast<AttrInputExpr &> (attrib.get_attr_input ()));
break;
}
case AST::AttrInput::AttrInputType::META_ITEM:
{
visit (static_cast<AttrInputMetaItemContainer &> (
Expand Down Expand Up @@ -907,6 +912,13 @@ TokenCollector::visit (AttrInputMacro &macro)
});
}

void
TokenCollector::visit (AttrInputExpr &attr)
{
describe_node (std::string ("AttrInputExpr"),
[this, &attr] () { visit (attr.get_expr ()); });
}

void
TokenCollector::visit (MetaItemLitExpr &item)
{
Expand Down
1 change: 1 addition & 0 deletions gcc/rust/ast/rust-ast-collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ class TokenCollector : public ASTVisitor
void visit (LiteralExpr &expr);
void visit (AttrInputLiteral &attr_input);
void visit (AttrInputMacro &attr_input);
void visit (AttrInputExpr &attr_input);
void visit (MetaItemLitExpr &meta_item);
void visit (MetaItemPathExpr &meta_item);
void visit (BorrowExpr &expr);
Expand Down
13 changes: 13 additions & 0 deletions gcc/rust/ast/rust-ast-dump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,16 @@ debug (Rust::AST::Visitable &v)
{
Rust::AST::Dump::debug (v);
}

void
debug (Rust::AST::Crate &crate)
{
for (auto &inner_attr : crate.get_inner_attrs ())
{
debug (inner_attr);
}
for (auto &item : crate.items)
{
debug (*item);
}
}
1 change: 1 addition & 0 deletions gcc/rust/ast/rust-ast-dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,6 @@ class Dump

// In the global namespace to make it easier to call from debugger
void debug (Rust::AST::Visitable &v);
void debug (Rust::AST::Crate &v);

#endif // !RUST_AST_DUMP_H
2 changes: 1 addition & 1 deletion gcc/rust/ast/rust-ast-full-decls.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DelimTokenTree;
class PathSegment;
class SimplePathSegment;
class SimplePath;
struct Attribute;
class Attribute;
class MetaItemInner;
class AttrInputMetaItemContainer;
class MetaItem;
Expand Down
14 changes: 14 additions & 0 deletions gcc/rust/ast/rust-ast-visitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ DefaultASTVisitor::visit (AST::LiteralExpr &expr)
visit_outer_attrs (expr);
}

void
DefaultASTVisitor::visit (AST::Attribute &attribute)
{
visit (attribute.get_path ());
if (attribute.has_attr_input ())
visit (attribute.get_attr_input ());
}

void
DefaultASTVisitor::visit (AST::AttrInputLiteral &attr_input)
{
Expand All @@ -206,6 +214,12 @@ DefaultASTVisitor::visit (AST::AttrInputMacro &attr_input)
visit (attr_input.get_macro ());
}

void
DefaultASTVisitor::visit (AST::AttrInputExpr &attr_input)
{
visit (attr_input.get_expr ());
}

void
DefaultASTVisitor::visit (AST::MetaItemLitExpr &meta_item)
{
Expand Down
5 changes: 4 additions & 1 deletion gcc/rust/ast/rust-ast-visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class ASTVisitor

// rust-ast.h
// virtual void visit(AttrInput& attr_input) = 0;
virtual void visit (AST::Attribute &attribute) = 0;
// virtual void visit(TokenTree& token_tree) = 0;
// virtual void visit(MacroMatch& macro_match) = 0;
virtual void visit (Token &tok) = 0;
Expand Down Expand Up @@ -72,6 +73,7 @@ class ASTVisitor
virtual void visit (LiteralExpr &expr) = 0;
virtual void visit (AttrInputLiteral &attr_input) = 0;
virtual void visit (AttrInputMacro &attr_input) = 0;
virtual void visit (AttrInputExpr &attr_input) = 0;
virtual void visit (MetaItemLitExpr &meta_item) = 0;
virtual void visit (MetaItemPathExpr &meta_item) = 0;
virtual void visit (BorrowExpr &expr) = 0;
Expand Down Expand Up @@ -267,6 +269,7 @@ class DefaultASTVisitor : public ASTVisitor
virtual void visit (AST::QualifiedPathInType &path) override;
virtual void visit (AST::LiteralExpr &expr) override;
virtual void visit (AST::AttrInputLiteral &attr_input) override;
virtual void visit (AST::AttrInputExpr &attr_input) override;
virtual void visit (AST::AttrInputMacro &attr_input) override;
virtual void visit (AST::MetaItemLitExpr &meta_item) override;
virtual void visit (AST::MetaItemPathExpr &meta_item) override;
Expand Down Expand Up @@ -444,7 +447,7 @@ class DefaultASTVisitor : public ASTVisitor
virtual void visit (AST::StructPatternElements &spe);
virtual void visit (AST::MaybeNamedParam &param);

void visit (AST::Attribute &attribute) {}
virtual void visit (AST::Attribute &attribute) override;

template <typename T> void visit_outer_attrs (T &node)
{
Expand Down
55 changes: 43 additions & 12 deletions gcc/rust/ast/rust-ast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ Crate::inject_extern_crate (std::string name)
{}, UNKNOWN_LOCATION)));
}

void
Crate::inject_inner_attribute (Attribute attribute)
{
inner_attrs.push_back (attribute);
}

std::string
Attribute::as_string () const
{
Expand All @@ -253,6 +259,12 @@ Attribute::as_string () const
return path_str + attr_input->as_string ();
}

void
Attribute::accept_vis (ASTVisitor &vis)
{
vis.visit (*this);
}

bool
Attribute::is_derive () const
{
Expand Down Expand Up @@ -302,8 +314,9 @@ Attribute::get_traits_to_derive ()
auto word = static_cast<AST::MetaWord *> (meta_item);
// Convert current word to path
current = std::make_unique<AST::MetaItemPath> (
AST::MetaItemPath (
AST::SimplePath (word->get_ident ())));
AST::MetaItemPath (AST::SimplePath::from_str (
word->get_ident ().as_string (),
word->get_locus ())));
auto path
= static_cast<AST::MetaItemPath *> (current.get ());

Expand Down Expand Up @@ -332,6 +345,7 @@ Attribute::get_traits_to_derive ()
case AST::AttrInput::TOKEN_TREE:
case AST::AttrInput::LITERAL:
case AST::AttrInput::MACRO:
case AST::AttrInput::EXPR:
rust_unreachable ();
break;
}
Expand Down Expand Up @@ -3340,6 +3354,29 @@ AttrInputMetaItemContainer::as_string () const
return str + ")";
}

AttrInputExpr::AttrInputExpr (const AttrInputExpr &oth)
: expr (oth.expr->clone_expr ())
{}

AttrInputExpr &
AttrInputExpr::operator= (const AttrInputExpr &oth)
{
expr = oth.expr->clone_expr ();
return *this;
}

std::string
AttrInputExpr::as_string () const
{
return expr->as_string ();
}

void
AttrInputExpr::accept_vis (ASTVisitor &vis)
{
vis.visit (*this);
}

std::string
AttrInputMacro::as_string () const
{
Expand Down Expand Up @@ -4169,10 +4206,8 @@ MetaListNameValueStr::to_attribute () const
Attribute
MetaItemPathExpr::to_attribute () const
{
rust_assert (expr->is_literal ());
auto &lit = static_cast<LiteralExpr &> (*expr);
return Attribute (path, std::unique_ptr<AttrInputLiteral> (
new AttrInputLiteral (lit)));
auto input = std::make_unique<AttrInputExpr> (expr->clone_expr ());
return Attribute (path, std::move (input));
}

std::vector<Attribute>
Expand All @@ -4188,13 +4223,9 @@ AttrInputMetaItemContainer::separate_cfg_attrs () const

for (auto it = items.begin () + 1; it != items.end (); ++it)
{
if ((*it)->get_kind () == MetaItemInner::Kind::MetaItem
&& static_cast<MetaItem &> (**it).get_item_kind ()
== MetaItem::ItemKind::PathExpr
&& !static_cast<MetaItemPathExpr &> (**it).get_expr ().is_literal ())
continue;
auto &item = **it;

Attribute attr = (*it)->to_attribute ();
Attribute attr = item.to_attribute ();
if (attr.is_empty ())
{
/* TODO should this be an error that causes us to chuck out
Expand Down
28 changes: 24 additions & 4 deletions gcc/rust/ast/rust-ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "rust-location.h"
#include "rust-diagnostics.h"
#include "rust-keyword-values.h"
#include "rust-cloneable.h"

namespace Rust {
// TODO: remove typedefs and make actual types for these
Expand Down Expand Up @@ -565,9 +566,8 @@ struct Visibility

// aka Attr
// Attribute AST representation
struct Attribute
class Attribute : public Visitable
{
private:
SimplePath path;

// bool has_attr_input;
Expand All @@ -577,6 +577,8 @@ struct Attribute

bool inner_attribute;

NodeId node_id;

// TODO: maybe a variable storing whether attr input is parsed or not

public:
Expand All @@ -587,7 +589,8 @@ struct Attribute
Attribute (SimplePath path, std::unique_ptr<AttrInput> input,
location_t locus = UNDEF_LOCATION, bool inner_attribute = false)
: path (std::move (path)), attr_input (std::move (input)), locus (locus),
inner_attribute (inner_attribute)
inner_attribute (inner_attribute),
node_id (Analysis::Mappings::get ().get_next_node_id ())
{}

bool is_derive () const;
Expand Down Expand Up @@ -685,11 +688,13 @@ struct Attribute

bool is_inner_attribute () const { return inner_attribute; }

// no visitor pattern as not currently polymorphic
void accept_vis (ASTVisitor &vis) override;

const SimplePath &get_path () const { return path; }
SimplePath &get_path () { return path; }

NodeId get_node_id () { return node_id; }

// Call to parse attribute body to meta item syntax.
void parse_attr_to_meta_item ();

Expand Down Expand Up @@ -719,6 +724,7 @@ class AttrInput : public Visitable
public:
enum AttrInputType
{
EXPR,
LITERAL,
MACRO,
META_ITEM,
Expand Down Expand Up @@ -2117,6 +2123,7 @@ struct Crate final : public GlobContainer
}

void inject_extern_crate (std::string name);
void inject_inner_attribute (Attribute attribute);

NodeId get_node_id () const { return node_id; }
const std::vector<Attribute> &get_inner_attrs () const { return inner_attrs; }
Expand All @@ -2139,6 +2146,19 @@ struct Crate final : public GlobContainer
};

} // namespace AST

template <> struct CloneableDelegate<std::unique_ptr<AST::Pattern>>
{
static std::unique_ptr<AST::Pattern>
clone (const std::unique_ptr<AST::Pattern> &other)
{
if (other == nullptr)
return nullptr;
else
return other->clone_pattern ();
}
};

} // namespace Rust

namespace std {
Expand Down
41 changes: 41 additions & 0 deletions gcc/rust/ast/rust-expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,47 @@ class AttrInputLiteral : public AttrInput
}
};

class AttrInputExpr : public AttrInput
{
std::unique_ptr<Expr> expr;

public:
AttrInputExpr (std::unique_ptr<Expr> expr) : expr (std::move (expr)) {}

AttrInputExpr (const AttrInputExpr &oth);

AttrInputExpr (AttrInputExpr &&oth) : expr (std::move (oth.expr)) {}

AttrInputType get_attr_input_type () const final override
{
return AttrInput::AttrInputType::EXPR;
}

AttrInputExpr &operator= (const AttrInputExpr &oth);

AttrInputExpr &operator= (AttrInputExpr &&oth)
{
expr = std::move (oth.expr);
return *this;
}

std::string as_string () const override;

void accept_vis (ASTVisitor &vis) override;

bool check_cfg_predicate (const Session &) const override { return false; }

// assuming this is like AttrInputLiteral
bool is_meta_item () const override { return false; }

Expr &get_expr () { return *expr; }

AttrInputExpr *clone_attr_input_impl () const override
{
return new AttrInputExpr (*this);
}
};

// Like an AttrInputLiteral, but stores a MacroInvocation
class AttrInputMacro : public AttrInput
{
Expand Down
Loading