Skip to content

Conversation

powerboat9
Copy link
Collaborator

This vendors some of rustc_feature 1.49 and generates a list of features by parsing the vendored code.

@powerboat9 powerboat9 force-pushed the feature-improve branch 4 times, most recently from ab44d03 to 56d724e Compare August 17, 2025 20:10
@powerboat9
Copy link
Collaborator Author

powerboat9 commented Aug 18, 2025

Note that the movements of rust-feature.cc and rust-feature-gate.cc into a subdirectory break incremental builds. Run rm gcc/rust/{,.deps/}rust-feature{,-gate}.* in the build directory to fix.

@iains
Copy link
Contributor

iains commented Aug 22, 2025

This vendors some of rustc_feature 1.49 and generates a list of features by parsing the vendored code.

I think the covering note would usefully contain more information;

  • what the data is needed for
  • where it comes from
  • how it would be changed

maybe?
perhaps this is obvious to folks working closely with the project - but it is less so to GCC reviewers

This vendors some of rustc_feature 1.49 (part of rustc) and generates a
list of features by parsing the vendored code. This ensures that our
list of unstable rust features can be more easily kept in sync with
rustc.

I wrote https://github.com/powerboat9/feature-scan before I wrote this
patch, but that program has a lot of unnecessary dependencies. This
patch only uses flex and bison to parse the included files, instead of
trying to compile them as part of a rust project that will only work
with a 5 year old version of rustc.

See https://doc.rust-lang.org/unstable-book/.

gcc/rust/ChangeLog:

	* Make-lang.in: Compile feature-related source files, including
	a flex/bison based parser for the vendored rust files.
	* checks/errors/rust-feature-gate.cc: Move to...
	* checks/errors/feature/rust-feature-gate.cc: ...here.
	(FeatureGate::gate): Handle removal of Feature::create.
	(FeatureGate::visit): Refer to AUTO_TRAITS as
	OPTIN_BUILTIN_TRAITS.
	* checks/errors/rust-feature-gate.h: Move to...
	* checks/errors/feature/rust-feature-gate.h: ...here.
	* checks/errors/rust-feature.cc: Move to...
	* checks/errors/feature/rust-feature.cc: ...here.
	(Feature::create): Remove.
	(Feature::feature_list): New static member variable.
	(Feature::name_hash_map): Use "rust-feature-defs.h" to define.
	(Feature::lookup): New member function definition.
	* checks/errors/rust-feature.h: Move to...
	* checks/errors/feature/rust-feature.h: ...here.
	(Feature::State): Add comments.
	(Feature::Name): Use "rust-feature-defs.h" to define.
	(Feature::as_string): Make const.
	(Feature::name): Likewise.
	(Feature::state): Likewise.
	(Feature::issue): Likewise.
	(Feature::description): Remove.
	(Feature::create): Remove.
	(Feature::lookup): New member function declarations.
	(Feature::Feature): Adjust arguments.
	(Feature::m_rustc_since): Rename to...
	(Feature::m_rust_since): ...here.
	(Feature::m_description): Remove.
	(Feature::m_reason): New member variable.
	(Feature::feature_list): New static member variable.
	* checks/errors/feature/rust-feature-gen.l: New file.
	* checks/errors/feature/rust-feature-gen.y: New file.
	* checks/errors/feature/vendor/LICENSE-APACHE: New file.
	* checks/errors/feature/vendor/LICENSE-MIT: New file.
	* checks/errors/feature/vendor/README: New file.
	* checks/errors/feature/vendor/accepted.rs: New file.
	* checks/errors/feature/vendor/active.rs: New file.
	* checks/errors/feature/vendor/removed.rs: New file.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
@powerboat9
Copy link
Collaborator Author

@iains I've added a link (https://doc.rust-lang.org/unstable-book/) and added a bit to the first paragraph of the commit message

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.

I'm not sure this is the best way to go about this. The format used by rustc for declaring features is not stable, so it might as well change in version 1.90 and the parser will require modifications. I think I would rather see something simpler, but if everyone agrees with this PR's approach then I'm okay with it too

@powerboat9
Copy link
Collaborator Author

The parser will almost certainly need modifications in the future -- I'm just not sure how else to do this, aside from trying to manually update rust-feature.h and rust-feature.cc

@CohenArthur
Copy link
Member

personally I think that manually updating rust-feature.{cc, h} every time we do a Rust version bump is fine. It won't happen that often (at least for now), and I think it can be achieved easily with a good editor and sed-fu.

I'm really not a fan of yacc/lex but as I said if others are okay with it then that's fine with me - but my opinion is that I'd rather be the one to manually update our features every time rather than maintain a yacc/lex parser

@iains
Copy link
Contributor

iains commented Aug 26, 2025

I'd imagine that a manual process could use awk, if sed was not enough - and perhaps if it's a "once every two years" and "the result is committed to the repo" then having a built tool to do it is overkill (not a particular fan of flex/bison either .. not really a fan of awk ;) ) ..
,, maybe the simplest approach is easiest to maintain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants