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

Direct IO which is asynchronous #553

Merged
merged 48 commits into from
Sep 25, 2024
Merged

Direct IO which is asynchronous #553

merged 48 commits into from
Sep 25, 2024

Conversation

phischu
Copy link
Collaborator

@phischu phischu commented Aug 23, 2024

TODO

  • Fix in JS backend io/console.effekt
  • Implement in LLVM backend io/console.effekt
  • Fix in JS backend io/network.effekt
  • Implement in LLVM backend io/network.effekt
  • Rename io/files.effekt to io/filesystem.effekt
  • Rename run_Pos to runPositive etc.
  • Check and handle error result in call to uv_fs_open etc.
  • Find and fix memory leaks

@phischu phischu changed the title Extern control defs in llvm Direct IO which is still asynchronous Aug 23, 2024
@phischu phischu changed the title Direct IO which is still asynchronous Direct IO which is asynchronous Sep 3, 2024
libraries/llvm/io.c Outdated Show resolved Hide resolved
@phischu phischu marked this pull request as ready for review September 6, 2024 15:56
Copy link
Collaborator

@b-studios b-studios left a comment

Choose a reason for hiding this comment

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

In general I like the direction of this PR, a lot.

Could you please:

  • rebase it (this will get rid of the additional control flag on externs in lifted, you can delete that again, since we don't plan on supporting the other backends any longer)
  • automatically insert a call to eventloop if main contains control?
  • check indentation (tabs are used in C files quite a lot)

In general, we need to decide which functions should be hidden behind namespaces like direct and promises and which don't.

Can you showcase somewhere how to recover the callback-based version, based on the direct-style one? I think a test or something to document it would be great.

effekt/shared/src/main/scala/effekt/lifted/Tree.scala Outdated Show resolved Hide resolved
examples/stdlib/io/files/async_file_io.effekt Show resolved Hide resolved
examples/stdlib/io/promise.effekt Outdated Show resolved Hide resolved
libraries/common/io.effekt Outdated Show resolved Hide resolved
char* path_str = c_buffer_as_null_terminated_string(path);
erasePositive((struct Pos) path);

// Convert the Effekt String representing the opening mode to libuv flags
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Convert the Effekt String representing the opening mode to libuv flags
// Convert the Effekt Mode-Datatype representing the opening mode to libuv flags

libraries/llvm/io.c Show resolved Hide resolved
request->data = stack;

uv_fs_open(uv_default_loop(), request, path_str, flags, 0666, c_resume_int_fs);
// TODO report result (UV_EINVAL)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to free stuff when this errors? This probably means the continuation is never called and also needs to be ref-count-decremented.

libraries/llvm/io.c Outdated Show resolved Hide resolved
libraries/llvm/io.c Outdated Show resolved Hide resolved
libraries/llvm/io.c Outdated Show resolved Hide resolved
libraries/llvm/io.c Outdated Show resolved Hide resolved
libraries/llvm/io.c Outdated Show resolved Hide resolved
libraries/llvm/io.c Outdated Show resolved Hide resolved
libraries/llvm/io.c Outdated Show resolved Hide resolved
@phischu phischu force-pushed the library/direct-io branch 2 times, most recently from 703ddee to 31af30d Compare September 23, 2024 11:29
char* bytes = c_buffer_bytes(buffer); // libuv expects signed integers
uv_buf_t buf = uv_buf_init(bytes, c_buffer_length(buffer));
// erasePositive(buffer);
// TODO we should erase the buffer but abort if this was the last reference
Copy link
Collaborator

Choose a reason for hiding this comment

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

You mean: decrement the RC but don't free?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This requires rethinking of the whole bytes/buffer/string story. Postponing.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Postponed solution:

a)

  • allocate a user-defined struct Stack x Buffer
  • erase in the continuation / callback

b)

  • erase here, but make sure that it is USED on the Effekt side.

@b-studios
Copy link
Collaborator

Please delete / fix all occurrences of AsyncIO, then this is ready to merge.

@b-studios
Copy link
Collaborator

Thanks, this is a huge step forward!

@b-studios b-studios merged commit b5ff081 into master Sep 25, 2024
2 checks passed
@b-studios b-studios deleted the library/direct-io branch September 25, 2024 14:27
@dvdvgt dvdvgt mentioned this pull request Sep 25, 2024
19 tasks
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