-
-
Notifications
You must be signed in to change notification settings - Fork 830
Warn when running a deprecated or internal module main function #4283
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
base: main
Are you sure you want to change the base?
Conversation
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.
I've addressed your questions in the related issue here
Looks good so far. Since this PR isn't ready to be merged yet, would you mind converting it to a draft? |
Yeah sure |
PR should be ready for review |
fixed failing workflows |
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.
Nice, thank you! I've left some notes inline. Could you also update the changelog file and add a snapshot test for each of the two warnings, so we can see what they look like.
Actually nevermind the snapshot tests, the warnings look simple enough. If you could add the module name to each of them though that would be great. Something like "The module x/y/z is internal" and "The main function in the module x/y/z is internal". |
Yeah sure, will add in the module names |
Module names added |
777d19b
to
4f2f1b3
Compare
should I fix these conflicts? |
At some point yes, although this won't be merged until 1.9 is released. |
cool |
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! I've left some notes inline.
@@ -220,6 +226,23 @@ pub enum DeprecatedSyntaxWarning { | |||
impl Warning { | |||
pub fn to_diagnostic(&self) -> Diagnostic { | |||
match self { | |||
Warning::DeprecatedMain { message } => Diagnostic { | |||
title: "Deprecated main function".into(), | |||
text: message.into(), |
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.
Format this the same as the existing deprecation message please
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.
I have updated the deprecation text, but run function doesn't have access to the location data like path
and src
? I can pass the module name itself but I don't think that's correct?
compiler-cli/src/run.rs
Outdated
@@ -120,9 +125,33 @@ fn setup( | |||
|
|||
let built = crate::build::main(paths, options, manifest)?; | |||
|
|||
// Warn incase the module being run has been as internal | |||
let warning_emitter = WarningEmitter::new(Rc::new(ConsoleWarningEmitter)); |
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.
This is using a different warning emitter to build::main
. I think we want to only use a single one per-run as we will be tracking things such as the total count when the project denys any warnings.
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.
ok
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.
@lpil I fixed it by adding a new parameter in the crate::build::main for the warning emitter
Since currently Rc::new(ConsoleWarningEmitter)
was being passed directly
Previous:
pub fn main(paths: &ProjectPaths, options: Options, manifest: Manifest) -> Result<Built> {
main_with_warnings(paths, options, manifest, Rc::new(ConsoleWarningEmitter))
}
Current:
pub fn main(
paths: &ProjectPaths,
options: Options,
manifest: Manifest,
warnings: Rc<dyn WarningEmitterIO>, // --> new
) -> Result<Built> {
main_with_warnings(paths, options, manifest, warnings)
}
is this fine?
compiler-cli/src/run.rs
Outdated
let warning_emitter = WarningEmitter::new(Rc::new(ConsoleWarningEmitter)); | ||
|
||
// Warn incase the module being run has been as internal | ||
let internal_module = built.is_internal(&module.clone().into()).unwrap_or(false); |
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.
When can the module be unknown at this point? Looking at the unwrap_or
here.
Don't clone the module please. Build an ecostring beforehand and use that here and below.
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.
changed modules into a EcoString,
As for the unwrap_or
it might happen when the module doesn't exist?
pub fn is_internal(&self, module: &EcoString) -> Result<bool, Error> {
match self.module_interfaces.get(module) {
Some(module_data) => Ok(module_data.is_internal),
None => Err(Error::ModuleDoesNotExist {
module: module.clone(),
suggestion: None,
}),
}
}
I had made this method to check if a particular module when passed by name is internal
|
||
// Warn incase the module being run has been as internal | ||
let internal_module = built.is_internal(&module.clone().into()).unwrap_or(false); | ||
if internal_module { |
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.
This is still warning for internal module from the root package!
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.
I must be misunderstanding a bit,
I am trying to test with
@internal
pub fn main() {
io.println("hello")
}
marking @internal
to the main will be giving the warning right?
can you please give an gleam code showing the case where it is happening?
level: diagnostic::Level::Warning, | ||
location: None, | ||
hint: None, | ||
} |
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.
It would be great to have snapshot tests for how these warnings look please!
aae84a1
to
8a177a3
Compare
Hello @Lioncat2002 ! Are you working on this atm? |
Hi @lpil , sorry, I have been tied up with irl stuff recently. |
This PR closes issue #2569
Features added:
A new
is_deprecated
field of typeDeprecation
has been introduced intoModuleFunction
structupdated struct looks like this:
The
get_main_function
inside ofModuleInterface
has been updated to return the deprecation value from thevalue
variableA new
is_internal
function has been introduced into theBuilt
struct. It accepts themodule
similar to the other functions in the struct, fetches it'sModuleInterface
and returns either a bool or an error based on if the module is present in the HashmapAdded warning when the module being called is either deprecated or internal