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

API: Use a ModItem as the root of a crate #306

Merged
merged 6 commits into from
Nov 4, 2023

Conversation

xFrednet
Copy link
Member

This PR has 3 major changes:

  1. The items of a Crate are now wrapped in a ModItem, that is the root module of the crate.
  2. The LintPass trait now as a new check_crate method.
  3. Rustc's driver no longer ICEs on spans from compiler generated code.

It has been some time, but I'm back. Exams really took it out of me, and then I felt so exhausted, that I needed to take a step back for some time, just to breathe. This should hopefully be the kickoff for me getting back into things :D


Closes #279

Feedback is as always highly appreciated! And for everyone reading this: I hope you have a beautiful day. It's awesome that you're a part of open source, be proud of yourself! Life can be stressful, so don't forget to take a break every once in a while.

@xFrednet xFrednet added this to the v0.4.0 milestone Oct 31, 2023
@xFrednet xFrednet added C-enhancement Category: New feature or request A-api Area: Stable API D-rustc-driver Driver: Rustc Driver I-api-break Issue: This change will break the public API labels Oct 31, 2023
marker_api/src/span.rs Outdated Show resolved Hide resolved
marker_rustc_driver/src/conversion/marker.rs Outdated Show resolved Hide resolved
marker_rustc_driver/src/conversion/marker/span.rs Outdated Show resolved Hide resolved
span: SpanId(..),
vis: Visibility {{ /* WIP: See rust-marker/marker#26 */}},
ident: Ident {
name: "",
Copy link
Contributor

@Veetaha Veetaha Nov 1, 2023

Choose a reason for hiding this comment

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

This ident is suspiciously empty. Shouldn't it be None?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not quite sure how this value was constructed. I've now removed all compiler generated items from Marker's AST representation and this "fixed" (meaning hid this issue) for now. I believe I have seen some circumstances, where the identifier was empty of something in the compiler for a valid reason, but I don't remember where. As for the None part. The Ident struct is used a lot, adding an option in it, would make handling it very cumber sum. So, even if this was a bug, I think it's better to have "" as a symbol than using an option inside the Ident

span: $DIR/print_me_root_module.rs:1:1 - 1:1,
},
},
use_path: AstPath {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd be glad if lints didn't even need to see the standard prelude. I guess it deserves it's own ugly crutch to skip such code. And.. in general, I think lints don't ever need to see code with the "built-in" spans auto-generated by the compiler. I imagine someone writes a lint that triggers on a standard prelude use item and thus is cursed to never be able to ignore that false positive unless ignoring it at crate-level meaning the lint is just disabled and useless 😺

Copy link
Member Author

Choose a reason for hiding this comment

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

Skipping the import items from the prelude would be pretty simple, items already have an ugly crunch to handle such things.

The question for me, is more if we want this? So these items are definitely not intended for lint emissions, but they are required to get the full information about what namespace etc are available. On the other hand, these changes are always bound to Editions, so if we provide information about that, it should be sufficient to get all the information needed for linting 🤔

Copy link
Contributor

@Veetaha Veetaha Nov 1, 2023

Choose a reason for hiding this comment

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

The namespace information should be queried from the TyCtxt. I don't think that lint authors will specifically traverse all uses and do manual name resolution, which is a complex and recursive algorithm.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done 👍

marker_api/src/interface.rs Show resolved Hide resolved
@@ -235,7 +235,7 @@ impl<'ast> std::fmt::Debug for Span<'ast> {
fmt_pos(file.try_to_file_pos(self.end))
),
SpanSource::Macro(expn) => format!("[Inside Macro] {:#?}", expn.call_site()),
SpanSource::Buildin(_) => "[From Prelude]".to_string(),
SpanSource::Builtin(_) => "[From Prelude]".to_string(),
Copy link
Contributor

Choose a reason for hiding this comment

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

If lints can't observe the prelude, then we may go without the "Builtin" span source? Or is there any other way this "Builtin" span source can be created? The test that was added in this PR no longer contains such a span source. If there is any other way it could be created, it would be good to have a test that showcases how it can be constructed

Copy link
Member Author

Choose a reason for hiding this comment

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

The filter mechanism added in this PR should filter out all spans with a builtin source. However, I'm not 100% sure if that really removes every trace. Before this new SpanSource Marker would ICE when requesting these spans. I'm in favor of keeping it in the API as it will prevent potential ICEs. If we're starting to look at the stabilization of Marker, we can review if this value ever came up again.

I can imagine that also some unstable features might fall back on this source, during initial development. This is just a guess, though.

I'll change the text of this function to say "[Builtin]" instead.

@xFrednet xFrednet added this pull request to the merge queue Nov 4, 2023
Merged via the queue into rust-marker:master with commit 7c2ba48 Nov 4, 2023
22 of 23 checks passed
@xFrednet xFrednet deleted the 279-crate-mod branch November 4, 2023 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-api Area: Stable API C-enhancement Category: New feature or request D-rustc-driver Driver: Rustc Driver I-api-break Issue: This change will break the public API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feat]: Add method to check the root module of a crate
2 participants