-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
feat(stdlib): Convert runtime printing utils to @unsafe #1135
Conversation
let decimalCount32Dummy = (n: WasmI32) => 0n | ||
let utoa32BufferedDummy = (a: WasmI32, b: WasmI32, c: WasmI32) => void | ||
|
||
// When these boxes are backpatched, the reference count of each function will |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we maybe emit a warning or something when using boxes in --compilation-mode=runtime
? It seems like this could bite us
(not for this PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe? The plan is for only malloc.gr
and gc.gr
to use runtime mode, so it might not be necessary. But it's not really just a problem for boxes; it's for anything that gets allocated in runtime mode that gets mutated by things outside of the runtime.
I actually thought about a couple of solutions for this:
- The fake reference count of runtime objects is
1
; could just set it to0xefffffff
. While this would work, I'd be worried about some large program that could decRef enough that the problem would occur, and it'd be a hell of a time debugging that. - Could alter
free
to never free anything in runtime land. Actually fairly easy to implement with lowish perf overhead, though I dislike that the reference counts for runtime values would be essentially random. That's more of an aesthetic problem though since the count doesn't matter at all. - Disallow mutable boxes/arrays/record fields in runtime mode. That'd completely prevent this (which is handy) though of course we couldn't use those constructs (which isn't a big deal since we don't need them, but it'd prevent doing backrefs for debugging like this, etc.).
But also maybe this comment is fine 🤷
Up to you if you want to make an issue for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You know me, I'm always happy with issues where we can have a longer discussion!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor comment, but this looks 🔥
977a0aa
to
536ba56
Compare
0d68959
to
ee6fce8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice to see real Grain code back!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Awesome!
stdlib/runtime/numberUtils.gr
Outdated
@@ -936,101 +968,108 @@ export let utoa32Buffered = (buf, value, radix) => { | |||
} | |||
} | |||
|
|||
@unsafe | |||
export let utoa32 = (value, radix) => { | |||
if (WasmI32.ltS(radix, 2n) || WasmI32.gtS(radix, 36n)) { | |||
throw Exception.InvalidArgument( | |||
"toString() radix argument must be between 2 and 36" | |||
) | |||
} | |||
let str = if (WasmI32.eqz(value)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you just remove let str
here and at the end where you return it?
stdlib/runtime/numberUtils.gr
Outdated
} | ||
|
||
@unsafe | ||
export let utoa64 = (value, radix) => { | ||
if (WasmI32.ltS(radix, 2n) || WasmI32.gtS(radix, 36n)) { | ||
throw Exception.InvalidArgument( | ||
"toString() radix argument must be between 2 and 36" | ||
) | ||
} | ||
let str = if (WasmI64.eqz(value)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove this str
variable?
let decimalCount32Dummy = (n: WasmI32) => 0n | ||
let utoa32BufferedDummy = (a: WasmI32, b: WasmI32, c: WasmI32) => void | ||
|
||
// When these boxes are backpatched, the reference count of each function will |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You know me, I'm always happy with issues where we can have a longer discussion!
[], | ||
[...](String, StringList), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is 🔥 Love it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we have an issue about this somewhere that should be closed by this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably #552 but that's not quite ready to be closed.
536ba56
to
d8cbb65
Compare
ee6fce8
to
b6658e8
Compare
b6658e8
to
33952ba
Compare
The major thing to notice in this PR is that
runtime/numberUtils.gr
is no longer--compilation-mode=runtime
. This means that it uses regular allocated Grain memory, which means that string literals, etc. are allowed to be used. Ideally,malloc.gr
/gc.gr
/memory.gr
will be the only files in runtime mode.