Muhammad Mahad [Tue, 15 Aug 2023 16:29:03 +0000 (21:29 +0500)]
gccrs: [E0391] Detected type dependency cycle
This errorcode & message emits when cycle
detected when computing the super predicates
of `x` which requires computing the super
predicates of `y`, which again requires
computing the super predicates of `x`,
completing the cycle.
gcc/rust/ChangeLog:
* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait):
Updated errorcode & more userfriendly message.
gcc/testsuite/ChangeLog:
* rust/compile/issue-1589.rs: Updated comment for dejagnu.
* rust/compile/trait-cycle.rs: New relevant test.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Muhammad Mahad [Wed, 16 Aug 2023 12:40:09 +0000 (17:40 +0500)]
gccrs: [E0164] Neither tuple struct nor tuple variant used as a pattern
Checking if pattern has items, before returing solves ICE.
Added error code and rich location.
Also, fixes https://github.com/Rust-GCC/gccrs/issues/2430
gcc/rust/ChangeLog:
* ast/rust-pattern.h: No need of assertion, we are handling it.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
Added check which emits error instead of using assertion.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Added rich location and error code.
gcc/testsuite/ChangeLog:
* rust/compile/match5.rs:
Updated comment for dejagnu.
* rust/compile/pattern-struct.rs: New test for ICE.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Muhammad Mahad [Thu, 10 Aug 2023 17:10:09 +0000 (22:10 +0500)]
gccrs: Support for rich-loc & errorcode in parser error
Added method of binding ErrorCode & rich location to
parser and expansion errors.
Fixes https://github.com/Rust-GCC/gccrs/issues/2385
gcc/rust/ChangeLog:
* rust-diagnostics.cc (va_constructor):
Added constructor for all possible cases.
(Error::Error): Updated error struct
for all possible cases.
* rust-diagnostics.h (struct Error):
Updated error struct to support error
code & rich location support.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Arthur Cohen [Thu, 3 Aug 2023 14:40:07 +0000 (16:40 +0200)]
gccrs: diagnostics: Fix mismatch between new[] and free
We cannot use `free` on a pointer allocated through `new[]`, and this
causes an ASAN failure. This fixes it by using `xcalloc` instead of
`new[]` when creating description buffers for our error codes.
gcc/rust/ChangeLog:
* rust-diagnostics.cc: Switch from new[] to xcalloc
Philip Herron [Sat, 12 Aug 2023 17:18:51 +0000 (18:18 +0100)]
gccrs: improve name mangling hash
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 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.
Arthur Cohen [Thu, 3 Aug 2023 15:24:14 +0000 (17:24 +0200)]
gccrs: macro-expand: Keep optional references to last_{def, invoc}
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.
* 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>
Muhammad Mahad [Tue, 8 Aug 2023 19:27:08 +0000 (00:27 +0500)]
gccrs: [E0658] Unstable langauge feature
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>
Arthur Cohen [Thu, 27 Jul 2023 08:06:37 +0000 (10:06 +0200)]
gccrs: nr2.0: Add complex macro name resolution test cases
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.
Arthur Cohen [Thu, 27 Jul 2023 08:06:13 +0000 (10:06 +0200)]
gccrs: nr2.0: Add Early name resolution visitor
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.
Arthur Cohen [Thu, 20 Jul 2023 15:52:14 +0000 (17:52 +0200)]
gccrs: forever stack: Add path resolution
gcc/rust/ChangeLog:
* resolve/rust-forever-stack.h
(insert_at_root): New method.
(resolve_path): New method.
(reverse_iter): Iterate on `Node`s instead of `Rib`s
* resolve/rust-forever-stack.hxx: Add path resolution.
Muhammad Mahad [Wed, 2 Aug 2023 11:21:15 +0000 (16:21 +0500)]
gccrs: [E0308] mismatch types on assignment
This errorcode emits when there are
mismatch types between lhs & rhs of
assignment operator & refactored
message. This error code was used
in many test cases, so updated the
error comments.
gcc/rust/ChangeLog:
* typecheck/rust-unify.cc (UnifyRules::emit_type_mismatch):
refactored & called error function.
Arthur Cohen [Thu, 20 Jul 2023 13:14:54 +0000 (15:14 +0200)]
gccrs: nr2.0: Add DefaultResolver visitor
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.
Arthur Cohen [Thu, 20 Jul 2023 12:15:14 +0000 (14:15 +0200)]
gccrs: top-level: Add base `TopLevel` visitor
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.
Arthur Cohen [Fri, 23 Jun 2023 14:17:51 +0000 (16:17 +0200)]
gccrs: name resolution 2.0: Add base for our context data structure
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.
Philip Herron [Sun, 30 Jul 2023 17:59:06 +0000 (18:59 +0100)]
gccrs: Fix ICE by adding check for enum candidate's in TypePath resolution
Fixes #2479
gcc/rust/ChangeLog:
* typecheck/rust-hir-trait-resolve.cc (TraitItemReference::resolve_item):
always resolve the type even when its an a mandatory trait item
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path):
Add check for enum candidates otherwise you get undefined behaviour
gcc/testsuite/ChangeLog:
* rust/compile/issue-2479.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Tue, 18 Jul 2023 16:46:08 +0000 (17:46 +0100)]
gccrs: Begin enforcing Sized properly and support anti traits like ?Sized
Sized is implicitly applied to every generic type parameter apart from the
implicit Self type parameter on traits, as that would cause a recursive
bound and would make Traits unable to be appied to unsized types.
In order to keep everything happy this means we also need to support the
anti trait bound '?' so that Sized can be removed properly. The full Sized
rules are not completely implemented here. Slice's and Str's are currently
marked as Sized but there is a small regression here that looks like a more
general bug which should be fixed on its own as part of #2443. There is
a big testsuite update here to pull in the Sized lang item.
Note this lays the bound's ground work so we can start supporting Drop
trait properly which needs tackled very soon.
Philip Herron [Tue, 18 Jul 2023 11:12:22 +0000 (12:12 +0100)]
gccrs: Track trait bound polarity properly
Trait bounds can have three forms in Rust the regular trait bound, '!' the
negative trait bound to enforice that this trait must not be implmented and
'?' the anti trait bound to remove this bound. This patch extends our
Polarity enum to include the Anti trait bound and updates the HIR lowering
code to track this properly.
Addresses #2443
gcc/rust/ChangeLog:
* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): use new BoundPolarity enum
* hir/rust-ast-lower-type.cc (ASTLoweringTypeBounds::visit): likewise
* hir/rust-hir-dump.cc (BoundPolarityString): new helper
(Dump::visit): update hir dump
* hir/tree/rust-hir-item.h (class ImplBlock): likewise
* hir/tree/rust-hir-type.h (class TraitBound): likewise
* hir/tree/rust-hir.cc (TraitBound::as_string): fix as string
* util/rust-common.h (enum Polarity): add new anti bound
(enum BoundPolarity): likewise
* util/rust-hir-map.cc (Mappings::Mappings): update naming
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
The function to get a literal from a string missed an implementation.
It did require a conversion function to achieve it, now that callback
system has been merged this function can be easily implemented.
* libproc_macro/literal.cc (Literal__from_string): Add
implementation with call to constructor.
(Literal::make_literal): Add new constructor which calls the
callback.
* libproc_macro/literal.h: Add new constructor's
prototype.
* libproc_macro/proc_macro.cc (bridge_is_available):
Change symbol name to match convention.
* libproc_macro/registration.h: Add lit_from_str
symbol.
* libproc_macro/tokenstream.cc (TokenStream::make_tokenstream):
Change symbol name to disambiguate with literal from string.
The literal conversion code could be used for the literal_from_string
callback, this means we should move it out of the function in it's own
function. This involves a new switch, which is quite sad but we're not
yet at a performance profiling phase, there may be lower hanging fruits.
gcc/rust/ChangeLog:
* util/rust-token-converter.cc (handle_suffix): Rework function
to make it work with the new literal conversion function.
(convert_literal): Add a new function to convert to a proc macro
literal from a literal tokenptr. The function will abort if the
pointer does not point to a literal.
(convert): Add call to convert literal for every literal case.
* util/rust-token-converter.h (convert_literal): Add public
prototype.
Muhammad Mahad [Thu, 27 Jul 2023 16:36:55 +0000 (21:36 +0500)]
gccrs: New Error Code Framework
Updated ErrorCode struct to enum class to enforce proper
error codes, similiar to rustc. For converting the enum
to the respective error code, I used a map and updated
make_description & make_url function accordingly and
also removes the memory leak from the previous frame-
work. Also, added macro to safely convert the enum
number to string.
gcc/rust/ChangeLog:
* backend/rust-compile-intrinsic.cc (Intrinsics::compile):
Formatted according to enum class.
* checks/errors/rust-feature-gate.cc (FeatureGate::gate): likewise.
* checks/errors/rust-unsafe-checker.cc (check_unsafe_call): likewise.
* hir/rust-ast-lower-base.cc (struct_field_name_exists): likewise.
* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): likewise.
* resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path):
likewise.
* resolve/rust-ast-resolve-pattern.cc (PatternDeclaration::go): likewise.
(PatternDeclaration::add_new_binding): likewise.
* resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): likewise.
* resolve/rust-ast-verify-assignee.h: likewise.
* rust-diagnostics.cc: updated make_desc & url function for enum class.
* rust-diagnostics.h (struct ErrorCode): removed struct to switch to enum.
(enum class): Switched from errorcode struct to enum class.
(XSTR): Macro for converting enum to string.
(STR): macro Used by XSTR for converting to string.
(ERROR_CODE): macro used by map for check.
(TABLE_TO_MAP): macro used by map for check
* typecheck/rust-casts.cc (TypeCastRules::emit_cast_error):
Formatted according to enum class.
* typecheck/rust-hir-path-probe.h: likewise.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): likewise.
* typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit):
likewise.
(TypeCheckImplItemWithTrait::visit): likewise.
* typecheck/rust-hir-type-check-item.cc: likewise.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): likewise.
(emit_invalid_field_error): likewise.
* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::resolve): likewise.
* typecheck/rust-tyty-call.cc (emit_unexpected_argument_error): likewise.
(TypeCheckCallExpr::visit): likewise.
* typecheck/rust-tyty-subst.cc (SubstitutionRef::get_mappings_from_generic_args):
likewise.
* typecheck/rust-tyty.cc (BaseType::bounds_compatible): likewise.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Add multiple tests to prevent regressions on procedural macros errors
when one is declared outside of the crate's top level.
gcc/testsuite/ChangeLog:
* rust/compile/proc_macro_attribute_non_root_function.rs: New test.
* rust/compile/proc_macro_attribute_non_root_method.rs: New test.
* rust/compile/proc_macro_attribute_non_root_module.rs: New test.
* rust/compile/proc_macro_derive_non_root_function.rs: New test.
* rust/compile/proc_macro_derive_non_root_method.rs: New test.
* rust/compile/proc_macro_derive_non_root_module.rs: New test.
* rust/compile/proc_macro_non_root_function.rs: New test.
* rust/compile/proc_macro_non_root_method.rs: New test.
* rust/compile/proc_macro_non_root_module.rs: New test.
gccrs: Check proc_macro attributes on non root functions
Check proc_macro, proc_macro_attribute and proc_macro_derive attributes
on non root functions, emit an error when one is found.
gcc/rust/ChangeLog:
* util/rust-attributes.cc (check_proc_macro_non_root): Add
function to emit this specific error.
(AttributeChecker::visit): Modify visitor to propagate to some
containers that were not handled correctly.
Initially a typedef was used to easily get the callback function pointer
type. Since this type has changed to a simpler well defined type, this
using declaration has no more purpose.
libgrust/ChangeLog:
* libproc_macro/proc_macro.cc: Remove type alias.
* libproc_macro/registration.h: Likewise.
Add a callback from gcc to determine wether the bridge is available or
not.
gcc/rust/ChangeLog:
* expand/rust-proc-macro.cc (available): Add symbol
registration.
(load_macros_array): Likewise.
libgrust/ChangeLog:
* libproc_macro/proc_macro.cc (not_available): Add a
function to express bridge unavailability.
* libproc_macro/proc_macro.h (not_available): Likewise.
* libproc_macro/registration.h: Add symbol type.
Refactor attribute search with early return. Also fix the optional
building an object with it's default empty constructor by explicitely
using tl::null_opt.
gcc/rust/ChangeLog:
* checks/errors/privacy/rust-privacy-reporter.cc (find_proc_macro_attribute):
Refactor the function to be safer and more efficient.
Refactor proc macro specific privacy check in multiple shorter
functions.
gcc/rust/ChangeLog:
* checks/errors/privacy/rust-privacy-reporter.cc (find_proc_macro_attribute):
Add a new function to find a potential proc macro type
attribute on a given item.
(proc_macro_privacy_check): Move all proc macro privacy check in
their own function to avoid cluttering the usual privacy check.
(PrivacyReporter::go): Add call to newly created proc macro
privacy check function.
gccrs: testsuite: Add tests for pub items in proc_macros
Crates of type 'proc-macro' should not have any other pub member than
procedural macros. These new test will avoid regression on error
messages in such sitation.
gcc/testsuite/ChangeLog:
* rust/compile/proc_macro_pub_function.rs: New test.
* rust/compile/proc_macro_pub_module.rs: New test.
gccrs: testsuite: Replace dg-excess-errors with dg-error
Some test were using dg-excess-errors instead of dg-error, this is now
fixed.
gcc/testsuite/ChangeLog:
* rust/compile/proc_macro_attribute_crate_type.rs: Replace
dg-excess-errors with dg-error and fix the line so the test
can pass.
* rust/compile/proc_macro_crate_type.rs: Likewise.
* rust/compile/proc_macro_derive_crate_type.rs: Likewise.
gccrs: privacy: Add tests for private proc macro error
Add some tests to prevent regression on private procedural macros error
messages.
gcc/testsuite/ChangeLog:
* rust/compile/proc_macro_attribute_private.rs: New test.
* rust/compile/proc_macro_derive_private.rs: New test.
* rust/compile/proc_macro_private.rs: New test.