Skip to content

Deprecate the blocking parameter of File, Socket and IO::FileDescriptor constructors#16034

Merged
straight-shoota merged 2 commits intocrystal-lang:masterfrom
ysbaddaden:feature/deprecate-file-socket-and-fd-blocking-arg
Jul 31, 2025
Merged

Deprecate the blocking parameter of File, Socket and IO::FileDescriptor constructors#16034
straight-shoota merged 2 commits intocrystal-lang:masterfrom
ysbaddaden:feature/deprecate-file-socket-and-fd-blocking-arg

Conversation

@ysbaddaden
Copy link
Collaborator

@ysbaddaden ysbaddaden commented Jul 29, 2025

The final patch to the blocking behavior rework. Each event loop configures the system file descriptor or handle as per its internal requirement, and we shall deprecate the blocking argument.

Extracted from #15924. Follow up to #15804, #15754, #15753, #15750, #15930 and #15977. Depends on #15999 and #16012 for the deprecations to be visible.

Parser support for annotations on def parameters was only added in #12044 for Crystal 1.5.

Copy link
Member

@straight-shoota straight-shoota left a comment

Choose a reason for hiding this comment

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

The version flags are annoying, but I suppose there's no way around that.

@straight-shoota straight-shoota added this to the 1.18.0 milestone Jul 29, 2025
@straight-shoota straight-shoota changed the title Deprecate the blocking arg of File, Socket and IO::FileDescriptor constructors Deprecate the blocking parameter of File, Socket and IO::FileDescriptor constructors Jul 31, 2025
@straight-shoota straight-shoota merged commit 2b85244 into crystal-lang:master Jul 31, 2025
39 checks passed
@ysbaddaden ysbaddaden deleted the feature/deprecate-file-socket-and-fd-blocking-arg branch July 31, 2025 09:32
@ysbaddaden
Copy link
Collaborator Author

At some point we might release a 2.0 that would allow us to drop these in a 2.x release, so we can build 1.0 -> 2.0 -> 2.x. Maybe.

@ysbaddaden
Copy link
Collaborator Author

ysbaddaden commented Jul 31, 2025

Or release patched versions of 1.0 -> 1.4 where the parser will skip over argument annotations?

@straight-shoota
Copy link
Member

straight-shoota commented Jul 31, 2025

Alternatively, we could break forward compatibility for building a 1.x compiler with a compiler < 1.5.
But this requires more consideration about the implications and exact implementation details (related: #12937).

@Blacksmoke16
Copy link
Member

This PR seems a bit problematic related to its deprecation warnings. If I have a file with puts "foo" and run it on latest commit in master I get:

$ ccrystal test.cr
Using compiled compiler at /home/george/dev/git/crystal/.build/crystal
In /home/george/dev/git/crystal/src/file.cr:525:3

 525 | {% begin %}
       ^
Warning: expanding macro


There was a problem expanding macro 'macro_140154605514400'

Called macro defined in /home/george/dev/git/crystal/src/file.cr:525:3

 525 | {% begin %}

Which expanded to:

    1 |
    2 |   def self.open(filename : Path | String, mode = "r", perm = DEFAULT_CREATE_PERMISSIONS, encoding = nil, invalid = nil,  @[Deprecated]  blocking = nil, &)
 >  3 |     file = new filename, mode, perm, encoding, invalid, blocking
    4 |     begin
    5 |       yield file
    6 |     ensure
    7 |       file.close
    8 |     end
    9 |   end
   10 |
Warning: Deprecated argument blocking.

A total of 1 warnings were found.
foo

I feel like I shouldn't be getting warned about something in the stdlib that I have no control over fixing.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants