Commit Graph

203606 Commits

Author SHA1 Message Date
Pierre-Emmanuel Patry
2c862b96f1 Add a new test for const without body
This new regression test highlight the fixed behavior for 2709.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2709.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-06 17:13:22 +00:00
Pierre-Emmanuel Patry
068753493f Make use of the Contextual visitor in validation
Use the new contextual ast visitor to reduce the amount of code in the
ast validation visitor.

gcc/rust/ChangeLog:

	* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Adapt
	the call to the new visit functions.
	(ASTValidation::check): Launch the parent class visitor root function.
	* checks/errors/rust-ast-validation.h (class ASTValidation): Inherit
	from the contextual visitor.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-06 17:13:22 +00:00
Pierre-Emmanuel Patry
95325d7864 Add a new visitor that gathers context information
This visitor is intended to be used by other visitors that require
context at some point for a given item.

gcc/rust/ChangeLog:

	* ast/rust-ast-visitor.cc (ContextualASTVisitor::visit): Add multiple
	context saving calls.
	* ast/rust-ast-visitor.h (class DefaultASTVisitor): Make visit
	functions virtual.
	(class ContextualASTVisitor): Add a stack like container for the
	current context chain.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-06 17:13:22 +00:00
Pierre-Emmanuel Patry
4068593c22 Add a default AST visitor
This will allow us to derive other visitors from it and overload only a
few selected visit methods.

gcc/rust/ChangeLog:

	* Make-lang.in: Add the new visitor object file.
	* ast/rust-ast-visitor.h (class DefaultASTVisitor): Create the default
	visitor class.
	* ast/rust-ast.h: Add a new reference getter for visitor pattern.
	* ast/rust-ast-visitor.cc: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-06 17:13:22 +00:00
Pierre-Emmanuel Patry
ebe2f98aa5 Add some reference getter
Visitor pattern requires a getter to children using a mutable reference.

gcc/rust/ChangeLog:

	* ast/rust-ast.h: Add some missing mutable reference getters.
	* ast/rust-expr.h: Likewise.
	* ast/rust-item.h: Likewise.
	* ast/rust-path.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-06 17:13:22 +00:00
Pierre-Emmanuel Patry
e7caf68fe0 Small fix to the ast collector visitor
The parameter type was used instead of the default value.

gcc/rust/ChangeLog:

	* ast/rust-ast-collector.cc (TokenCollector::visit): Check for presence
	of a type and use the default value instead of the type.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-06 17:13:22 +00:00
Pierre-Emmanuel Patry
fb346fab74 Emit an error on associated const without values
Associated const with no value that are not in trait impl are prohibited.

gcc/rust/ChangeLog:

	* checks/errors/rust-ast-validation.cc (ASTValidation::check): Launch
	check over the whole given crate.
	(ASTValidation::visit): Implement visitor for some members of the ast.
	* checks/errors/rust-ast-validation.h: Update some prototype according
	to implemented visitor functions. Also add a context tracker.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-06 17:13:22 +00:00
Pierre-Emmanuel Patry
230cd6df82 Add call to ast validation checker
Add call to ast validation check, also add appropriate step to this pass
and the feature gating.

gcc/rust/ChangeLog:

	* rust-session-manager.cc (Session::compile_crate): Add call to ast
	validation.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-06 17:13:22 +00:00
Pierre-Emmanuel Patry
d8286cfb1f Add two new steps to compile process
Add the ast validation and feature gating steps to the compile pipeline.

gcc/rust/ChangeLog:

	* lang.opt: Add the new compile options and update the enum values.
	* rust-session-manager.h (struct CompileOptions): Add the new steps to
	the enumeration.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-06 17:13:22 +00:00
Pierre-Emmanuel Patry
b70b3d6110 Add ast validation checker
Add a new visitor to validate a given ast after the expansion pass.

gcc/rust/ChangeLog:

	* Make-lang.in: Add the new object file the list.
	* checks/errors/rust-ast-validation.cc: New file.
	* checks/errors/rust-ast-validation.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-06 17:13:22 +00:00
Pierre-Emmanuel Patry
2c5d1113e3 Add more checks for expr value in early visitors
Early passes visitors may encounter constant item without a value, this
is expected as the pass rejecting a constant without an expression is
done later during the ast validation.

