io: implement posix.open/read/write.close + _io.FileIO + open#434
io: implement posix.open/read/write.close + _io.FileIO + open#434paugier wants to merge 7 commits intospylang:mainfrom
Conversation
|
I think it is ready for review. One evident very annoying issue is that the C code is not actually tested! |
2be2633 to
bc1176f
Compare
53a6c58 to
0217b07
Compare
|
@paugier thank you! I'll give it a proper review later but in the mean time, some comments:
|
|
@paugier so, I have made some extra investigation on this topic.
I think that what we ultimately want is something like (2), but written in SPy. However, we are probably lacking some low-level capabilities at the moment (e.g. we cannot call I also asked claude what it thinks it's missing:
I think that this is what we should strive for, but as you see it might require a while. Then, we we have more low-level capabilities, we can revisit this plan and implement "proper" IO. What do you think? |
This is not exactly simple... One thing is that I "discussed" a lot with Claude about SPy and its implementation (not particularly for this PR). I'm really impressed how this model is able to nicely explain quite complex ideas. I don't know if Claude keeps some context from previous conversations. For this particular PR, I explained my goals in particular with the issues texts and I asked for the implementation of spy/vm/modules/posix.py and the related tests (nothing special in terms of prompts). I was happy with posix.py (except a Mypy issue and ValueError) but strangely the produced tests were not perfect from my point of view so I cleaned them. I asked for the reason of I'm very impressed by these interactions with a LLM and this is totally new to me... One thing is that I still do not use Claude Code which help me keeping the control. I use copy and paste, format, diff, test, understand and potentially modify to reach the feeling "this is similar to what I would have written manually". For the C code, I do not feel as comfortable as in Python, which is why I didn't feel very well with it. |
I didn't realize that io was so complex 🙂 I also better realize the tension when building a new language between implemented low level features to build the tower with strong underpinnings and giving quickly high level features so that people can start to experiment with the language and are happy with what they see. As a potential SPy user, I tend to think more about user facing syntax and utilities to start to do real things. However, I don't want to rush you in this direction. I see that it would be a very nice demo that SPy can be useful for low level to implement in SPy something like 2. (implement a python-like I/O tower in C). And I see that we need (i) memcpy / memmove, (ii) bytes and str/bytes interop and (iii) more pointers. To start to use SPy for things like benchmarks, it seems to me that the IO can be quite limited. Just FileIO might even be sufficient? |
I think that would be very bad, especially for benchmarks: unbuffered IO is extremely slow and would make all the benchmark looking bad. Sorry for having made you unnecessary work. I even considered merging this PR anyway and keep it for the future, but I don't think it's a good idea because we need a much deeper thinking about it: in particular, on CPython I'm going to leave this PR open, I might decide to "extract" the implementations of |
Fixesrelated to Create afileobject in the stdlib #357Fixesrelated to Add preliminary support for file I/O #354I was helped by Claude, which in particular wrote the C code! It seems reasonable but I'm quite unable to judge if it is really correct.
The most important tests (
test_open_readandtest_open_write) raises an error for the C backend.Claude told me that it is due to the WASI sandbox and that the test can be skipped with
Nevertheless a good news is that this works fine: