You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Passing Instance through an Object Literal Causes a runtime error on exit #1272
So I noticed another thing weird with Object literals. If I try to pass a class into my init object, to construct my other class. Everything works fine, but when everything is done, the runtime will throw a memory error.
Here is the test case code:
import{Console}from"as-wasi";classOtherClass{stuff: i32;constructor(newStuff: i32){this.stuff=newStuff;}}classMyClassInit{otherClass: OtherClass;}classMyClass{_myParam: i32;_otherClass: OtherClass;constructor(param: i32,init: MyClassInit){this._myParam=param;this._otherClass=init.otherClass;}toString(): string{returnthis._otherClass.stuff.toString();}}exportfunction_start(): void{// Make our Other classletotherClass=newOtherClass(24);// Pass to my class as an object literalletmyClass=newMyClass(2424,{otherClass: otherClass});// This will all workConsole.log("Logging myClass.toString() ...\n");Console.log(myClass.toString());Console.log("\n");// Will Error on Exit// ~lib/rt/pure.ts:122:13: error: null}
cc @dcodeIO or @MaxGraey , if you can point me to where this would be fixed in the compiler (would this object literal be fixed in the same place as #1229 ), I can make this fix 😄
classOtherClass{stuff: i32;constructor(newStuff: i32){this.stuff=newStuff;}}classMyClassInit{otherClass: OtherClass;}classMyClass{_myParam: i32;_otherClass: OtherClass;constructor(param: i32,init: MyClassInit){this._myParam=param;this._otherClass=init.otherClass;}toString(): string{returnthis._otherClass.stuff.toString();}}functionstart(): void{// Make our Other classletotherClass=newOtherClass(24);// Pass to my class as an object literalletmyClass=newMyClass(2424,{otherClass: otherClass});trace("Logging myClass.toString() ...");trace(myClass.toString());}start();
Running this on master, with rtrace enabled, doesn't show any problems. Might this have been fixed since the last release?
Translated your example to this test case: ... Running this on master, with rtrace enabled, doesn't show any problems. Might this have been fixed since the last release?
So I tried installing the latest master with my example and it didn't work 😢
Looks fine from a runtime perspective, with the UB depending on the implementation of fd_write but even then not affecting the runtime.
I think your responding to Max here, but just in case: I don't think there's anything wrong with the Logging. Because I can totally add some more logs after my testing logs, or do whatever I need to do, and it's fine. I think we may have some dangling memory or something weird after the _start ends? 🤔
In my test, what might have happened is that since I'm not importing as-wasi, static memory contents differ in a way that the bug does not show. Will try to replicate it more closely.
Tried to compile your exact snippet using as-wasi from Git and AS master, but that doesn't compile due to
ERROR AS231: A class with a constructor explicitly returning something else than 'this' must be '@final'.
export class Descriptor {
~~~~~~~~~~
in ~lib/as-wasi/as-wasi.ts(91,14)
Are you sure you tried with master? I think you should have seen that error as well then.
Updating the snippet to AS 0.10.0 (incl. adding @final to Descriptor)
import"wasi";import{Console}from"as-wasi";classOtherClass{stuff: i32;constructor(newStuff: i32){this.stuff=newStuff;}}classMyClassInit{otherClass: OtherClass;}classMyClass{_myParam: i32;_otherClass: OtherClass;constructor(param: i32,init: MyClassInit){this._myParam=param;this._otherClass=init.otherClass;}toString(): string{returnthis._otherClass.stuff.toString();}}// Make our Other classletotherClass=newOtherClass(24);// Pass to my class as an object literalletmyClass=newMyClass(2424,{otherClass: otherClass});Console.log("Logging myClass.toString() ...\n");Console.log(myClass.toString());Console.log("\n");
Activity
dcodeIO commentedon May 14, 2020
Translated your example to this test case:
Running this on master, with rtrace enabled, doesn't show any problems. Might this have been fixed since the last release?
MaxGraey commentedon May 14, 2020
Hmm, I don't see any issues in browser (
--debugflag turned on):https://webassembly.studio/?f=xioif2ne2k
It could be problem with
wasmtimeoras-wasiand ConsoleMaxGraey commentedon May 14, 2020
@dcodeIO I guess need test with node.js and as-wasi for reproduce full picture.
Also could you check this function?
MaxGraey commentedon May 14, 2020
@torch2424 btw you use pretty old assemblyscript version in your playground: https://github.com/torch2424/as-playground/blob/master/object-literal-pass-instance/package-lock.json#L12
dcodeIO commentedon May 14, 2020
Looks fine from a runtime perspective, with the UB depending on the implementation of
fd_writebut even then not affecting the runtime.torch2424 commentedon May 14, 2020
Oh Wow that was fast haha! 😄 Thanks y'all!
@dcodeIO
So I tried installing the latest master with my example and it didn't work 😢
@MaxGraey
Two minors is old? 😂 But thanks for catching that! I updated to
0.9.4and still no dice 😢So I replaced out as-wasi and the console logging and it didn't work:
So It may be an issue with Wasmtime? Though, I originally found this bug running AS on Lucet 🤔
@dcodeIO
I think your responding to Max here, but just in case: I don't think there's anything wrong with the Logging. Because I can totally add some more logs after my testing logs, or do whatever I need to do, and it's fine. I think we may have some dangling memory or something weird after the
_startends? 🤔dcodeIO commentedon May 14, 2020
In my test, what might have happened is that since I'm not importing
as-wasi, static memory contents differ in a way that the bug does not show. Will try to replicate it more closely.dcodeIO commentedon May 14, 2020
Tried to compile your exact snippet using as-wasi from Git and AS master, but that doesn't compile due to
Are you sure you tried with master? I think you should have seen that error as well then.
dcodeIO commentedon May 14, 2020
Updating the snippet to AS 0.10.0 (incl. adding
@finaltoDescriptor)compiling with
and then running it in wasmtime v0.16.0
seems to work:
torch2424 commentedon May 15, 2020
@dcodeIO
Oh huh :o I installed from git using like the syntax of:
npm install --save https://git.assemblyscript ....Maybe that doesn't install master for you? 🤔
Just tested this, and yep,
0.10.0fixes this issue! 😄 👍 Thanks very much for making the release that fixed this by proxy haha! 😄 😂Closing this...