gcc/rust/ChangeLog:

	* expand/rust-cfg-strip.cc (CfgStrip::visit): Add expr value check.
	* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise.
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
	Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-06 17:13:22 +00:00
Pierre-Emmanuel Patry
1f8a1bbff6 Move SingleASTNode implementation out of header
Those functions implementation put additional constraints on the headers
which makes the codebase harder to work with.

gcc/rust/ChangeLog:

	* ast/rust-ast.h: Move implementation from here...
	* ast/rust-ast.cc (SingleASTNode::SingleASTNode): ...to here.
	(SingleASTNode::operator=): ...and here...
	(SingleASTNode::accept_vis): ...and here...
	(SingleASTNode::is_error): ...and here...
	(SingleASTNode::as_string): ...also here.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-06 11:46:54 +00:00
Pierre-Emmanuel Patry
78ba5b74fb Add missing override specifier
Some function lacked the override specifier, this made the compiler emit
several warning.

gcc/rust/ChangeLog:

	* ast/rust-ast.h: Add override specifier.
	* ast/rust-item.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-06 11:46:54 +00:00
Pierre-Emmanuel Patry
e009d3df6a Add regression test for float literal tuple indices
Add a new regression test in order to highlight the fix for #2659.

gcc/testsuite/ChangeLog:

	* rust/compile/not_a_float_literal_tuple_index.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-06 10:08:09 +00:00
Pierre-Emmanuel Patry
7de72c6684 Fix token lexed as a float literal
The lexer cannot distinguish the difference between a float literal and a
tuple index in some cases. This means we should fix this while parsing
depending on the context.

gcc/rust/ChangeLog:

	* expand/rust-macro-invoc-lexer.cc (MacroInvocLexer::split_current_token):
	Add implementation for multiple token split.
	* expand/rust-macro-invoc-lexer.h: Add function prototype.
	* expand/rust-proc-macro-invoc-lexer.cc (ProcMacroInvocLexer::split_current_token):
	Add implementation for 2+ token split for procedural macros.
	* expand/rust-proc-macro-invoc-lexer.h: Add function prototype.
	* lex/rust-lex.cc (Lexer::split_current_token): Add function to split a
	token in multiple other tokens.
	* lex/rust-lex.h: Add function prototype for split_current_token.
	* parse/rust-parse-impl.h (Parser::left_denotation): Handle float tuple
	index identified as a float literal.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-06 10:08:09 +00:00
Jakub Dupak
0a2f8fc8f2 HIR: remove obsole double borrow member
gcc/rust/ChangeLog:

	* hir/rust-hir-dump.cc (Dump::visit): Remove obsolete member.
	* hir/tree/rust-hir-expr.h (class BorrowExpr): Remove obsolete member.
	* hir/tree/rust-hir.cc (BorrowExpr::as_string): Remove obsolete member.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2023-11-02 13:41:31 +00:00
Jakub Dupak
16182dc050 HIR: fix typo
gcc/rust/ChangeLog:

	* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Fix typo.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2023-11-02 13:41:31 +00:00
Owen Avery
e489a694c7 Compile pattern match statements into conditional statements
gcc/rust/ChangeLog:

	* backend/rust-compile-expr.cc
	(patterns_mergeable): Remove.
	(struct PatternMerge): Remove.
	(sort_tuple_patterns): Remove.
	(simplify_tuple_match): Remove.
	(CompileExpr::visit): Modify compilation of MatchExpr.

	* backend/rust-compile-pattern.cc
	(CompilePatternCaseLabelExpr::visit): Replace with...
	(CompilePatternCheckExpr::visit): ...this.
	* backend/rust-compile-pattern.h
	(class CompilePatternCaseLabelExpr): Replace with...
	(class CompilePatternCheckExpr): ...this.

	* backend/rust-compile-type.cc
	(TyTyResolveCompile::get_implicit_enumeral_node_type):
	Make enumeral type equivalent to isize.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2023-11-01 16:46:52 +00:00
Pierre-Emmanuel Patry
5d622b6a6d Document proc macro token tree indices
Multiple references to procedural macro token trees were left as magic
number in the code. This commit introduces some constexpr for those along
some explanation for the selected value.

gcc/rust/ChangeLog:

	* backend/rust-compile-base.cc (get_attributes): Add documentation for
	indices 3 and 4.
	(get_trait_name): Add documentation for index 1.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-10-31 11:39:08 +00:00
