Owen Avery [Wed, 16 Oct 2024 03:16:23 +0000 (23:16 -0400)]
gccrs: Disambiguate generic args during name resolution 2.0
gcc/rust/ChangeLog:
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Visit GenericArgs and GenericArg, the former
because the latter involves a non-virtual member function call.
* resolve/rust-late-name-resolver-2.0.h
(Late::visit): Likewise.
* backend/rust-compile-asm.cc (CompileAsm::asm_construct_inputs):
Provide input operand for gccrs
* expand/rust-macro-builtins-asm.cc (parse_reg_operand_in):
Move expr to In
(expand_inline_asm_strings):
Add comments to debug strings
gcc/testsuite/ChangeLog:
* rust/compile/inline_asm_parse_operand.rs:
Remove inout, functionality not supported. Remove redundant {}
* rust/execute/torture/inline_asm_mov_x_5_ARM.rs: Add operand in
* rust/execute/torture/inline_asm_mov_x_5_x86_64.rs: Likewise
Owen Avery [Tue, 15 Oct 2024 02:07:54 +0000 (22:07 -0400)]
gccrs: Allow identifiers and paths to reference types during nr2.0
gcc/rust/ChangeLog:
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Allow IdentifierExpr and PathInExpression to
reference types as well as values, remove ability for
IdentifierExpr to reference labels.
Owen Avery [Fri, 11 Oct 2024 05:24:14 +0000 (01:24 -0400)]
gccrs: Insert static items into the value namespace
gcc/rust/ChangeLog:
* backend/rust-compile-item.cc
(CompileItem::visit): Check canonical path of StaticItem
properly when name resolution 2.0 is enabled.
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Insert static items into the value namespace.
Owen Avery [Fri, 11 Oct 2024 01:24:50 +0000 (21:24 -0400)]
gccrs: Rework InlineAsmOperand
Not thrilled with some of this boilerplate, but it does seem like an
improvement.
gcc/rust/ChangeLog:
* ast/rust-expr.h
(InlineAsmOperand): Replace multiple mutually-exclusive tl::optional
fields with a std::unique_ptr and modify nested classes to allow
this. Also, make getters return references where possible.
* expand/rust-macro-builtins-asm.cc
(parse_reg_operand_out): Pass location when constructing
InlineAsmOperand.
Owen Avery [Wed, 9 Oct 2024 03:29:27 +0000 (23:29 -0400)]
gccrs: Fix some issues with canonical path fetching in name resolution 2.0
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-enumitem.cc: Add includes.
(TypeCheckEnumItem::visit): Fetch canonical paths properly when
name resolution 2.0 is enabled.
* typecheck/rust-hir-type-check-implitem.cc: Add includes.
(TypeCheckImplItem::visit): Fetch canonical paths properly when
name resolution 2.0 is enabled.
* typecheck/rust-hir-type-check-item.cc: Add include.
(TypeCheckItem::visit): Fetch canonical paths properly when name
resolution 2.0 is enabled.
Philip Herron [Wed, 2 Oct 2024 14:47:33 +0000 (15:47 +0100)]
gccrs: Fix ICE when typechecking non-trait item when we expect one
We just had an assertion here for this case where we expect a trait.
This changes the assertion into error handling producing the correct
error code with fixit suggestion like rustc.
Fixes #2499
gcc/rust/ChangeLog:
* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_path_to_trait):
use error handling instead of assertion
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): reuse trait reference
* typecheck/rust-hir-type-check-item.h: update prototype
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-2499.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Thu, 19 Sep 2024 15:45:54 +0000 (16:45 +0100)]
rust: Add support for Clone and Copy derive on generic types
When we generate derivations for Copy and Clone we need to make sure
the associated impl block sets up the generic parameters and arguments
correctly. This patch introduces the framework to copy chunks of the AST
because we need to make sure these new AST nodes have their own associated
id, calling clone on the nodes will just confuse name-resolution and
subsequent mappings.
Fixes #3139
gcc/rust/ChangeLog:
* Make-lang.in: new objects
* ast/rust-ast-builder.cc (Builder::generic_type_path_segment): new helper
(Builder::single_generic_type_path): likewise
(Builder::new_type): likewise
(Builder::new_lifetime_param): likewise
(Builder::new_type_param): likewise
(Builder::new_lifetime): likewise
(Builder::new_generic_args): likewise
* ast/rust-ast-builder.h: new helper decls
* ast/rust-ast.h: new const getters
* ast/rust-path.h: likewise
* ast/rust-type.h: likewise
* expand/rust-derive-clone.cc (DeriveClone::clone_impl): take the types generics
(DeriveClone::visit_tuple): likewise
(DeriveClone::visit_struct): likewise
(DeriveClone::visit_union): likewise
* expand/rust-derive-clone.h: update header
* expand/rust-derive-copy.cc (DeriveCopy::copy_impl): similarly take type generics
(DeriveCopy::visit_struct): likewise
(DeriveCopy::visit_tuple): likewise
(DeriveCopy::visit_enum): likewise
(DeriveCopy::visit_union): likewise
* expand/rust-derive-copy.h: likewse
* ast/rust-ast-builder-type.cc: New file.
* ast/rust-ast-builder-type.h: New file.
gcc/testsuite/ChangeLog:
* rust/compile/issue-3139-1.rs: New test.
* rust/compile/issue-3139-2.rs: New test.
* rust/compile/issue-3139-3.rs: New test.
* rust/compile/nr2/exclude: these all break nr2
Box definition is part of the standard library and cannot be found during
name resolution. This simple definition prevent any error from being
emitted.
gcc/testsuite/ChangeLog:
* rust/compile/box_syntax_feature_gate.rs: Add box land item
definition.
It requires the standard library and Copy to work correctly which we
cannot provide. Stopping the compiler before the name resolution allow us
to prevent an error whilst resolving Copy and keep the test's goal.
We want to begin experimenting with this new name resolution 2.0
algorithm as soon as possible. This test highlight a problem where the
compiler should emit an error and should be fixed soon.
gccrs: Loop on expansion if a new export has been defined
When a use statement requires a reexported item it cannot find it in
the same pass, an additional pass shall be performed. This means we need
to detect whether a new item has been reexported and resolve until the
end.
gcc/rust/ChangeLog:
* resolve/rust-early-name-resolver-2.0.cc (Early::Early): Add dirty
flag initialization.
(Early::go): Set dirty flag using top level resolver.
* resolve/rust-early-name-resolver-2.0.h: Add dirty flag.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::TopLevel):
Initialize dirty flag.
(TopLevel::insert_or_error_out): Set dirty flag on successful
namespace modification.
* resolve/rust-toplevel-name-resolver-2.0.h: Add dirty flag.
* rust-session-manager.cc (Session::expansion): Modify fixed point
condition to include name resolution modifications.
When we tried to insert a shadowable node and another shadowable node has
been inserted before, we didn't emit any error if the node has already
been inserted previously and failed silently.
gcc/rust/ChangeLog:
* resolve/rust-rib.cc (Rib::insert): Emit an error when trying to
insert an already inserted node.
Arthur Cohen [Mon, 8 Apr 2024 16:44:15 +0000 (18:44 +0200)]
gccrs: Insert imports in all namespaces they were resolved in
gcc/rust/ChangeLog:
* resolve/rust-early-name-resolver-2.0.cc (Early::resolve_simple_import):
Insert import in all namespaces where they were resolved.
(Early::resolve_rebind_import): Likewise.
* resolve/rust-early-name-resolver-2.0.h: Improve APIs, make them
accept multiple resolutions.
* resolve/rust-finalize-imports-2.0.cc: Handle multiple resolutions.
* resolve/rust-name-resolution-context.h (resolve_path): Remove function.
Arthur Cohen [Fri, 5 Apr 2024 22:32:57 +0000 (00:32 +0200)]
gccrs: imports: Start storing Ribs in ImportKind
gcc/rust/ChangeLog:
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add debug call.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Store
imports using the new classes.
* resolve/rust-toplevel-name-resolver-2.0.h: Use new classes.
Arthur Cohen [Thu, 4 Apr 2024 14:25:30 +0000 (16:25 +0200)]
gccrs: early: Resolve imports and create import mappings
gcc/rust/ChangeLog:
* resolve/rust-early-name-resolver-2.0.cc (Early::resolve_glob_import): New function.
(Early::resolve_simple_import): Likewise.
(Early::resolve_rebind_import): Likewise.
(Early::build_import_mapping): Likewise.
* resolve/rust-early-name-resolver-2.0.h: Add declarations and list of imports to
resolve.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::handle_use_glob): Remove function,
which is now being handled by the Early name resolver.
(TopLevel::handle_use_dec): Likewise.
(TopLevel::handle_rebind): Likewise.
* resolve/rust-toplevel-name-resolver-2.0.h: Likewise, and add functions for creating
import list and fetching it.
Philip Herron [Fri, 20 Sep 2024 17:45:12 +0000 (18:45 +0100)]
rust: fix ICE when compiling impl block for !
We need to resolve the never type which is its own special AST node so it
doesnt magically get handled like the regular builtin type paths such as
i32.
Fixes #3035
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-type.cc (ResolveType::visit):
handle never type
(ResolveTypeToCanonicalPath::visit): likewise
* resolve/rust-ast-resolve-type.h: missing never type
* resolve/rust-name-resolver.cc (Resolver::generate_builtins):
track never type node_id
(Resolver::setup_builtin): likewise
* resolve/rust-name-resolver.h: new never type getter
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-3035.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gccrs: Remove some overloaded methods from DefaultResolver.
gcc/rust/ChangeLog:
* resolve/rust-default-resolver.cc
(DefaultResolver::visit): Remove some empty overloads which
DefaultASTVisitor::visit should be able to handle.
* resolve/rust-default-resolver.h
(DefaultResolver::visit): Likewise.
gccrs: Create new test system for name resolution 2.0
This runs the standard compile/**.rs tests
with name resolution 2.0 enabled. The exclude file
can be used to exclude tests which are not yet working
with name resolution 2.0.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/compile.exp: New test.
* rust/compile/nr2/exclude: New.
gccrs: [gccrs#3141] Fix incorrect handling of overflow in numeric types
Fixes gccrs#3141.
gcc/rust/ChangeLog:
* backend/rust-compile-expr.cc: Fix range checking for both integers and floats.
* hir/tree/rust-hir-expr.h: Add "negative_number" boolean to LiteralExpr class.
gcc/testsuite/ChangeLog:
* rust/compile/issue-3141.rs: New test.
Signed-off-by: Joan Vilardaga <github-91yu@joanvc.cat>
Throw an error when auto-traits used without feature attribute.
gcc/rust/ChangeLog:
* checks/errors/rust-feature-gate.cc (FeatureGate::visit): Emit error
on trait when auto field member true.
* checks/errors/rust-feature-gate.h: add prototype of trait visitor.
* checks/errors/rust-feature.cc (Feature::create): add
optin_builtin_traits in match of feature.
gcc/testsuite/ChangeLog:
* rust/compile/auto_trait_super_trait.rs: Add feature attribute.
* rust/compile/generic_auto_trait.rs: likewise.
* rust/compile/auto_trait.rs: add test for error without
feature attribute
Liam Naddell [Thu, 8 Aug 2024 09:31:58 +0000 (05:31 -0400)]
gccrs: Dynamic dispatch with supertraits
gcc/rust/ChangeLog:
* backend/rust-compile.cc:
Modify compute_address_for_trait_item to support supertraits
* typecheck/rust-tyty.cc:
Remove auto
gcc/testsuite/ChangeLog:
* rust/compile/trait13.rs:
Add test for supertraits of supertraits
* rust/compile/trait14.rs:
Diamond problem with supertraits test
* rust/execute/torture/trait14.rs:
Add test for dynamic dispatch with supertraits
* rust/execute/torture/trait15.rs:
Add test for dynamic dispatch with generics
* rust/execute/torture/trait16.rs:
Add test for dynamic dispatch with lifetime params 1
* rust/execute/torture/trait17.rs:
Add test for dynamic dispatch with lifetime params 2
* rust/execute/torture/trait18.rs:
Add test for default implementations with dynamic dispatch and
supertraits
Kushal Pal [Wed, 28 Aug 2024 06:39:28 +0000 (06:39 +0000)]
gccrs: Used `IndexVec` for place_map
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Use strong
type instead of size_t.
(Dump::visit_place): Likewise.
(Dump::visit_scope): Likewise.
* checks/errors/borrowck/rust-bir-dump.h (class Dump): Use
IndeVec for place_map.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Wed, 28 Aug 2024 06:16:11 +0000 (06:16 +0000)]
gccrs: Use `IndexVec` for bb_fold_map
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-dump.cc (simplify_cfg):
Used `IndexVec` for bb_fold_map.
(Dump::go): Use strong type as index instead of value as now we
are using `IndexVec`.
(Dump::visit): Likewise.
* checks/errors/borrowck/rust-bir-dump.h (class Dump): Use
`IndexVec` for bb_fold_map.
* checks/errors/borrowck/rust-bir-place.h: Add constructor for
`IndexVec` that can reserve size.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Mon, 19 Aug 2024 10:06:49 +0000 (10:06 +0000)]
gccrs: Used `IndexVec` for BasicBlocks
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
(ExprStmtBuilder::visit): Use strong type as index and
remove access to numeric value.
* checks/errors/borrowck/rust-bir-builder-internal.h
(struct BuilderContext): Likewise.
* checks/errors/borrowck/rust-bir-dump.cc (simplify_cfg):
Likewise.
(Dump::go): Likewise.
(Dump::visit): Likewise.
* checks/errors/borrowck/rust-bir-fact-collector.h
(class FactCollector): Likewise.
(points): Likewise.
* checks/errors/borrowck/rust-bir.h (struct BasicBlockId): Used
IndexVec for BasicBlocks.
(struct Function): Likewise.
* checks/errors/borrowck/rust-borrow-checker-diagnostics.cc
(BorrowCheckerDiagnostics::get_statement): Change the extracted
index to strong type.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Mon, 19 Aug 2024 09:48:49 +0000 (09:48 +0000)]
gccrs: Used `IndexVec` for Loans
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-place.h: Used `IndexVec` with
ScopeId as index.
* checks/errors/borrowck/rust-borrow-checker-diagnostics.cc
(BorrowCheckerDiagnostics::get_loan): Convert Polonius::Loan to
BIR::Loan, so we can use it as index.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Mon, 19 Aug 2024 09:28:25 +0000 (09:28 +0000)]
gccrs: Introduce `IndexVec`
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-place.h (struct Loan):
Introduce new class `IndexVec` inspired from IndexVec of rust.
It acts as a wrapper around `std::vector` and lets user specify
a strong type to use as index.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Wed, 7 Aug 2024 10:58:17 +0000 (10:58 +0000)]
gccrs: Strong type BasicBlockId
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit):
Use value of BasicBlockId as index.
* checks/errors/borrowck/rust-bir-builder-internal.h (struct BuilderContext):
Likewise.
* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h:
Initialize with ENTRY_BASIC_BLOCK.
* checks/errors/borrowck/rust-bir-dump.cc (simplify_cfg):
Use value of BasicBlockId as index.
(Dump::go): Likewise.
(Dump::visit): Likewise.
* checks/errors/borrowck/rust-bir-fact-collector.h (class FactCollector):
Initialize with ENTRY_BASIC_BLOCK.
(points): Use value of BasicBlockId as index.
* checks/errors/borrowck/rust-bir.h (struct BasicBlockId):
BasicBlockId is a struct now.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Wed, 7 Aug 2024 10:16:24 +0000 (10:16 +0000)]
gccrs: Strong type ScopeId
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
(ExprStmtBuilder::setup_loop): Use value of ScopeId.
(ExprStmtBuilder::visit): Use continue scope id instead of
continue basic block id.
* checks/errors/borrowck/rust-bir-builder-internal.h: Use value
of ScopeId.
* checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Use
ROOT_VALUE instead of hardcoded 0.
(Dump::visit_scope): Use value of ScopeId.
* checks/errors/borrowck/rust-bir-place.h (struct ScopeId):
ScopeId is now a struct.
(std::numeric_limits::max): Set invalid ScopeId.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Wed, 7 Aug 2024 08:44:03 +0000 (08:44 +0000)]
gccrs: Strong type LoanId
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-dump.cc (Dump::visit): Use new
API, i.e get_loan_id() instead of get_loan().
* checks/errors/borrowck/rust-bir-fact-collector.h (points): Use
value of LoanId in Polonius facts.
* checks/errors/borrowck/rust-bir-place.h (struct LoanId):
LoanId is a struct now.
* checks/errors/borrowck/rust-bir.h (class AbstractExpr): Use
new API, as we are getting a LoanId and not a loan itself.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Thu, 8 Aug 2024 07:12:00 +0000 (07:12 +0000)]
gccrs: Use FreeRegions inplace of `std::vector<FreeRegion>`
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-builder-internal.h: Use
FreeRegions instead of making a temporary vector of FreeRegion.
* checks/errors/borrowck/rust-bir-builder.h: Likewise.
* checks/errors/borrowck/rust-bir-fact-collector.h (class FactCollector):
Likewise.
(points): Likewise.
* checks/errors/borrowck/rust-bir-free-region.h: Remove obsolete
set_from() helpers, add push_back().
* checks/errors/borrowck/rust-bir-place.h: Use FreeRegions
instead of making a temporary vector of Origin.
* typecheck/rust-tyty-variance-analysis-private.h: Change type
of `regions`.
* typecheck/rust-tyty-variance-analysis.cc (CrateCtx::query_type_regions):
Use new type.
(GenericTyPerCrateCtx::query_generic_variance): Likewise.
(TyVisitorCtx::add_constraints_from_generic_args): Likewise.
(FieldVisitorCtx::add_constraints_from_region): Likewise.
(FieldVisitorCtx::add_constrints_from_param): Likewise.
* typecheck/rust-tyty-variance-analysis.h: Likewise.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Wed, 7 Aug 2024 05:19:28 +0000 (05:19 +0000)]
gccrs: Strong type FreeRegion
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-builder-internal.h: Use
STATIC_FREE_REGION, use value of FreeRegion for origin.
* checks/errors/borrowck/rust-bir-builder.h: Use free region
value.
* checks/errors/borrowck/rust-bir-dump.cc (Dump::visit_scope):
Likewise.
* checks/errors/borrowck/rust-bir-fact-collector.h (points):
Likewise.
* checks/errors/borrowck/rust-bir-free-region.h (struct FreeRegion):
Make FreeRegion a struct.
* checks/errors/borrowck/rust-bir-place.h: Use FreeRegion
instead of Origin in PlaceDB.
* typecheck/rust-tyty-variance-analysis.cc (FieldVisitorCtx::add_constraints_from_region):
Use value of FreeRegion for origin.
(FieldVisitorCtx::add_constrints_from_param): Likewise.
(Term::make_transform): Likewise.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Mon, 5 Aug 2024 10:50:55 +0000 (10:50 +0000)]
gccrs: Strong type PlaceId
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-dump.cc (renumber_places):
Use value of PlaceId as index.
(Dump::visit_place): Likewise.
(Dump::visit_scope): Likewise.
(Dump::go): Refill `place_map` with for loop instead of
using std::iota().
* checks/errors/borrowck/rust-bir-fact-collector.h (points): Use
value as index.
* checks/errors/borrowck/rust-bir-place.h (struct PlaceId):
PlaceId is now a class holding a uint32_t value. Overloaded
comparision operators for easier comparision.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
badumbatish [Thu, 8 Aug 2024 21:22:05 +0000 (14:22 -0700)]
gccrs: Use's array type when constring string tree
gcc/rust/ChangeLog:
* backend/rust-compile-asm.cc (CompileAsm::asm_build_expr):
Use's array type when constring string tree
(CompileAsm::asm_construct_string_tree):
Use's array type when constring string tree
badumbatish [Thu, 1 Aug 2024 23:22:32 +0000 (16:22 -0700)]
gccrs: Perform lowering hir output operand to tree
gcc/rust/ChangeLog:
* backend/rust-compile-asm.cc (CompileAsm::asm_build_expr):
Add debug comment
(CompileAsm::asm_construct_outputs):
Perform lowering hir output operand to tree
* backend/rust-compile-asm.cc (CompileAsm::asm_construct_outputs):
Lower the HIR to tree with CompileExpr
* backend/rust-compile-asm.h: Remove static from method
* expand/rust-macro-builtins-asm.cc (parse_reg_operand):
Remove warnings
(parse_reg_operand_out): Remove warnings
(expand_inline_asm): New function for eventual expansion
(parse_asm): Use expand_inline_asm
gcc/testsuite/ChangeLog:
* rust/execute/torture/inline_asm_mov_x_5.rs: New test.