Add an option to the command line interface to dump the ast back to a
tokenstream.
gcc/rust/ChangeLog:
* rust-session-manager.cc (Session::enable_dump): Enable new
dump.
(Session::compile_crate): CLI argument parsing.
(Session::dump_tokenstream): Dump the tokenstream as a string in
the specified file.
* rust-session-manager.h (struct CompileOptions): Add
tokenstream dump option.
Add an option to output trailing commas depending on the configuration
of the TokenStream.
gcc/rust/ChangeLog:
* ast/rust-ast-tokenstream.cc (TokenStream::trailing_comma):
Output a trailing comma to the token stream according to the
configuration.
* ast/rust-ast-tokenstream.h: Add function prototype.
Add several functions to convert an ast back to a token stream. This may
be used later either to unify the ast dumping and modifications on ast
nodes in procedural macros.
gcc/rust/ChangeLog:
* Make-lang.in: Add rust-as-tokenstream to compile list.
* ast/rust-item.h: Add missing getter for location.
* ast/rust-ast-tokenstream.cc: Add ast visitor implementation.
* ast/rust-ast-tokenstream.h: New file.
* ast/rust-pattern.h: Add getter.
Philip Herron [Wed, 29 Mar 2023 15:28:11 +0000 (16:28 +0100)]
gccrs: handle bare function types with no specified return type
When we have a function with no return type this defaults to (), but we
need to be sure we generate a new implicit HirId for it otherwise it will
end up in a recursive reference chain.
Fixes #2042
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit):
Add implicit unit type as the return type when not specified
gcc/testsuite/ChangeLog:
* rust/compile/issue-2042.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Wed, 29 Mar 2023 14:57:56 +0000 (15:57 +0100)]
gccrs: fix ICE with bad match arm type
We expect to get some kind of ADT or Tuple type when computing this kind of
match arms this adds a new diagnostic to check for this case instead of
an assertion.
Fixes #2029
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): return early on bad type
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::TypeCheckPattern):
remove assertion in favor of check
(TypeCheckPattern::visit): likewise
gcc/testsuite/ChangeLog:
* rust/compile/issue-2029.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
* libproc_macro/rust/bridge.rs: New file.
* libproc_macro/rust/bridge/group.rs: New file.
* libproc_macro/rust/bridge/ident.rs: New file.
* libproc_macro/rust/bridge/literal.rs: New file.
* libproc_macro/rust/bridge/punct.rs: New file.
* libproc_macro/rust/bridge/span.rs: New file.
* libproc_macro/rust/bridge/token_stream.rs: New file.
* libproc_macro/rust/group.rs: New file.
* libproc_macro/rust/ident.rs: New file.
* libproc_macro/rust/lib.rs: New file.
* libproc_macro/rust/literal.rs: New file.
* libproc_macro/rust/punct.rs: New file.
* libproc_macro/rust/span.rs: New file.
* libproc_macro/rust/token_stream.rs: New file.
Arthur Cohen [Tue, 28 Mar 2023 12:22:21 +0000 (14:22 +0200)]
gccrs: privacy: Check for pub(crate) when resolving visibility path.
This causes the function to return true and the checks to pass, but it
requires more thinking - how do we deal with pub(crate) in the current system?
Should we simply treat it as a pub item in the current crate, but export it as
a private item in the metadata?
gcc/rust/ChangeLog:
* ast/rust-item.h: Fix `Visibility::has_path()` implementation.
* checks/errors/privacy/rust-visibility-resolver.cc
(VisibilityResolver::resolve_module_path): Check if we are dealing with pub(crate) properly.
Arthur Cohen [Tue, 28 Mar 2023 11:55:19 +0000 (13:55 +0200)]
gccrs: resolver: Allow SimplePath to resolve to their root segment
SimplePath are allowed to resolve to their root segment even if it is `crate`
or `super` when checking visibilities. We now have to make sure that this
is allowed everywhere a SimplePath is kept.
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): Set
resolved_node_id when visiting root segment of SimplePath.
Arthur Cohen [Tue, 28 Mar 2023 09:34:27 +0000 (11:34 +0200)]
gccrs: ast: Fix location for pub(crate)
When creating a SimplePath from a string, we end up creating a path
which contains only one segment but no location. Take the location of
the one segment instead and use it as the simple path's location.
gcc/rust/ChangeLog:
* ast/rust-ast.h: Call SimplePath constructor differently in
SimplePath::from_str
Arthur Cohen [Tue, 21 Mar 2023 16:37:47 +0000 (17:37 +0100)]
gccrs: expand: Rename AttrVisitor -> CfgStrip
Since the expansion and stripping phase are now separated, it does not
make sense to keep AttrVisitor named AttrVisitor. Furthermore, the visitor
is already very complex, with a heavy mental load (erasing iterators,
rearranging them, performing cfg-expansion, etc) so further attribute
handling should probably happen in rust-attribute-checker.h
gcc/rust/ChangeLog:
* Make-lang.in: Rename rust-asttribute-visitor.o -> rust-cfg-strip.o
* expand/rust-attribute-visitor.cc: Moved to...
* expand/rust-cfg-strip.cc: ...here.
* expand/rust-attribute-visitor.h: Moved to...
* expand/rust-cfg-strip.h: ...here.
* expand/rust-macro-expand.cc: Fix include of rust-attribute-visitor.h
* expand/rust-macro-builtins.cc: Likewise.
* rust-session-manager.cc (Session::expansion): Call CfgStrip instead of
AttrVisitor.
Arthur Cohen [Mon, 20 Mar 2023 03:17:04 +0000 (04:17 +0100)]
gccrs: expand: Add new ExpandVisitor class
This class takes care of actually performing the macro expansion by calling
into the MacroExpander for each node of a given AST, leaving the job of
cfg-stripping nodes to the AttrVisitor.
gcc/rust/ChangeLog:
* Make-lang.in: Add new object file.
* expand/rust-attribute-visitor.cc (AttrVisitor::go): Visit all items of a
crate.
(AttrVisitor::expand_struct_fields): Do not perform macro expansion anymore.
(AttrVisitor::expand_function_params): Likewise.
(AttrVisitor::expand_generic_args): Likewise.
(AttrVisitor::expand_qualified_path_type): Likewise.
(AttrVisitor::expand_self_param): Likewise.
(AttrVisitor::expand_trait_function_decl): Likewise.
(AttrVisitor::expand_trait_method_decl): Likewise.
(AttrVisitor::visit): Likewise.
(AttrVisitor::maybe_expand_expr): Remove function.
(AttrVisitor::maybe_expand_type): Likewise.
* expand/rust-attribute-visitor.h: Do not keep MacroExpander inside AttrVisitor
anymore.
* expand/rust-macro-expand.h (struct MacroExpander): Turn ContextType into an
enum class for more type safety.
* expand/rust-macro-expand.cc (MacroExpander::expand_crate): Use new ContextType
API.
* rust-session-manager.cc (Session::expansion): Call into ExpandVisitor.
* expand/rust-expand-visitor.cc: New file.
* expand/rust-expand-visitor.h: New file.
gcc/testsuite/ChangeLog:
* rust/compile/macro49.rs: New test.
* rust/compile/macro50.rs: New test.
Arthur Cohen [Mon, 20 Mar 2023 02:10:26 +0000 (03:10 +0100)]
gccrs: expand: Move cfg-attrs related functions out of MacroExpander
The current situation where the MacroExpander and AttrVisitor recursively
call into each other is not great, and causes pains for macro imports. We
need to split this pass in two, with one pass being responsible for cfg-attr
checking and stripping, and one being responsible for macro expansion.
gcc/rust/ChangeLog:
* expand/rust-macro-expand.cc (MacroExpander::expand_crate): Do not cfg-attr
strip in MacroExpander
(MacroExpander::fails_cfg): Function moved...
(MacroExpander::fails_cfg_with_expand): Function moved...
(MacroExpander::expand_cfg_attrs): Function moved...
* expand/rust-attribute-visitor.cc (fails_cfg): ...here.
(fails_cfg_with_expand): ...here.
(expand_cfg_attrs): ...here.
(AttrVisitor::expand_struct_fields): Use new functions.
(AttrVisitor::expand_tuple_fields): Likewise.
(AttrVisitor::expand_function_params): Likewise.
(AttrVisitor::visit): Likewise.
(AttrVisitor::go): New function.
* expand/rust-attribute-visitor.h: Declare AttrVisitor::go.
* expand/rust-macro-expand.h (struct MacroExpander): Remove cfg-attr related
functions.
Arthur Cohen [Wed, 15 Mar 2023 16:30:25 +0000 (17:30 +0100)]
gccrs: mappings: Keep exported macro IDs
gcc/rust/ChangeLog:
* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Add new visitor
for AST::MacroRulesDefinition.
* hir/rust-ast-lower-item.h: Declare above mentioned visitor.
* metadata/rust-export-metadata.cc (ExportContext::emit_macro): New function.
* metadata/rust-export-metadata.h: Declare it.
(PublicInterface::gather_export_data): Go through each exported macro.
* util/rust-hir-map.cc (Mappings::insert_exported_macro): New function.
(Mappings::get_exported_macros): New function.
* util/rust-hir-map.h: Add new mappings for exported macros.
Arthur Cohen [Wed, 15 Mar 2023 16:15:39 +0000 (17:15 +0100)]
gccrs: Revert "hir: Add ExportedMacro node and handling."
This reverts commit a1f940d193c6cdb13483690a4f4a7d501ad7040e. It is easier
and cleaner to store exported macros' NodeIds into our mappings rather than
create a new HIR kind of node.
Philip Herron [Fri, 24 Mar 2023 22:17:36 +0000 (22:17 +0000)]
gccrs: Fix ICE on parsing trait object missing dyn keyword
Trait objects are not required to use the 'dyn' keyword though it is
depreciated in later editions/version of Rustc. This patch handles the case
when we query the type for an HIR::Item which happens to be an HIR::Trait
and return a trait object or error.
Fixes #2037
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): return a TraitObject
gcc/testsuite/ChangeLog:
* rust/compile/issue-2037.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Arthur Cohen [Mon, 20 Mar 2023 01:58:55 +0000 (02:58 +0100)]
gccrs: ast: Dump each MacroRule properly without the extra semicolon
Having the extra semicolon causes parsing errors when importing macros
exported using the AST dump, as no rule expects multiple tokens after a
single macro rule definition.
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Remove extraneous semicolon when
dumping macro rules.
Philip Herron [Fri, 17 Mar 2023 22:46:37 +0000 (22:46 +0000)]
gccrs: support use declaration to write the type into the correct namespace
This builds upon the previous path resolution fixes so that it returns the
resolved_node_id or UNKNOWN_NODEID on failure to resolve the use-path.
It then exports the name to the current module namespace so it can be used.
Fixes #850 #855
gcc/rust/ChangeLog:
* ast/rust-ast.h: add const get_final_segment helper
* hir/rust-ast-lower-enumitem.h: dont add an item mapping for enumitems
* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): add enum to enum-items mappings
* hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): likewise
* hir/tree/rust-hir-item.h: add non const helper to get variants
* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): resolve the use declaration
* resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): handle self
* resolve/rust-ast-resolve-toplevel.h: add enum item mappings to module mappings
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path): ensure variant
(TypeCheckExpr::resolve_segments): likewise
* typecheck/rust-type-util.cc (query_type): lookup enum's
* util/rust-hir-map.cc (Mappings::insert_hir_enumitem): enum item mappings
(Mappings::lookup_hir_enumitem): likewise
* util/rust-hir-map.h: likewise
gcc/testsuite/ChangeLog:
* rust/compile/issue-850.rs: New test.
* rust/compile/issue-855.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Fri, 17 Mar 2023 22:46:20 +0000 (22:46 +0000)]
gccrs: Return resolved_node_id when possible
To enable use statement to export a name to a path such as the prelude
example: use option::Option::{self, None, Some} we need to get the resolved
node id of the self, None and Some in order to export the name of None and
Some to their respective NodeId.
Philip Herron [Fri, 17 Mar 2023 18:09:53 +0000 (18:09 +0000)]
gccrs: add new apply_primtiive_type_hint to inference variables
In the senario where you infer types via unify_site_and but choose to not
commit the result you can end up with coercion to infer the result later on
which does not get fully replaced resulting in a stray inference variable
that can be left alone as a general inference variable leading to missing
type context info. This patch gives support to add type hints to inference
variables so they can be defaulted correctly in more complex cases. The
old system relied on the unification result commiting and overriding the
inference variables so they dissapear out of the current typeing context.
This was needed to fix #1981 where it is valid to inject inference
variables here. This lead to a regression in a few of the complex generic
trait test cases such as execute/torture/traits9.rs which had the wrong
argument type and defaulted wrongly to i32 instead of isize.
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::resolve_literal): fix ctor
* typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit): likewise
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): likewise
* typecheck/rust-typecheck-context.cc (TypeCheckContext::push_new_loop_context): likewise
* typecheck/rust-tyty-util.cc (TyVar::get_implicit_infer_var): likewise
* typecheck/rust-tyty.cc (InferType::InferType): new ctor with type hint
(InferType::clone): fix ctor
(InferType::apply_primitive_type_hint): new function to apply possible hint
* typecheck/rust-tyty.h: update prototypes
* typecheck/rust-unify.cc (UnifyRules::expect_inference_variable): apply type hints
(UnifyRules::expect_bool): likewise
(UnifyRules::expect_char): likewise
(UnifyRules::expect_int): likewise
(UnifyRules::expect_uint): likewise
(UnifyRules::expect_float): likewise
(UnifyRules::expect_isize): likewise
(UnifyRules::expect_usize): likewise
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Mahmoud Mohamed [Wed, 15 Mar 2023 23:54:11 +0000 (02:54 +0300)]
gccrs: resolve: Add name resolution for AltPattern
The main changes in this commit can be logically split into two parts:
1) Pushing new pattern binding contexts in alt patterns. At the start
of each AltPattern we push an 'Or' context which represents the relation
between the bindings of different alts.
Before we resolve each alt arm we need to push a 'Product' context to represent
the relation between the bindings of this specific alt arm and each other.
This 'Product' context is removed after the alt arm visit and the its bindings
are pushed into the 'Or' context.
Eventually, the 'Or' context is removed as well after it fulfills its duty.
Its bindings are then pushed into the previous context similarly and so on.
2) Checking for consistent bindings between the alt arms which is handled
by check_bindings_consistency. The info necessary for this check is held
by binding_info_map inside PatternDeclaration class. The binding_info_map
only holds bindings for one alt arm at a time. After every alt arm visit,
these bindings info are pushed into a vec (that contains all alt arms info
and will eventually be passed to check_bindings_consistency) and emptied out
for the next alt arm visit. At the end, all the info from all the alt arms
are pushed again into binding_info in addition to the initial bindings that
were there before the alt arms visits, this way the binding_info will contain
all the binding_info present in the AltPattern (as it should).
In addition to that, some refactors were made (e.g. add_new_binding function)
and some errors emitted, no biggie.
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-pattern.cc (PatternDeclaration::go):
Print out consistency errors.
(PatternDeclaration::visit): Implement visit for AltPattern.
(PatternDeclaration::add_new_binding): New helper function for
adding a binding to identifier.
* resolve/rust-ast-resolve-pattern.h (struct BindingInfo):
New struct to facilitate checking for inconsistencies between bindings.
gcc/testsuite/ChangeLog:
* rust/compile/torture/alt_patterns1.rs: New test.
This is wrong because it turned into a double reference type becasuse this
bug was consistent bugs were not picked up but this is not correct. We now
reuse our type inference infrastructure to solve the parameters instead.
Philip Herron [Fri, 10 Mar 2023 18:13:01 +0000 (18:13 +0000)]
gccrs: tyty get rid of useless virtuals
This removes can_substitute and contains_type_parameters which were
confusing interfaces to act as a proxy to the SubstitionRef types. This
replaces them with a single base implementation which is much easier to
debug and follow.
Tage Johansson [Sat, 4 Mar 2023 18:43:02 +0000 (19:43 +0100)]
gccrs: Add all rust keywords (except priv) to the follow-set of `:vis` when parsing macro rules
Previously, the following macro rules were rejected by gccrs:
```Rust
macro_rules! {
($v:vis <KEY_WORD>) => { ... };
}
```
This PR fixes so the above code is accepted by the compiler for all key words like `async` or `unsafe`.
The only exception is the keyword `priv` which is not allowed.
See [this page](https://doc.rust-lang.org/reference/macro-ambiguity.html) for reference. Especially the following excerpt:
> FOLLOW(vis) = {,l any keyword or identifier except a non-raw priv; any token that can begin a type; ident, ty, and path nonterminals}.
Fixes #1060
gcc/rust/ChangeLog:
* parse/rust-parse.cc: fix follow-sets
gcc/testsuite/ChangeLog:
* rust/compile/macro47.rs: Test that :vis can be followed by some keywords
* rust/compile/macro48.rs: Test that :vis cannot be followed by the keyword priv
Signed-off-by: Tage Johansson <frans.tage@gmail.com>
Mahmoud Mohamed [Mon, 13 Mar 2023 14:18:11 +0000 (17:18 +0300)]
gccrs: resolve: Handle multiple bindings to the same identifier
https://github.com/rust-lang/rust/blob/master/compiler/rustc_resolve/src/late.rs#L3168
This commit follows rustc's implementation of handling multiple bindings
to the same identifier in parameters.
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit) :declare and
pass bindings to PatternDeclaration::go.
(ResolveExpr::resolve_closure_param): Likewise.
* resolve/rust-ast-resolve-expr.h: Likewise.
* resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit): Likewise.
(ResolveItem::visit): Likewise.
* resolve/rust-ast-resolve-pattern.cc (PatternDeclaration::go): Likewise.
(PatternDeclaration::visit): check for previous identifier bindings
before inserting the new one.
* resolve/rust-ast-resolve-pattern.h (enum PatternBoundCtx): New enum.
* resolve/rust-ast-resolve-stmt.h: pass bindings to PatterDeclaration::go.
Owen Avery [Tue, 14 Mar 2023 22:52:50 +0000 (18:52 -0400)]
gccrs: Convert structs to classes
gcc/rust/ChangeLog:
* hir/tree/rust-hir-full-decls.h
(struct GenericArgsBinding): Convert to class.
(class GenericArgsBinding): Convert from struct.
(struct TypePathFunction): See above.
(class TypePathFunction): See above.
(struct QualifiedPathType): See above.
(class QualifiedPathType): See above.
* ast/rust-ast-full-decls.h
(struct WhereClause): See above.
(class WhereClause): See above.
(struct SelfParam): See above.
(class SelfParam): See above.
(struct FunctionQualifiers): See above.
(class FunctionQualifiers): See above.
(struct FunctionParam): See above.
(class FunctionParam): See above.
(struct StructField): See above.
(class StructField): See above.
(struct TupleField): See above.
(class TupleField): See above.
(struct TraitFunctionDecl): See above.
(class TraitFunctionDecl): See above.
(struct TraitMethodDecl): See above.
(class TraitMethodDecl): See above.
(struct NamedFunctionParam): See above.
(class NamedFunctionParam): See above.
* hir/tree/rust-hir-path.h
(struct GenericArgsBinding): See above.
(class GenericArgsBinding): See above.
(struct TypePathFunction): See above.
(class TypePathFunction): See above.
(struct QualifiedPathType): See above.
(class QualifiedPathType): See above.
* ast/rust-item.h
(struct WhereClause): See above.
(class WhereClause): See above.
(struct SelfParam): See above.
(class SelfParam): See above.
(struct FunctionQualifiers): See above.
(class FunctionQualifiers): See above.
(struct FunctionParam): See above.
(class FunctionParam): See above.
(struct StructField): See above.
(class StructField): See above.
(struct TupleField): See above.
(class TupleField): See above.
(struct TraitFunctionDecl): See above.
(class TraitFunctionDecl): See above.
(struct TraitMethodDecl): See above.
(class TraitMethodDecl): See above.
(struct NamedFunctionParam): See above.
(class NamedFunctionParam): See above.
Arthur Cohen [Wed, 1 Mar 2023 11:35:18 +0000 (12:35 +0100)]
gccrs: hir: Add ExportedMacro node and handling.
This HIR node represents macros which should be exported into the final
Rust metadata files. Because our metadata exporter operates on the HIR,
while macros are inherently tied to the AST, we need a way to propagate
exported macros up until the metadata export pass on the HIR. Hence the
existence of this class, whose sole purpose is to keep enough information
for the metadata exporter to retrieve the original AST::MacroRulesDefinition.
Handling for actually exporting these macros will come later.
Mahmoud Mohamed [Tue, 7 Mar 2023 23:57:24 +0000 (02:57 +0300)]
gccrs: hir: Provide basic handling for ReferencePattern in function parameter
Added an implementation for
`CompilePatternBindings::visit (HIR::ReferencePattern)` where we
dereference the initial expression and recurse.
Added an implementation for
`CompilePatternBindings::visit (HIR::IdentifierPattern)` as well since it's
the simplest base case.
In addition to this, a small refactor for the shared code in
`StructPattern` and `TupleStructPattern` visits was added as a helper
function called `create_tmp_param_var`.
gcc/rust/ChangeLog:
* backend/rust-compile-fnparam.cc (CompileFnParam::visit):
Added visit implementation for ReferencePattern.
(CompileFnParam::create_tmp_param_var):
Refactored duplicated code into a helper function.
* backend/rust-compile-fnparam.h: Added visit implementation for
ReferencePattern.
* backend/rust-compile-pattern.cc (CompilePatternBindings::visit):
Added visit implementation for ReferencePattern and
IdentifierPattern.
* backend/rust-compile-pattern.h: Added visit implementation for
ReferencePattern and IdentifierPattern.
gcc/testsuite/ChangeLog:
* rust/compile/ref_pattern_fn_param.rs: Moved to...
* rust/compile/ref_pattern_fn_param1.rs: ...here.
* rust/compile/ref_pattern_fn_param2.rs: New test.
* rust/execute/torture/ref-pattern1.rs: New test.
Arthur Cohen [Thu, 2 Mar 2023 15:56:33 +0000 (16:56 +0100)]
gccrs: enr: Fetch module items during early name resolution
This is important as public macros can be present in other modules,
which would otherwise not be loaded until the expansion phase
happening right after the early name resolution.
Jakub Dupak [Sat, 11 Mar 2023 19:36:11 +0000 (20:36 +0100)]
gccrs: hir: Unify indentation approach with ast
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Indent::Indent): Move to separate file.
(operator<<): Move to separate file.
(Indent::increment): Move to separate file.
(Indent::decrement): Move to separate file.
* ast/rust-ast-dump.h (class Indent): Move to separate file.
* hir/rust-hir-dump.cc (Dump::Dump): Use new indentation object.
(Dump::go): Use new indentation object.
(Dump::visit): Use new indention object.
* hir/rust-hir-dump.h: Use new indentation object.
* util/rust-dump.h: New file. Moved Indentation from rust-ast-dump.cc
Marc Poulhiès [Sat, 17 Dec 2022 15:23:05 +0000 (16:23 +0100)]
gccrs: fix some clang warnings
This fixes some extra warnings reported by clang.
gcc/rust/ChangeLog:
PR rust/108111
* ast/rust-ast-full-decls.h (StructPatternElements): Declare as a
class.
* ast/rust-item.h (EnumItem): Mark several method as being
overrides.
* ast/rust-pattern.h (StructPattern::get_locus): Add override.
* lex/rust-lex.h (BufferInputSource): Use reference_wrapper
instead of bare reference.
(TokenSource::get): Add method to implement the reference_wrapper
interface.
* typecheck/rust-tyty.h (TypeBoundPredicate): Add empty dtor.
* util/rust-buffered-queue.h (peek): Source token stream is now
using a reference_wrapper, use .get()
vincent [Tue, 7 Mar 2023 20:32:04 +0000 (20:32 +0000)]
gccrs: hir: add a helper function for visit
This commit adds a helper function for TypeCheckPattern::visit
(HIR::RangePattern &pattern) to remove redundancy
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-pattern.cc
(TypeCheckPattern::visit): rewrite part code to helper function
(TypeCheckPattern::typecheck_range_pattern_bound): helper function
* typecheck/rust-hir-type-check-pattern.h
(TypeCheckPattern::typecheck_range_pattern_bound):
change the parameter of the function
Signed-off-by: Jiakun Fan <jfan30@u.rochester.edu>
Owen Avery [Tue, 7 Mar 2023 18:37:08 +0000 (13:37 -0500)]
gccrs: Add coherence related lang_items
gcc/rust/ChangeLog:
* util/rust-lang-item.h
(RustLangItem::ItemType): New enumerators.
(RustLangItem::Parse): Parse new enumerators.
(RustLangItem::ToString): Handle new enumerators.
* rust/compile/stringify.rs: Add a basic test with some text.
* rust/execute/torture/builtin_macro_stringify.rs: Verify the
text is left as is without any other macro expansion.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Add length checking for tuple patterns.
(TypeCheckPattern::emit_pattern_size_error): New function.
* typecheck/rust-hir-type-check-pattern.h: New function
emit_pattern_size_error.
Philip Herron [Fri, 3 Mar 2023 18:17:50 +0000 (18:17 +0000)]
gccrs: make predicate bounds overwrite-able
When compiling types especially when using queries it needs to be
permissive and allow them to be overwritten and a predicate might have one
set of details in one senario and a new one with the same id later on but
with different types.
Fixes #1524
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
Philip Herron [Fri, 3 Mar 2023 18:01:01 +0000 (18:01 +0000)]
gccrs: Fix name-resolution to be permissive and carry on
There are a few edge cases when resolving TypePaths that we cannot fully
resolve to an explicit node_id and this is expected. So for example
<A as B>::foo
A and B are simple Type paths and thats 100% but the segment foo cannot be
100% resolved to an explicit node id as this requires type-resolution to
find the correct path. So when we have complex paths such as:
<<A as B>::foo as C>
The ::foo part will return UNKNOWN_NODEId and we return early and think its
a failure case but its not necessarily a failure but we need to make sure
to name resolve C so when we do type-resolution we can resolve C properly.
Addresses #1524
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
Philip Herron [Wed, 1 Mar 2023 22:09:47 +0000 (22:09 +0000)]
gccrs: Fix missing move and copy constructors missing the associated-path
Addresses #1524
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* ast/rust-ast.cc (QualifiedPathInType::as_string): add missing to string
* ast/rust-path.h: add missing copy+move constructors and assignment overloads
* hir/tree/rust-hir-path.h: likewise
* hir/tree/rust-hir.cc (QualifiedPathInType::as_string): add missing to string
gcc/testsuite/ChangeLog:
* rust/compile/parse_associated_type_as_generic_arg.rs: it now works without -fsyntax-only
* rust/compile/parse_associated_type_as_generic_arg2.rs: likewise
Philip Herron [Fri, 3 Mar 2023 16:12:46 +0000 (16:12 +0000)]
gccrs: destructure parameter names.
When we have complex generic code you can end up with situations where we
compile types:
Maybe<<S as Foo>::A>
Into
Maybe<<placeholder:<Projection=::()>>>
This calls destructure to cleanup the naming here and avoid making non
canonical TREE_TYPES hitting the verify_gimple code triggering non-trival
constructors.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
Philip Herron [Fri, 3 Mar 2023 18:42:21 +0000 (18:42 +0000)]
gccrs: Take advantage of our new unify_and to inject inference
Wen computing higher ranked trait bounds where there are multiple type
params and ones which are not bound entirely on the impl-type we need
to inject inference variables as required to compute the types. The
inference variables we inject are missing the callbacks that we can compute
the bounds properly so this is the first part of the fix.
Addresses #1893
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* typecheck/rust-hir-trait-resolve.cc: use unify_and infer