Pierre-Emmanuel Patry
4ac19a0501 Move proc macro builders to their own file
The code to build the required procedural macro symbols is rather long
and could be placed in it's own file.

gcc/rust/ChangeLog:

	* Make-lang.in: Add gcc/rust/backend/rust-compile-proc-macro.cc to the
	list of file to compile.
	* backend/rust-compile.cc (attribute_array): Move to
	rust-compile-proc-macro.cc
	(derive_proc_macro): Likewise.
	(bang_proc_macro): Likewise.
	(attribute_proc_macro): Likewise.
	(proc_macro_payload): Likewise.
	(proc_macro): Likewise.
	(proc_macro_buffer): Likewise.
	(entrypoint): Likewise.
	(proc_macro_array): Likewise.
	(CompileCrate::add_proc_macro_symbols): Likewise.
	* backend/rust-compile-proc-macro.cc: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-10-31 11:39:08 +00:00
Pierre-Emmanuel Patry
3c6aca6cc1 Add array length to the proc macro buffer
The compiler cannot infer the array length from the type, we should
therefore hand it the information. The proc macro buffer missed that
information.

gcc/rust/ChangeLog:

	* backend/rust-compile.cc (proc_macro_buffer): Update type builder with
	array length information.
	(proc_macro_array): Update type initializer with array length
	information.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-10-31 11:39:08 +00:00
Pierre-Emmanuel Patry
a1ed0756c0 Put common functions in their own namespace
Half of the functions introduced recently had a similar goal while the
other half had a similar goal too. Introducing some namespace to separate
those will keep the code cleaner and avoid confusion.

gcc/rust/ChangeLog:

	* backend/rust-compile.cc (build_attribute_array): Renamed from...
	(attribute_array): ...to attribute array.
	(build_derive_proc_macro): Likewise from...
	(derive_proc_macro): ... to derive_proc_macro.
	(build_bang_proc_macro): Likewise from...
	(bang_proc_macro): ...to bang_proc_macro.
	(build_attribute_proc_macro): Likewise from...
	(attribute_proc_macro): ... to attribute_proc_macro.
	(build_proc_macro_payload): Likewise from...
	(proc_macro_payload): to proc_macro_payload.
	(build_proc_macro): Likewise from...
	(proc_macro): ...to proc_macro.
	(build_proc_macro_buffer): Likewise from...
	(proc_macro_buffer): ... to proc_macro_buffer.
	(build_entrypoint): Likewise from...
	(entrypoint): ...to entrypoint.
	(init_derive_proc_macro): Renamed to it's shorter counterpart.
	(init_attribute_proc_macro): Likewise.
	(init_bang_proc_macro): Likewise.
	(init_proc_macro): Likewise.
	(initialize_proc_macro_array): Likewise.
	(proc_macro_array): Likewise.
	(CompileCrate::add_proc_macro_symbols): Update function calls.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-10-31 11:39:08 +00:00
Pierre-Emmanuel Patry
aee54e56a9 Add macro buffer global variable export
Export a new symbol containing the proc macros.

gcc/rust/ChangeLog:

	* backend/rust-compile-base.h: Make static function address_expression
	public.
	* backend/rust-compile.cc (CompileCrate::add_proc_macro_symbols): Add
	new global variable in export function.
	(build_bang_proc_macro): Add a function to build the bang proc macro
	structure type.
	(build_proc_macro): Add a function to build the proc macro structure
	type.
	(build_proc_macro_payload): Add a function to build the proc macro
	union used in proc macro structures.
	(init_derive_proc_macro): Add a function to initialize custom derive
	proc macros.
	(init_attribute_proc_macro): Add a function to initialize attribute
	proc macros.
	(init_bang_proc_macro): Add a function to initialize bang proc macros.
	(init_proc_macro): Add a function to initialize proc macro structures.
	(initialize_proc_macro_array): Add a function to initialize the proc
	macro buffer array.
	(CompileCrate::add_proc_macro_symbols): Add call to the new functions
	to correctly initialize proc macros as well as their entrypoint.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-10-31 11:39:08 +00:00
Pierre-Emmanuel Patry
5afa8b58b7 Add an explicit value to proc macro enum kind
We'll need this value in the final binary, it should therefore be kept
explicit.

