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

run prints value with bogus type #328

Open
byorgey opened this issue Apr 27, 2022 · 9 comments
Open

run prints value with bogus type #328

byorgey opened this issue Apr 27, 2022 · 9 comments
Labels
Bug The observed behaviour is incorrect or unexpected. C-Project A larger project, more suitable for experienced contributors. G-REPL An issue having to do with the REPL. L-Type system Issues related to the Swarm language type system. S-Nice to have The bug fix or feature would be nice but doesn't currently have much negative impact. T-UI Involves the user interface.

Comments

@byorgey
Copy link
Member

byorgey commented Apr 27, 2022

Describe the bug
Calling run on certain files causes the result of executing the file to be printed along with a unit type, regardless of the actual type of the result.

To Reproduce
In true.sw:

true

Now start swarm and at the REPL, type run("true.sw") This will print out

true : ()

Expected behavior
It should result in

true : bool

(or perhaps it shouldn't print anything at all?).

@byorgey byorgey added Bug The observed behaviour is incorrect or unexpected. S-Nice to have The bug fix or feature would be nice but doesn't currently have much negative impact. L-Type system Issues related to the Swarm language type system. T-UI Involves the user interface. G-REPL An issue having to do with the REPL. labels Apr 27, 2022
@byorgey
Copy link
Member Author

byorgey commented Apr 29, 2022

Another odd thing which seems related:

> if true {move; move} {move}
> if true {x <- move; move} {move}
() : ()

Both execute normally, but in the first case nothing is printed, whereas in the second case () : () is printed. I think it has something to do with binds generating a VResult, which is also related to #327 .

@byorgey
Copy link
Member Author

byorgey commented May 5, 2022

When an expression is entered at the REPL, we first store its type by setting the replStatus to REPLWorking ty Nothing. Then once the CESK machine finishes we take the value that results and print it out along with the type. So the type of run("foo.sw") is cmd () (there is a special case that strips off the cmd before printing the type). But the problem is that run("foo.sw") basically replaces itself so that we actually evaluate the contents of the file foo.sw; but the type in the replStatus never gets updated.

...I guess this means run actually breaks type preservation! The more I think about it the less I like run and the way it currently works. It's expedient but not very well-motivated theoretically.

@byorgey
Copy link
Member Author

byorgey commented Jun 24, 2022

I also encountered () : () being printed when defining a function that called build and did a few other things, then calling that function at the REPL prompt.

@byorgey
Copy link
Member Author

byorgey commented Sep 4, 2022

To be clear at this point, I am keeping this open so we remember that it's a problem, but I expect it will be completely and properly solved by #495, so this issue is not worth working on in and of itself.

@xsebek
Copy link
Member

xsebek commented Nov 6, 2022

Fun idea, would it make more sense for run to have type cmd a?

Then you could at least use the return value at your own risk.

@byorgey
Copy link
Member Author

byorgey commented Nov 6, 2022

I don't see how that would be better. It would still be wrong, and you can already use the return value at your own risk.

@xsebek
Copy link
Member

xsebek commented Nov 6, 2022

@byorgey no, you can only use it as a result of the whole computation (e.g. in objective #828), not in the same term.

Consider this file coinflip.sw:

b <- random 1;
if (b == 0) {
    r <- run "coinflip.sw";
    return $ r + 1; // <-- this r does not type check, because it is unit
} {
    return 0;
}

@byorgey
Copy link
Member Author

byorgey commented Nov 6, 2022

Ah, good point. Still, I don't really see the benefit. I'd rather just do it properly and implement #495. In fact that is one of the next things I was thinking of working on.

@byorgey
Copy link
Member Author

byorgey commented Jun 22, 2023

Also related is #1087 which will hopefully get rid of all the VResult machinery.

@byorgey byorgey added the C-Project A larger project, more suitable for experienced contributors. label Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug The observed behaviour is incorrect or unexpected. C-Project A larger project, more suitable for experienced contributors. G-REPL An issue having to do with the REPL. L-Type system Issues related to the Swarm language type system. S-Nice to have The bug fix or feature would be nice but doesn't currently have much negative impact. T-UI Involves the user interface.
Projects
None yet
Development

No branches or pull requests

2 participants