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

Mass-adding type restrictions (def foo() : Bar) #10575

Closed
11 tasks done
oprypin opened this issue Apr 3, 2021 · 12 comments
Closed
11 tasks done

Mass-adding type restrictions (def foo() : Bar) #10575

oprypin opened this issue Apr 3, 2021 · 12 comments

Comments

@oprypin
Copy link
Member

oprypin commented Apr 3, 2021

I have developed a semi-automatic workflow to insert type restrictions into Crystal code, and I plan to apply it to the Crystal standard library. The main purpose is to make documentation better. It also guards against some accidental incompatible changes.

The first phase will be only adding method return type restrictions. It's about 1400 annotations added.

Links (I don't guarantee that the links won't break):

The implementation just needs to be fed real usages of the code, and it looks at all the methods that the compiler resolves while compiling the code, and if the method resolves to the same type in every situation, it figures that maybe it's good to add that type as a type restriction. It's super hacky and super unreliable so I filter and fix the results myself.

But I hope that the methods that this automation suggests to restrict are also safe places to make those changes; I'm not coming up with my own ideas, and if I did, I might miss the fact that I'm changing the actual type (e.g. setting it to Nil but it really isn't Nil and someone relied on that).

Semi-related to #4864, mainly because the implementation is based on the patch posted to the issue

@oprypin
Copy link
Member Author

oprypin commented Apr 12, 2021

Launched phase 2, adding Nil return type restrictions where the methods currently actually don't return nil but weren't meant to have a return value.

@asterite
Copy link
Member

Keep'em coming! ❤️

@straight-shoota
Copy link
Member

I milestoned the entire first batch of PRs. I think they're ready to be merged.
There hasn't been a lot of discussion entries, which I interpret as no general opposition (it could also be that nobody bothered to take a closer look).

The changes are rather big in terms of affected code. But there are presumably no semantic changes.
I'd leave them in the queue for a couple of days to allow for final reviews, but it we wait for too long, conflicts with other PRs may appear again.

@straight-shoota straight-shoota added this to the 1.1.0 milestone Jun 1, 2021
@oprypin
Copy link
Member Author

oprypin commented Jun 4, 2021

Nice. 5 more conflicts appeared.

@straight-shoota
Copy link
Member

straight-shoota commented Jun 9, 2021

The entire first batch has been merged.

@straight-shoota
Copy link
Member

About the second batch: These are technically breaking changes because they alter the return value from something that is not Nil to Nil. However, that something was never meant to be returned and is probably of no particularly use. I would consider this a bug fix to avoid unintended leakage of implementation details, which requires altering the return type. So I think it's fine to merge in a minor release, but please speak up if someone thinks this should rather wait for 2.0.

@straight-shoota
Copy link
Member

I'd like to test the incoming changes from the second batch with test-ecosystem before merging them to master.
We could do that for each PR individually, or merge them in a combined feature branch first. I suppose the former makes it easier to identify where issues come from.

Should wait after 1.1.1 is released though, to avoid congestion on test-ecosystem CI.

@straight-shoota
Copy link
Member

I ran test-ecosystem on all five outstanding PRs and they look good 👍 That doesn't mean it won't break anything else, but it's a encouraging sign. Adding a return type restriction of Nil to methods that were not supposed to return a value in the first place is considerably less likely to cause hidden issues. It would only break code that depends on the (undocumented) return value and we can just say that that's not expected use.

So I think we should go on and merge the Change nonsense return types to Nil PRs.

@sdogruyol
Copy link
Member

Gotta love more return types ❤️ Thanks @oprypin @straight-shoota 🙏

@straight-shoota
Copy link
Member

The second batch has been merged. Thanks @oprypin

@straight-shoota
Copy link
Member

I'm not sure if there's anything left here. Can we close this?

@oprypin
Copy link
Member Author

oprypin commented Sep 17, 2021

It could be used for tracking of something in the future, but right now indeed it's best to close it. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants