Skip to content

Conversation

powerboat9
Copy link
Collaborator

@powerboat9 powerboat9 commented Aug 17, 2025

This includes a program, written using flex and bison, to extract information on unstable features from rustc source code and save it to a header file.

The script does fetch files from https://github.com/rust-lang/rust (the official rustc git repository), which should be alright, as it's only intended to be run by maintainers.

See https://doc.rust-lang.org/unstable-book/ for information on unstable features.

@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

@powerboat9 powerboat9 force-pushed the feature-improve branch 2 times, most recently from 191f938 to e53bff9 Compare August 22, 2025 23:08
@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.

@powerboat9
Copy link
Collaborator Author

If we don't skip versions, we'll need to do the update 40+ times. Someone could reimplement this PR in awk or sed, or just manually do the updates, but I'd think either would require much more effort. The maintenance required to keep this updated should be minimal, but I'd be willing to do it whatever the case.

@powerboat9 powerboat9 force-pushed the feature-improve branch 4 times, most recently from e59670b to 5e848a7 Compare August 27, 2025 02:45
@powerboat9
Copy link
Collaborator Author

I've moved the script* to contrib/rust and adjusted things a bit so that only maintainers have to run it.

@powerboat9 powerboat9 marked this pull request as draft August 27, 2025 03:20
@CohenArthur
Copy link
Member

@powerboat9 I think we will be skipping versions honestly, I don't think there is much point trying to have every single version implemented at different stages during the project's life. Since the main difference between versions is unstable features, if we try and implement every single version, we will run into situations where we implement a feature and then disable it in a few version bumps.

This can also happen with doing big updates obviously, but less often

@powerboat9
Copy link
Collaborator Author

This code just makes sure that the list of recognized features is up to date

gcc/rust/ChangeLog:

	* Make-lang.in: Handle source files in checks/errors/feature.
	* checks/errors/rust-feature-gate.cc: Move to...
	* checks/errors/feature/rust-feature-gate.cc: ...here.
	* 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.
	* checks/errors/rust-feature.h: Move to...
	* checks/errors/feature/rust-feature.h: ...here.

Signed-off-by: Owen Avery <[email protected]>
This includes a program, written using flex and bison, to extract
information on unstable features from rustc source code and save it to a
header file.

The script does fetch files from https://github.com/rust-lang/rust (the
official rustc git repository), which should be alright, as it's only
intended to be run by maintainers.

See https://doc.rust-lang.org/unstable-book/ for information on unstable
features.

gcc/rust/ChangeLog:

	* checks/errors/feature/rust-feature-gate.cc
	(FeatureGate::gate): Handle removal of Feature::create.
	(FeatureGate::visit): Refer to AUTO_TRAITS as
	OPTIN_BUILTIN_TRAITS.
	* checks/errors/feature/rust-feature.cc (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/feature/rust-feature.h (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 member function declaration.
	(Feature::create): Remove static member function declaration.
	(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-defs.h: New file.

contrib/ChangeLog:

	* rust/feature-fetch/parse.y: New file.
	* rust/feature-fetch/scan.l: New file.
	* rust/feature-fetch/.gitignore: New file.
	* rust/feature-fetch/Makefile: New file.
	* rust/feature-fetch/fetch: New file.
	* rust/feature-fetch/regen: New file.
	* rust/feature-fetch/copyright-stub.h: New file.

Signed-off-by: Owen Avery <[email protected]>
@powerboat9
Copy link
Collaborator Author

Now depends on #4107

@powerboat9
Copy link
Collaborator Author

Would it be better if I left the script out-of-tree?

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