ChangeLog:

	* libgrust/libproc_macro_internal/proc_macro.h (enum ProcmacroTag): Add
	explicit value for proc macro tag enum.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-10-31 11:39:08 +00:00
Pierre-Emmanuel Patry
b71fd2afa8 Change proc macro entrypoint
Change proc macro entrypoint from a fixed constant declaration to a
proper generation from the stable crate id. Although the stable crate id
is not in use yet, the mechanism to handle it is.

gcc/rust/ChangeLog:

	* expand/rust-proc-macro.cc (CustomDeriveProcMacro::CustomDeriveProcMacro):
	Remove constant string declaration.
	(load_macros_array): Add call to the new generation function.
	(generate_proc_macro_decls_symbol): Add a new function to generate the
	entrypoint symbol name from the stable crate id.
	(PROC_MACRO_DECLS_FMT_ARGS):
	New macro to keep formats arguments in sync between each call.
	* expand/rust-proc-macro.h (generate_proc_macro_decls_symbol): Add
	function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-10-31 11:39:08 +00:00
Pierre-Emmanuel Patry
16c0f9c7fb Add utility function to build proc macro types
Add some utility function to build proc macro entrypoint related types.
Those functions will help generate all required metadata in order for
proc macros to be expanded properly.

gcc/rust/ChangeLog:

	* backend/rust-compile.cc (build_attribute_array): Add a function to
	build the attribute array type.
	(build_derive_proc_macro): Add a function to build the derive proc
	macro type.
	(build_bang_proc_macro): Add a function to build the bang proc macro
	type.
	(build_attribute_proc_macro): Add a function to build the attribute
	proc macro type.
	(build_proc_macro): Add a function to build the proc macro tagged union
	type.
	(build_proc_macro_buffer): Add a function to build the proc macro
	buffer type.
	(build_entrypoint): Add a function to build the proc macro entrypoint
	type.
	* backend/rust-compile.h: Add function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-10-31 11:39:08 +00:00
Pierre-Emmanuel Patry
c5dc4b0a5f Add getters for proc macro mappings
Add three different getters, one for each proc macro type.

gcc/rust/ChangeLog:

	* backend/rust-compile-context.h: Add getters.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-10-31 11:39:08 +00:00
Pierre-Emmanuel Patry
573ca06d2a Collect procedural macros in the crate
Collect informations on procedural macros in the compiled crate. For
attribute and bang procedural macros we only require the final address
as well as the name of the function. Derive procedural macros are a bit
different, we collect the fonction's address through it's fndecl tree as
well as the trait's name and the multiple attributes.

gcc/rust/ChangeLog:

	* backend/rust-compile-base.cc (HIRCompileBase::setup_fndecl):
	Make the function non static in order to be able to access the
	compile context. Also add the whole proc macro infomrmation
	collection.
	(get_attributes): Add a function to retrieve the different
	attributes from a derive procedural macro definition attribute.
	(get_trait_name): Add a function to retrieve the trait name from
	a derive procedural macro definition attribute.
	* backend/rust-compile-base.h: Add function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-10-31 11:39:08 +00:00
Pierre-Emmanuel Patry
80fe1c7b6f Reformat comments
gcc/rust/ChangeLog:

	* backend/rust-compile-base.cc (HIRCompileBase::setup_abi_options):
	Reformat uncorrectly formatted comments.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-10-31 11:39:08 +00:00
Pierre-Emmanuel Patry
e76f9223ed Add containers for proc macro collection mappings
Add one container for each kind of procedural macro mapping. Also add a
new structure to gather informations required for derive procedural
macros. Add different functions to fill those new containers.

gcc/rust/ChangeLog:

	* backend/rust-compile-context.h (struct CustomDeriveInfo): Add
	new derive procedural macro metadata information holder for
	mappings.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-10-31 11:39:08 +00:00
Pierre-Emmanuel Patry
b5118d1a6a Add const getter for tokentrees
We often need to retrieve the underlying tokentree without modifying it,
this getter will help achieve this.

gcc/rust/ChangeLog:

	* ast/rust-ast.h: Add const getter.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-10-31 11:39:08 +00:00
Pierre-Emmanuel Patry
327a285500 Change ABI setup and add gccrs_proc_macro attr
Change the way the ABI is setup on a function to avoid duplicates. ABI
is setup by the setup function only now. Add a new attribute to the
function "gccrs_proc_macro" in order to differentiate it from another
type of function.

