-
Notifications
You must be signed in to change notification settings - Fork 26
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
Improved printing support #380
Conversation
the error doesn't seem to have anything to do with this PR. The error detected by the CI server is related to the ParTs. Reviews of this PR should be done with care (just in case) |
I am not sure why the CI printed this error:
As I said, the reviewer of this PR should proceed with caution. ParTs have produced an error but the error mentioned above was raised in the same build |
No, that's me being sloppy... Had forgotten a type annotation in the test. Should be working now! |
I have tested this and it works on my machine and the tests pass and the code looks pretty :) |
It's unclear to me why printing closure and other things are disabled, while printing future is allowed. IMO, having pointer address is good default for Should The code for printing The type change in It's better to limit touched/new lines below 80 columns, IMO. |
My motivation was that futures are objects (values) while closures are functions. The concept of identity (which is what we would print) makes sense for a future, but not for a function. We could print the address of the closure, but if someone ever decides to rely on this printing, we would lose possible optimization opportunities of for example reusing equivalent closures. Printing polymorphic values breaks the polymorphic abstraction. Just as you cannot (or at least should not be able to) compare the equality of two polymorphic values (because you can't be sure that there is a well-defined notion of equality for the actual type), you shouldn't be able to print a polymorphic value. If you need it for debugging purposes, you can embed the pointer and print it.
Yes! Fixing now.
Yes, it's a bit complex... The problem with implementing it on the encore level is that we have no polymorphic functions. We would need a printing function of type
I think they worked, but probably through typecasting somehow. This makes more sense anyway!
Maybe I was a bit sloppy. Fixing this with the |
Fixed |
I disagree about the comment on printing closures. Printing a closure is printing its string representation; it could be its identity or source code. Either is fine, but disallowing printing of closures is unreasonable, IMO. p = console.log
f = () -> 1
p f
p "#{f}"
I don't think this is similar or equivalent to equality, just like Yes, indeed, need dynamic dispatch to implement printing |
This commit improves the printing support and fixes #352 and fixes #320. The following list summarizes the current printing behavior: * Reference types `T` are printed as `T@0x012345`, where the hexadecimal value is the address of the object. The same thing goes for futures, streams, arrays, ParTs and closures. `null` is printed as `T@0x0`. * Values whose type isn't statically known cannot be printed. This includes any polymorphic values. * Values of embedded types cannot be printed. You can (and should) drop down to C if you really need to print such a value (or closures or polymorphic values for that matter). * Ranges are printed as `[1..10 by 1]`. The `by` part is always included for simplicity. * Maybe types are printed like they should, although the generated code is a bit nasty. For each maybe type, a string is allocated for the sole purpose of being printed. The length of this string is approximated by summing approximations of the lengths of all subexpressions. Strings use their dynamic lengths and tuples the sum of the approximations of their contents. All other lengths are approximated as the length of their type plus 30 (compare with how reference types are printed). The 30 should be enough to hold any addresses, integers or reals. It would be better to calculate a maximum depending on the type, but if you're doing things like printing `Maybe`s, you probably don't care about performance anyway. * Tuples are also printed like they should, and since their shape is known statically, the code isn't as bad. * Values of `void` type are always printed as `()` * Strings, chars, ints, booleans and reals are printed like you would expect. The only news here is proper printing of booleans as `true` and `false`. The existing tests already test much of the printing, and some of them have been updated to align with the new syntax. The test `printf` tests some of the new printing. Testing this has reminded me that the lack of proper inference for `null` and `bottom` is annoying, but fixing this does not belong in this PR.
Reluctantly added support for printing closures... ;) |
For record purpose, I am the one who insisted in adding the closure-printing features. |
For the record. I agree with @albertnetymk that printing closures is pretty nice! |
This commit improves the printing support and fixes #352 and fixes #320.
The following list summarizes the current printing behavior:
T
are printed asT@0x012345
, where the hexadecimalvalue is the address of the object. The same thing goes for futures,
streams, arrays and ParT-values.
null
is printed asT@0x0
.includes any polymorphic values.
down to C if you really need to print such a value (or closures or
polymorphic values for that matter).
[1..10 by 1]
. Theby
part is always includedfor simplicity.
is a bit nasty. For each maybe type, a string is allocated for the
sole purpose of being printed. The length of this string is
approximated by summing approximations of the lengths of all
subexpressions. Strings use their dynamic lengths and tuples the sum
of the approximations of their contents. All other lengths are
approximated as the length of their type plus 30 (compare with how
reference types are printed). The 30 should be enough to hold any
addresses, integers or reals. It would be better to calculate a
maximum depending on the type, but if you're doing things like
printing
Maybe
s, you probably don't care about performance anyway.known statically, the code isn't as bad.
void
type are always printed as()
expect. The only news here is proper printing of booleans as
true
and
false
.The existing tests already test much of the printing, and some of them
have been updated to align with the new syntax. The test
printf
testssome of the new printing.
Testing this has reminded me that the lack of proper inference for
null
andbottom
is annoying, but fixing this does not belong in thisPR.