-
Notifications
You must be signed in to change notification settings - Fork 81
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
compiler: temporary disallow generics usages #3041
Conversation
756b2d8
to
4ae4bcc
Compare
@roman-khimov, this problem is completely generics-related, I'm not sure we'd like to fix this panic right now with some temporary solution. Please, see the #3040 (comment). |
Codecov Report
@@ Coverage Diff @@
## master #3041 +/- ##
==========================================
+ Coverage 84.78% 84.86% +0.08%
==========================================
Files 329 329
Lines 43953 44023 +70
==========================================
+ Hits 37265 37360 +95
+ Misses 5189 5160 -29
- Partials 1499 1503 +4
... and 8 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
We can just return an error if we detect any code using generics. |
|
I don't know if there is any way to detect generic code use without going that deep. That'd be perfect, but if we don't have it then we can:
|
4ae4bcc
to
51b9f56
Compare
Close #3040. |
51b9f56
to
777fcc8
Compare
I've adjusted the behaviour for method receiver, now the proper error is returned to the user and it is done inside the |
If you don't feel comfortable with these changes, it's OK to postpone them for 0.102.1, no need to rush here. |
777fcc8
to
a8c2be8
Compare
a8c2be8
to
febab9f
Compare
@roman-khimov, I've reworked the initial structure a bit so that it'll be easier for us to revert generics-related commits. Now all generics-related checks are separated in the |
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.
Can we at least partially fix #3023 here? Our compiler documentation still doesn't say a word about generics.
case *ast.IndexExpr: | ||
// Generic func declaration receiver: func (x *Pointer[T]) Load() *T | ||
name = t.X.(*ast.IndexExpr).X.(*ast.Ident).Name + "." + name | ||
} |
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.
Panic by default?
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.
No, we won't panic here. We will retrieve the proper name and I want this code to be kept in future (unlike the rest of commits in this PR). We will analize whether the method is generic in a separate place.
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.
Got your idea, will fix.
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.
Fixed.
name = t.X.(*ast.IndexExpr).X.(*ast.Ident).Name + "." + name | ||
} | ||
case *ast.IndexExpr: | ||
switch t.X.(type) { |
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.
Why a switch here?
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.
Because there might be some other types, and if so, then we'll handle only the known one. Do you want to panic on something unexpected?
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.
Yeah, there needs to be some reasonable error, otherwise we have an undefined behavior and that's not what I would like to have in the compiler.
pkg/compiler/analysis.go
Outdated
@@ -19,6 +19,8 @@ var ( | |||
ErrMissingExportedParamName = errors.New("exported method is not allowed to have unnamed parameter") | |||
// ErrInvalidExportedRetCount is returned when exported contract method has invalid return values count. | |||
ErrInvalidExportedRetCount = errors.New("exported method is not allowed to have more than one return value") | |||
// ErrGenericsUnsuppored is returned when generics-related tokens are encountered. | |||
ErrGenericsUnsuppored = errors.New("generics are currently unsupported, please, see the https://github.com/nspcc-dev/neo-go/issues/2377") |
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.
2376! Commits should reference it as well.
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.
Fixed.
Fix panic described in #3040. Ref. #2376. Signed-off-by: Anna Shaleva <[email protected]>
Either non-pointer or pointer, both cases are disallowed to be generic. Need to be reverted and properly handled within the scope of #2376. Signed-off-by: Anna Shaleva <[email protected]>
Need to be reverted and properly handled within the scope of #2376. Signed-off-by: Anna Shaleva <[email protected]>
Need to be reverted and properly handled within the scope of #2376. Signed-off-by: Anna Shaleva <[email protected]>
27edec4
to
ec814da
Compare
docs/compiler.md
Outdated
@@ -31,6 +31,8 @@ a dialect of Go rather than a complete port of the language: | |||
* type assertion with two return values is not supported; single return value (of the desired type) | |||
is supported; type assertion panics if value can't be asserted to the desired type, therefore | |||
it's up to the programmer whether assert can be performed successfully. | |||
* type aliases including the built-in `any` alias are supported. | |||
* generics are not supported, but eventually will be, ref. https://github.com/nspcc-dev/neo-go/issues/2376. |
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.
Not sure they will be supported properly, but partially maybe.
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.
Adjusted.
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.
Hope, they will. At least function arguments can be supported, it doesn't seem impossible.
Part of #3023. Signed-off-by: Anna Shaleva <[email protected]>
ec814da
to
66a8001
Compare
This PR includes the following changes:
Close #3040. Ref. #2377.