gcc/rust/ChangeLog:

	* backend/rust-compile-base.cc (handle_proc_macro_common): Add
	new attribute "gccrs_proc_macro" to all procedural macro
	functions.
	(get_abi): Add a function to retrieve the correct ABI depending
	on wether the function is a proc macro or not.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-10-31 11:39:08 +00:00
Pierre-Emmanuel Patry
ff32f8fdce Make proc macro definition cdecl
We need to make sure proc macros have the C abi in order to be called by
the compiler with dlopen.

gcc/rust/ChangeLog:

	* backend/rust-compile-base.cc (HIRCompileBase::setup_fndecl):
	Add proc macro handlers dispatch.
	(handle_proc_macro_common): Add a function for common behavior
	between all kinds of proc macros.
	* backend/rust-compile-base.h: Add function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-10-31 11:39:08 +00:00
Jakub Dupak
2a1a37344f borrowck: Refactor and BIR improvements
gcc/rust/ChangeLog:

	* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::setup_loop): Move.
	(ExprStmtBuilder::get_label_ctx): Move.
	(ExprStmtBuilder::get_unnamed_loop_ctx): Moved.
	(ExprStmtBuilder::visit): BIR improvements.
	* checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Refactor.
	* checks/errors/borrowck/rust-bir-builder-internal.h (class LifetimeResolver):
	Refactor.
	(struct BuilderContext): Move.Refactor.
	(optional_from_ptr): Map on null ptr.
	* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h (class LazyBooleanExprBuilder):
	Refactor.
	* checks/errors/borrowck/rust-bir-builder-pattern.h: Refactor.
	* checks/errors/borrowck/rust-bir-builder-struct.h (class StructBuilder): Refactor.
	* checks/errors/borrowck/rust-bir-builder.h: Refactor.
	* checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Refactor.
	(Dump::visit): Refactor.
	(Dump::visit_place): Refactor.
	(Dump::visit_move_place): Refactor.
	(Dump::visit_lifetime): Refactor.
	* checks/errors/borrowck/rust-bir-dump.h: Refactor.
	* checks/errors/borrowck/rust-bir-place.h: Refactor.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2023-10-26 15:05:49 +00:00
Jakub Dupak
325dd9ed04 borrowck: Dev notes
gcc/rust/ChangeLog:

	* checks/errors/borrowck/dev-notes.md: New file.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2023-10-26 15:05:49 +00:00
Jakub Dupak
df5b6a371d borrowck: Docs
gcc/rust/ChangeLog:

	* checks/errors/borrowck/bir-design-notes.md: New file.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2023-10-26 15:05:49 +00:00
Jakub Dupak
449a375541 borrowck: Make goto explicit.
gcc/rust/ChangeLog:

	* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Use goto.
	* checks/errors/borrowck/rust-bir-builder-internal.h: Explicit goto.
	* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Explicit goto.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2023-10-26 15:05:49 +00:00
Jakub Dupak
587c3b2b91 borrowck: BIR continue
gcc/rust/ChangeLog:

	* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Continue.
	(ExprStmtBuilder::setup_loop): Continue.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2023-10-26 15:05:49 +00:00
Jakub Dupak
8aac66b06e borrowck: Dump: handle infinite loops
gcc/rust/ChangeLog:

	* checks/errors/borrowck/rust-bir-dump.cc (simplify_cfg): Detech infinite loops.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2023-10-26 15:05:49 +00:00
Jakub Dupak
85f924f470 borrowck: BIR: handle break
gcc/rust/ChangeLog:

	* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Push ctx.
	(ExprStmtBuilder::setup_loop): Common loop infractructure setup.
	* checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Loop ctx.
	* checks/errors/borrowck/rust-bir-builder-internal.h (struct BuilderContext): Loop ctx.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2023-10-26 15:05:49 +00:00
Jakub Dupak
97a0d40594 borrowck: Dump improve jumps
gcc/rust/ChangeLog:

	* checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Improve jumps dump.
	(Dump::visit): Improve jumps dump.
	* checks/errors/borrowck/rust-bir-dump.h (class Dump): Improve jumps dump.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2023-10-26 15:05:49 +00:00
