We can endup with duplicate symbol names for different intrinsics with our
current hash setup. This adds in the mappings and extra info to improve
hash uniqueness.
Addresses #1895
gcc/rust/ChangeLog:
* backend/rust-compile-intrinsic.cc (check_for_cached_intrinsic):
simplify this cached intrinsic check
* backend/rust-mangle.cc (legacy_mangle_item): use new interface
* typecheck/rust-tyty.h: new managle helper
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
We do extra checking after the fact here to ensure its a valid candidate
and in the case there is only one candidate lets just go for it.
Addresses #1895
gcc/rust/ChangeLog:
* backend/rust-compile-base.cc (HIRCompileBase::resolve_method_address):
use the single candidate
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
We hit an assertion with range based iterators here. This code was used
to solve complex generics such as:
struct Foo<X,Y>(X,Y);
impl<T> Foo<T, i32> {
fn test<Y>(self, a: Y) { }
}
The impl item will have the signiture of:
fn test<T,Y> (Foo<T, i32> self, a:Y)
So in the case where we have:
let a = Foo(123f32, 456);
a.test<bool>(true);
We need to solve the generic argument T from the impl block by infering the
arguments there and applying them so that when we apply the generic
argument bool we dont end up in the case of missing number of generics.
Addresses #1895
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): remove hack
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
This avoids a use-after-free when reaching the recursion limit.
gcc/rust/ChangeLog:
* expand/rust-macro-expand.h: Keep optional references for last_def
and last_invoc.
* expand/rust-macro-expand.cc (MacroExpander::expand_invoc): Store
optional references.
* rust-session-manager.cc (Session::expansion): Use tl::optional's APIs
for better checking.
Adjust the HIR dump for IfExpr and IfExprConseqElse
to use visit_field() and factor common part.
gcc/rust/ChangeLog:
* hir/rust-hir-dump.h (do_ifexpr): New.
* hir/rust-hir-dump.cc (Dump::do_ifexpr): New.
(Dump::visit): Use do_ifexpr and visit_field
Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Added errorcodes according to different conditions
and updated error message according to type casting
type.
gcc/rust/ChangeLog:
* typecheck/rust-casts.cc (TypeCastRules::emit_cast_error):
Refactored ErrorCodes & error messages.
gcc/testsuite/ChangeLog:
* rust/compile/bad_as_bool_char.rs:
Updated comment to pass test case.
* rust/compile/cast1.rs: likewise.
* rust/compile/cast4.rs: likewise.
* rust/compile/cast5.rs: likewise.
* rust/compile/all-cast.rs: New test for all error codes.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Added error code support for invalid ABI.
gcc/rust/ChangeLog:
* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_qualifiers):
called error function.
(ASTLoweringBase::lower_extern_block): likewise.
gcc/testsuite/ChangeLog:
* rust/compile/abi-options1.rs: updated comment for testcase.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
type must be known at compile time.
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check.cc (TypeResolution::Resolve):
added errorcode.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
This semicolon produces several warning in each TU the header file is
included in.
gcc/rust/ChangeLog:
* util/rust-common.h (enum_to_str): Remove extra semicolon after
the function.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/ChangeLog:
* checks/errors/rust-const-checker.cc (ConstChecker::visit):
Use of mutable reference in constant functions.
* checks/errors/rust-feature-gate.cc (FeatureGate::gate):
ErrorCode for intrinsics are subject to change.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
gcc/testsuite/ChangeLog:
* rust/compile/name_resolution6.rs: New test.
* rust/compile/name_resolution7.rs: New test.
* rust/compile/name_resolution8.rs: New test.
* rust/compile/name_resolution9.rs: New test.
This visitor takes care of resolving macro invocations, procedural macros
and imports - it is used in conjunction with the `TopLevel` pass and
the macro expander.
gcc/rust/ChangeLog:
* Make-lang.in: Add new object file.
* resolve/rust-early-name-resolver-2.0.cc: New file.
* resolve/rust-early-name-resolver-2.0.h: New file.
Refactored error message to print more
userfriendly message and added error
code.
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit):
refactored message and called error function.
gcc/testsuite/ChangeLog:
* rust/compile/undeclared_label.rs: New test for E0426.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Added ErrorCode support for use of unknown
feature.
gcc/rust/ChangeLog:
* checks/errors/rust-feature-gate.cc (FeatureGate::check):
errorcode support for unknown feature.
gcc/testsuite/ChangeLog:
* rust/compile/feature.rs: Added new unknown feature.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
When the load_file_bytes() fails to open the file, it emits an error but
returns an empty vector (as if the file is empty).
Instead, return a tl::optional nullopt in case of error and an empty
vector in case of an empty file.
fixes#2421
gcc/rust/ChangeLog:
* expand/rust-macro-builtins.cc
(load_file_bytes): Return a tl::optional.
(MacroBuiltin::include_byte_handler): Adjust and check file was
correctly opened.
(MacroBuiltin::include_str_handler): Likewise.
gcc/testsuite/ChangeLog:
* rust/compile/empty_file: New file.
* rust/compile/issue-2421_str.rs: New test.
Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
The DefaultResolver class provides a visitor framework for all three resolvers
in the new name resolution algorithm, with things such as scoping or visiting
sub items.
gcc/rust/ChangeLog:
* Make-lang.in: Add new object file.
* resolve/rust-default-resolver.cc: New file.
* resolve/rust-default-resolver.h: New file.
The `TopLevel` pass takes care of collecting definitions, placing them
in the proper namespaces, and making them accessible for later resolution
passes like `Early` and `Late`. It is meant to be run in a fixed point
fashion, as import resolution, macro resolution and macro expansion
may generate multiple new definitions.
gcc/rust/ChangeLog:
* Make-lang.in: Add new object file.
* resolve/rust-toplevel-name-resolver-2.0.cc: New file.
* resolve/rust-toplevel-name-resolver-2.0.h: New file.
This commit adds a first simple `NameResolutionContext` data structure, which will
be used by all passes of the name resolution to store definitions and access
them. Namely, it contains a few instances of `ForeverStack`, for each
namespace we will be using.
gcc/rust/ChangeLog:
* Make-lang.in: Add new object file.
* resolve/rust-name-resolution-context.cc: New file.
* resolve/rust-name-resolution-context.h: New file.