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

support deprecated attribute in type constructors #3715

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

Wilbert-mad
Copy link

@Wilbert-mad Wilbert-mad commented Oct 19, 2024

Addressing: #3698

  • Analysis should report error when a custom types' variants are all deprecated
  • Parser should error if an unsupported attribute is used on a variant
  • LSP warning for deprecated variants
  • Formator allow attributes for type constructors

Copy link
Member

@giacomocavalieri giacomocavalieri left a comment

Choose a reason for hiding this comment

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

This is looking nice! I left a couple of comments inline

compiler-core/src/parse.rs Outdated Show resolved Hide resolved
Comment on lines 311 to 318
ParseErrorType::UnknownAttributeRecordConstructor => (
"Variant attribute(s) are unknow.",
vec!["Try `@deprecated`.".into()],
),
Copy link
Member

Choose a reason for hiding this comment

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

I think I'd rather have an error that explicitly says that the attribute cannot be used on a variant for each of the attributes rather than a single error for all of those.

pub type Wibble {
  @external(javascript, "", "")
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This attribute cannot be used on a type variant
  Wobble
}

Also I would not include that hint, it doesn't make much sense to suggest using deprecated if I wrote an @external or @internal attribute

@lpil
Copy link
Member

lpil commented Oct 20, 2024

Thank both!!

@lpil lpil marked this pull request as draft October 20, 2024 11:26
@lpil
Copy link
Member

lpil commented Oct 21, 2024

When you're ready for review please un-draft this PR 💜

@Wilbert-mad Wilbert-mad marked this pull request as ready for review October 23, 2024 23:41
@lpil
Copy link
Member

lpil commented Oct 24, 2024

Is this ready for a review? :)

@Wilbert-mad
Copy link
Author

Yes! :D

compiler-core/src/error.rs Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@GearsDatapacks
Copy link
Member

Just so you know, merge commits are not allowed in this repository. You'll need to rebase before Louis will accept it

@Wilbert-mad Wilbert-mad force-pushed the deprecated-tag-in-type-constructor branch from 9857f7c to 836d5a4 Compare October 26, 2024 00:55
@Wilbert-mad
Copy link
Author

Alright, that should be good. Sorry about that. I'll leave it up to y'all from here.

@giacomocavalieri
Copy link
Member

giacomocavalieri commented Oct 26, 2024

One thing is missing is version tracking. If someone is using the deprecated attribute on a constructor we want to make sure the version in their gleam.toml is >= 1.6 (if this gets merged before the 1.6 release).

This would require adding a new variant ConstructorWithDeprecatedAnnotation to the FeatureKind enum (

pub enum FeatureKind {
LabelShorthandSyntax,
ConstantStringConcatenation,
ArithmeticInGuards,
UnannotatedUtf8StringSegment,
NestedTupleAccess,
InternalAnnotation,
AtInJavascriptModules,
}
) and track its usage during the analysis phase I think

@Wilbert-mad Wilbert-mad force-pushed the deprecated-tag-in-type-constructor branch from 5a06896 to 3828be4 Compare October 27, 2024 01:02
@Wilbert-mad
Copy link
Author

Done!

Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

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

Very nice!! This is nearly ready to go. I've left some small comments

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
compiler-core/src/analyse.rs Outdated Show resolved Hide resolved
compiler-core/src/error.rs Outdated Show resolved Hide resolved
compiler-core/src/parse.rs Outdated Show resolved Hide resolved
compiler-core/src/type_/tests/custom_types.rs Show resolved Hide resolved
@Wilbert-mad
Copy link
Author

Finished!

@lpil lpil force-pushed the deprecated-tag-in-type-constructor branch 3 times, most recently from 84845bb to 33f9f03 Compare November 7, 2024 16:01
Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

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

Fab! I've left some notes inline improving the wording of messages and making internal types more accurate. After that we're ready to merge! Thank you

@@ -878,6 +886,36 @@ impl<'a, A> ModuleAnalyzer<'a, A> {
.parameters
.clone();

// check if all constructors are deprecated if so error
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// check if all constructors are deprecated if so error
// Check if all constructors are deprecated if so error.

.error(Error::AllVariantsConstructorDeprecated { location });
}

// if any constructor record/varient is deprecated while
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// if any constructor record/varient is deprecated while
// If any constructor record/varient is deprecated while

.iter()
.any(|record| record.deprecation.is_deprecated())
{
// report error on all variants attibuted with deprecated
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// report error on all variants attibuted with deprecated
// Report error on all variants attibuted with deprecated

}
");
Diagnostic {
title: "Deprecating all variants of a type is not allowed.".into(),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
title: "Deprecating all variants of a type is not allowed.".into(),
title: "All variants of custom type deprecated.".into(),

let text = String::from("Consider removing the deprecation attribute on the type's variant.");

Diagnostic {
title: "Deprecating variants of a type that is deprecated is not allowed".into(),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
title: "Deprecating variants of a type that is deprecated is not allowed".into(),
title: "Custom type already deprecated".into(),

@@ -398,6 +402,7 @@ pub enum ParseErrorType {
ConstantRecordConstructorNoArguments, // const x = Record()
TypeConstructorNoArguments, // let a : Int()
TypeDefinitionNoArguments, // pub type Wibble() { ... }
UnknownAttributeRecordConstructor, // an attribute was used that is not know for a custom type constructor
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
UnknownAttributeRecordConstructor, // an attribute was used that is not know for a custom type constructor
UnknownAttributeRecordVariant // an attribute was used that is not know for a custom type variant

@@ -860,6 +880,7 @@ pub enum FeatureKind {
AtInJavascriptModules,
RecordUpdateVariantInference,
RecordAccessVariantInference,
ConstructorWithDeprecatedAnnotation,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ConstructorWithDeprecatedAnnotation,
VariantWithDeprecatedAnnotation,

@@ -1033,6 +1033,9 @@ See: https://tour.gleam.run/functions/pipelines/",
FeatureKind::RecordAccessVariantInference => {
"Field access on custom types when the variant is known was"
}
FeatureKind::ConstructorWithDeprecatedAnnotation => {
"The constructor's `@deprecated` annotation was"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"The constructor's `@deprecated` annotation was"
"Deprecating individual custom type variants was"

@@ -972,7 +994,9 @@ impl Error {
}
| Error::UseFnDoesntTakeCallback { location, .. }
| Error::UseFnIncorrectArity { location, .. }
| Error::BadName { location, .. } => location.start,
| Error::BadName { location, .. }
| Error::AllVariantsConstructorDeprecated { location }
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
| Error::AllVariantsConstructorDeprecated { location }
| Error::AllVariantsDeprecated { location }

| Error::BadName { location, .. } => location.start,
| Error::BadName { location, .. }
| Error::AllVariantsConstructorDeprecated { location }
| Error::VariantDeprecatedOnDeprecatedConstructor { location } => location.start,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
| Error::VariantDeprecatedOnDeprecatedConstructor { location } => location.start,
| Error::DeprecatedVariantOnDeprecatedType { location } => location.start,

@Wilbert-mad Wilbert-mad force-pushed the deprecated-tag-in-type-constructor branch from c1908bb to ec69f60 Compare November 9, 2024 17:49
@lpil
Copy link
Member

lpil commented Nov 10, 2024

Hi @Wilbert-mad, you've force pushed to an older version of the code so there's now merge conflicts. Please rebase on main. Thank you

@Wilbert-mad Wilbert-mad force-pushed the deprecated-tag-in-type-constructor branch from ec69f60 to f8280b9 Compare November 11, 2024 04:39
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.

4 participants