Jakub Dupak
c92e110f06 borrowck: Dump: simplify cfg
Add option to simplify cfg for better readability. Off by default.

gcc/rust/ChangeLog:

	* checks/errors/borrowck/rust-bir-dump.cc (simplify_cfg): Simplify cfg logic.
	(Dump::go): Run simplify cfg.
	* checks/errors/borrowck/rust-bir-dump.h: Option to simplify cfg.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2023-10-26 15:05:49 +00:00
Jakub Dupak
8eb8474add borrowck: Dump: proper comma separation
gcc/rust/ChangeLog:

	* checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Use new print.
	(print_comma_separated): Comma separation print.
	(Dump::visit): Use new print.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2023-10-26 15:05:49 +00:00
Jakub Dupak
f5b9bab688 borrowck: BIR dump
gcc/rust/ChangeLog:

	* Make-lang.in: Build BIR dump.
	* checks/errors/borrowck/rust-borrow-checker.cc (mkdir_wrapped): Cross-platform mkdir.
	(dump_function_bir): Save dump to file.
	(BorrowChecker::go): Run dump during borrowck.
	* checks/errors/borrowck/rust-bir-dump.cc: New file.
	* checks/errors/borrowck/rust-bir-dump.h: New file.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2023-10-26 15:05:49 +00:00
Jakub Dupak
9a45588f39 borrowck: Create BIR builders (visitors)
gcc/rust/ChangeLog:

	* Make-lang.in: Compile BIR expr visitor.
	* checks/errors/borrowck/rust-borrow-checker.cc (BorrowChecker::go): Use BIR builder.
	* rust-session-manager.cc (Session::compile_crate): Run borrow checker.
	* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc: New file.
	* checks/errors/borrowck/rust-bir-builder-expr-stmt.h: New file.
	* checks/errors/borrowck/rust-bir-builder-internal.h: New file.
	* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: New file.
	* checks/errors/borrowck/rust-bir-builder-pattern.h: New file.
	* checks/errors/borrowck/rust-bir-builder-struct.h: New file.
	* checks/errors/borrowck/rust-bir-builder.h: New file.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2023-10-26 15:05:49 +00:00
Jakub Dupak
dfafead7c2 borrowck: Create Borrow-checker IR (BIR)
gcc/rust/ChangeLog:

	* checks/errors/borrowck/rust-borrow-checker.cc: Include to compile new code.
	* checks/errors/borrowck/rust-bir-place.h: New file.
	* checks/errors/borrowck/rust-bir-visitor.h: New file.
	* checks/errors/borrowck/rust-bir.h: New file.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2023-10-26 15:05:49 +00:00
Jakub Dupak
dd23e4f8b9 borrowck: Execute only with CLI flag
gcc/rust/ChangeLog:

	* lang.opt: CLI flag.
	* rust-session-manager.cc (Session::compile_crate): Guard execution.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2023-10-26 15:05:49 +00:00
Jakub Dupak
7ac6f9b4c7 borrowck: Add CLI option for borrowck
gcc/rust/ChangeLog:

	* checks/errors/borrowck/rust-borrow-checker.cc (BorrowChecker::BorrowChecker): Opt dump.
	(BorrowChecker::go): Opt dump.
	* checks/errors/borrowck/rust-borrow-checker.h (class BorrowChecker): Opt dump.
	* lang.opt: Add compile until borrowcheck.
	* rust-session-manager.cc (Session::enable_dump): Add BIR.
	(Session::compile_crate): Handle new options.
	* rust-session-manager.h (struct CompileOptions): Add BIR.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2023-10-26 15:05:49 +00:00
Jakub Dupak
2bb559cea9 borrowck: Add initial structure for borrowchecking
gcc/rust/ChangeLog:

	* Make-lang.in: Build borrowck.
	* checks/errors/borrowck/rust-borrow-checker.cc: New file.
	* checks/errors/borrowck/rust-borrow-checker.h: New file.
	* checks/errors/borrowck/rust-function-collector.h: New file.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2023-10-26 15:05:49 +00:00
Pierre-Emmanuel Patry
9a8b3eaedd Fix warning with overridden virtual methods
Overridden virtual methods were not marked as such.

gcc/rust/ChangeLog:

	* ast/rust-pattern.h: Add override modifier to overriding methods.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-10-24 07:33:57 +00:00