-
Notifications
You must be signed in to change notification settings - Fork 164
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
Parse variadic functions #2701
Parse variadic functions #2701
Conversation
e675b5e
to
bf6c4ec
Compare
01dc98b
to
385376e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory it should be possibe to add a hello world test here by adding a parameter name to the printf varadic function lets make sure that works and go for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you! nice work :)
99af120
to
b9e6943
Compare
I did as you suggested, with two new tests in 171e3ae, one execute with a printf as well as another test to ensure named variadic with a wildcard pattern are parsed correctly. |
Variadic were represented at the function level while retaining most informations of a given parameter. gcc/rust/ChangeLog: * ast/rust-item.h (class FunctionParam): Add some informations to function parameters in order to be able to store variadic argument as a function parameter. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Variadic functions were not parsed because it is an unstable feature. While it is still unstable, it is required in order to parse libcore. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_function_param): Parse variadic functions. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
This function provides an easy way to check for a function's varidicity. gcc/rust/ChangeLog: * ast/rust-item.h: Add a getter to check if a given function is variadic. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
This was made to align NamedFunctionParam with FunctionParam. gcc/rust/ChangeLog: * ast/rust-item.h (class NamedFunctionParam): Add variadic boolean and another constructor. * hir/rust-ast-lower-extern.h: Avoid last parameter when variadic. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
171e3ae
to
52f448d
Compare
The new variadic representation has introduced multiple issues and ICE into the codebase. Some early passes in the compiler depend on the parameters all having a type and being an actual parameter. gcc/rust/ChangeLog: * ast/rust-ast.cc (ExternalFunctionItem::as_string): Adapt as_string function to the new ast representation. (NamedFunctionParam::as_string): Likewise. * ast/rust-item.h: Add a function to test whether a FunctionParam has a name pattern. * expand/rust-cfg-strip.cc (CfgStrip::visit): Adapt cfg strip visitor for the new variadic arguments. * hir/rust-ast-lower-extern.h: Adapt lowering to the new variadic function representation. * metadata/rust-export-metadata.cc (ExportContext::emit_function): Change call to constructor. * parse/rust-parse-impl.h (Parser::parse_named_function_param): Change NamedFunctionParam parsing to accomodate new variadic representation. (Parser::parse_external_item): Change external item parsing to use the new NamedFunctionParam variadics. * parse/rust-parse.h: Add new parsing function prototypes. * ast/rust-ast-collector.cc (TokenCollector::visit): Rework token collection to take into account variadic parameters. * ast/rust-ast-visitor.cc: Likewise. * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Change function bound to avoid getting the type of a variadic parameter. * resolve/rust-ast-resolve-item.cc (ResolveExternItem::visit): Likewise. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
This new test highlight the behavior of the new parser and it's ability to parse variadic rust functions. gcc/testsuite/ChangeLog: * rust/compile/parse_variadic_function.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Add ability to parse named variadic parameters in extern c functions. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_named_function_param): Add new parsing ability. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
This test ensure that extern C named variadics are parsed correctly. gcc/testsuite/ChangeLog: * rust/compile/extern_c_named_variadic.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Variadic arguments may have a name or a pattern. This commit provides two new tests in order to ensure their correct behavior. gcc/testsuite/ChangeLog: * rust/compile/pattern_variadic.rs: New test. * rust/execute/torture/named_variadic.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
52f448d
to
e1d0970
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM go for it
Parse variadic functions.
This version of the PR modifies the way variadic are stored in the ast. Variadic were previously handled at function level, but this makes the parser a bit ugly. This PR suggest keeping variadic informations as a special parameter instead. It requires a lot of work to reflect this change at all level of the compiler. Many passes consider the number of arguments without checking for variadicity, therefore, this PR creates a big pile of ICE as of c6d9843.
Alternative to #2704
Fixes #2664
Fixes #2700