Improve feature collection and permit macro attribute input#4425
Open
P-E-P wants to merge 7 commits intoRust-GCC:masterfrom
Open
Improve feature collection and permit macro attribute input#4425P-E-P wants to merge 7 commits intoRust-GCC:masterfrom
P-E-P wants to merge 7 commits intoRust-GCC:masterfrom
Conversation
d6e2638 to
946e07e
Compare
c748a69 to
5b8cec3
Compare
Rename is_builtin to identify_builtin and change prototype to return the builtin when found. gcc/rust/ChangeLog: * util/rust-attributes.cc (is_builtin): Rename from here ... (identify_builtin): ... to here. (is_proc_macro_type): Handle new return value. (AttributeChecker::check_inner_attribute): Likewise. (AttributeChecker::check_attribute): Likewise. (AttributeChecker::visit): Likewise. * util/rust-attributes.h (identify_builtin): Update function prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Feature collection should happen before expansion because some feature gating happens with macros. This commit does no move the feature collection before the expansion pass, it simply split the collection part from the gating part. gcc/rust/ChangeLog: * Make-lang.in: Add new feature collector file. * checks/errors/feature/rust-feature-gate.cc (FeatureGate::visit): Remove feature collection from gating visitor. (FeatureGate::gate): Use features from the crate feature entity instead of old class members. * checks/errors/feature/rust-feature-gate.h: Get features from a separate CrateFeatures struct instead of keeping them in the class. * rust-session-manager.cc (Session::compile_crate): Collect features before gating them. * util/rust-attribute-values.h: Add feature attribute value. * checks/errors/feature/rust-feature-collector.cc: New file. * checks/errors/feature/rust-feature-collector.h: New file. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/ChangeLog: * expand/rust-cfg-strip.cc (CfgStrip::fails_cfg): Remove function. * expand/rust-cfg-strip.h: Remove function prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Features are now collected early rather than later during the feature gating visitor. This requires the introduction of an early cfg strip in order to collect #![cfg(xxxx), feature(yyyy)] correctly. gcc/rust/ChangeLog: * Make-lang.in: Add rust-early-cfg-strip object file. * expand/rust-cfg-strip.h (expand_cfg_attrs): Declare function prototype. * rust-session-manager.cc (Session::compile_crate): Reorder feature collection and add early cfg strip. * expand/rust-early-cfg-strip.cc: New file. * expand/rust-early-cfg-strip.h: New file. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
rust-for-linux uses some nightly features that appeared with rust 1.50. gcc/rust/ChangeLog: * checks/errors/feature/contrib/fetch: Bump version from 1.49.0 to 1.50.0. Change brace expansion to explicit file fetch. * checks/errors/feature/rust-feature-defs.h: Regenerate. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Some nightly features change the parser's behavior, it may accepts syntax that should be rejected when the feature is missing. But the complete list of enabled features can only be found once the parsing is complete. We should therefore not emit any error at parse time and instead collect a potential error and emit it later during the feature gating step. gcc/rust/ChangeLog: * checks/errors/feature/rust-feature-gate.cc (FeatureGate::check): Check all parse time errors. * checks/errors/feature/rust-feature-gate.h: Update function prototype with parse time errors. * parse/rust-parse-impl-attribute.hxx: Collect potential gating error with non literal attribute values. Remove error emission. * parse/rust-parse.h: Add a function to gather potential feature gating errors as well as a getter for collected errors. * rust-session-manager.cc (Session::compile_crate): Retrieve potential feature gating errors and check them later during the feature gating step. * util/rust-attributes.cc (check_export_name_attribute): Change attribute checking error emission to prevent errors with macro inputs. gcc/testsuite/ChangeLog: * rust/compile/doc_macro.rs: Enable feature to use a macro within an attribute input. * rust/compile/parse_time_feature_gate.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
We use multiple parsers and can't retrieve all early feature gating errors within the usual gating pass. This commit introduces a store to collect all early gating errors in the same place from multiple parsers. The features are then checked as usual within the feature gate checker. gcc/rust/ChangeLog: * checks/errors/feature/rust-feature-gate.cc (EarlyFeatureGateStore::get): Add function to retrieve singleton instance. (EarlyFeatureGateStore::add): New function to add an error and the corresponding feature in the store. (EarlyFeatureGateStore::get_error): Add new function to retrieve the oldest error. (FeatureGate::check): Update the function to retrieve the errors from the store instead of getting it from the parameters. * checks/errors/feature/rust-feature-gate.h (class EarlyFeatureGateStore): Add a new class to collect all early feature gating errors. * parse/rust-parse.h: Use store instead of keeping the errors within the parser instance. * rust-session-manager.cc (Session::compile_crate): Remove old early error collection from the main parser. * rust-system.h: Include queue header. gcc/testsuite/ChangeLog: * rust/compile/issue-3661.rs: Add key_value_attribute feature to prevent error on stringify macro. * rust/compile/early_feature_gate_in_macro.rs: Add test to highlight early feature gate error collection within macros. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
5b8cec3 to
bd9918d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.