Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make function body optional and reject invalid functions during AST validation #2755

Merged
merged 3 commits into from
Dec 6, 2023

Conversation

P-E-P
Copy link
Member

@P-E-P P-E-P commented Nov 22, 2023

Change the function definition to have a clear optional body. Change the AST validation pass to check for free or associated functions without a body.

@P-E-P P-E-P added this to the GCC 14.1 release milestone Nov 22, 2023
@P-E-P P-E-P requested a review from CohenArthur November 22, 2023 15:43
@P-E-P P-E-P self-assigned this Nov 22, 2023
@P-E-P P-E-P force-pushed the function_optional_body branch 2 times, most recently from e7ab4ce to 053a758 Compare November 23, 2023 13:24
@P-E-P P-E-P marked this pull request as ready for review November 23, 2023 14:10
Copy link
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

gcc/rust/ast/rust-ast.cc Outdated Show resolved Hide resolved
@P-E-P P-E-P force-pushed the function_optional_body branch 2 times, most recently from 7bd52a7 to f9a64f6 Compare December 5, 2023 17:57
P-E-P added 3 commits December 5, 2023 19:06
Missing body on a function should be rejected at a later stage in the
compiler, not during parsing.

gcc/rust/ChangeLog:

	* ast/rust-ast-collector.cc (TokenCollector::visit): Adapt defintion
	getter.
	* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise.
	* expand/rust-cfg-strip.cc (CfgStrip::visit): Likewise.
	* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise.
	* hir/rust-ast-lower-implitem.h: Likewise.
	* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Likewise.
	* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Likewise.
	* resolve/rust-ast-resolve-stmt.h: Likewise.
	* resolve/rust-default-resolver.cc (DefaultResolver::visit): Likewise.
	* util/rust-attributes.cc (AttributeChecker::visit):  Likewise.
	* parse/rust-parse-impl.h: Allow empty function body during parsing.
	* ast/rust-ast.cc (Function::Function): Constructor now take an
	optional for the body.
	(Function::operator=): Adapt to new optional member.
	(Function::as_string): Likewise.
	* ast/rust-item.h (class Function): Make body optional and do not
	rely on nullptr anymore.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Add checks in the ast validation pass to error out with functions
(either free or associated) without a definition.

gcc/rust/ChangeLog:

	* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
	a validation check and emit an error depending on the context.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Function body check emit an error message when a required function body
is missing.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
@P-E-P P-E-P force-pushed the function_optional_body branch from f9a64f6 to 89d16c8 Compare December 5, 2023 18:07
@P-E-P P-E-P added this pull request to the merge queue Dec 6, 2023
Merged via the queue into Rust-GCC:master with commit a48b4f8 Dec 6, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants