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

nqp-JS is broken on master #656

Open
nwc10 opened this issue Aug 16, 2020 · 3 comments
Open

nqp-JS is broken on master #656

nwc10 opened this issue Aug 16, 2020 · 3 comments
Labels
BLOCKER Preventing the next release of NQP, or just needing attention before the release JavaScript

Comments

@nwc10
Copy link
Contributor

nwc10 commented Aug 16, 2020

nqp-JS won't build on master, even with the fix from #655

The build was unintentionally broken by

commit d2a35ac5ac3a3c8a5d5f80bd0ed8e2330d660559
Date:   Fri Jul 31 18:06:21 2020 +0200

    Add a HLL::SysConfig class

    This class acts as a central point where configuration information is
    stored. The class should only ever be accessed via
    `nqp::gethllsym('default', 'SysConfig')`. This then allows the class to be
    overridden by a subclass.

 src/HLL/Compiler.nqp                       | 40 +++++-------------------------
 src/HLL/SysConfig.nqp                      | 38 ++++++++++++++++++++++++++++
 src/NQP/Compiler.nqp                       |  1 -
 src/vm/moar/HLL/Backend.nqp                |  2 +-
 tools/templates/Makefile-backend-common.in | 10 +++++---
 tools/templates/Makefile-common.in         |  1 +
 6 files changed, 53 insertions(+), 39 deletions(-)

The commit looks sensible, and seems only to move code around, but this is enough to break the nqp-JS build. From trying to diagnose the problem and find a fix, I think that part of the problem is that this change exposes that gen/js/stage2/NQPHLL.nqp was not actually being built correctly. In master, the MoarVM equivalent ends

# From gen/moar/stage2/nqp-config.nqp

sub hll-config($config) {
    $config<version>         := '2020.07-8-gd2a35ac5a';
    $config<prefix>          := '/home/nick/Sandpit/moar-Og';
    $config<static-nqp-home> := '/home/nick/Sandpit/moar-Og/share/nqp';
    $config<nqp-home>        := '/home/nick/Sandpit/moar-Og/share/nqp';
    $config<libdir>          := '/home/nick/Sandpit/moar-Og/share/nqp/lib';
    $config<source-digest>   := '6101801815a41757e20f95dedd4bcd57b0c51327';
}

but the JS version did not. However, gen/moar/stage2/NQP.nqp does not have this, but the JS equivalent does.

Hence, it was looking like the fix might be this:

diff --git a/tools/build/gen-js-makefile.nqp b/tools/build/gen-js-makefile.nqp
index e1cc85c25..14d3279b4 100644
--- a/tools/build/gen-js-makefile.nqp
+++ b/tools/build/gen-js-makefile.nqp
@@ -195,11 +195,11 @@ constant('JS_NQP_SOURCES', '$(COMMON_NQP_SOURCES)');



-my $nqp-combined := combine(:stage(2), :sources('$(JS_NQP_SOURCES)'), :file('$(NQP_COMBINED)'), :gen-version(1));
+my $nqp-combined := combine(:stage(2), :sources('$(JS_NQP_SOURCES)'), :file('$(NQP_COMBINED)'));

 constant('JS_HLL_SOURCES', nfp('src/vm/js/HLL/Backend.nqp') ~ ' $(COMMON_HLL_SOURCES)');

-my $hll-combined := combine(:stage(2), :sources('$(JS_HLL_SOURCES)'), :file('$(HLL_COMBINED)'));
+my $hll-combined := combine(:stage(2), :sources('$(JS_HLL_SOURCES)'), :file('$(HLL_COMBINED)'), :gen-version(1));


Sadly that doesn't fix it. The master build fails like this:

/home/nick/Perl/nqp/nqp-m --module-path gen/js/stage1 src/vm/js/bin/cross-compile.nqp --setting=NQPCORE --target=mbc --js-output nqp-js-on-js/NQPP5QRegex.js --output /home/nick/Perl/nqp/gen/js/stage2/NQPP5QRegex.moarvm --no-regex-lib /home/nick/Perl/nqp/gen/js/stage2/NQPP5QRegex.nqp > nqp-js-on-js/NQPP5QRegex.js
Cannot invoke this object (REPR: Null; VMNull)
   at /home/nick/Perl/nqp/gen/js/stage2/NQPHLL.nqp:2097  (/home/nick/Perl/nqp/gen/js/stage2/NQPHLL.moarvm:BUILD)
 from /home/nick/Perl/nqp/gen/js/stage2/NQPCORE.setting.nqp:695  (/home/nick/Perl/nqp/gen/js/stage2/NQPCORE.setting.moarvm:BUILDALL)
 from /home/nick/Perl/nqp/gen/js/stage2/NQPCORE.setting.nqp:630  (/home/nick/Perl/nqp/gen/js/stage2/NQPCORE.setting.moarvm:bless)
 from /home/nick/Perl/nqp/gen/js/stage2/NQPCORE.setting.nqp:702  (/home/nick/Perl/nqp/gen/js/stage2/NQPCORE.setting.moarvm:new)
 from /home/nick/Perl/nqp/gen/js/stage2/NQPHLL.nqp:1  (/home/nick/Perl/nqp/gen/js/stage2/NQPHLL.moarvm:<mainline>)
 from <unknown>:1  (/home/nick/Perl/nqp/gen/js/stage2/NQPHLL.moarvm:<load>)
 from src/vm/moar/ModuleLoader.nqp:47  (/home/nick/Perl/nqp/ModuleLoader.moarvm:)
 from src/vm/moar/ModuleLoader.nqp:40  (/home/nick/Perl/nqp/ModuleLoader.moarvm:load_module)
 from gen/moar/stage2/NQP.nqp:271  (nqp.moarvm:load_module)
 from gen/moar/stage2/NQP.nqp:2461  (nqp.moarvm:statement_control:sym<use>)
 from gen/moar/stage2/QRegex.nqp:1587  (/home/nick/Perl/nqp/QRegex.moarvm:!cursor_pass)
 from <unknown>:1  (nqp.moarvm:statement_control:sym<use>)
 from gen/moar/stage2/QRegex.nqp:1676  (/home/nick/Perl/nqp/QRegex.moarvm:!protoregex)
 from <unknown>:1  (nqp.moarvm:statement_control)
 from gen/moar/stage2/NQP.nqp:978  (nqp.moarvm:statement)
 from <unknown>:1  (nqp.moarvm:statementlist)
 from gen/moar/stage2/NQP.nqp:945  (nqp.moarvm:comp_unit)
 from gen/moar/stage2/NQP.nqp:806  (nqp.moarvm:TOP)
 from gen/moar/stage2/QRegex.nqp:2258  (/home/nick/Perl/nqp/QRegex.moarvm:parse)
 from gen/moar/stage2/NQPHLL.nqp:2297  (/home/nick/Perl/nqp/NQPHLL.moarvm:parse)
 from gen/moar/stage2/NQPHLL.nqp:2213  (/home/nick/Perl/nqp/NQPHLL.moarvm:execute_stage)
 from gen/moar/stage2/NQPHLL.nqp:2248  (/home/nick/Perl/nqp/NQPHLL.moarvm:run)
 from gen/moar/stage2/NQPHLL.nqp:2244  (/home/nick/Perl/nqp/NQPHLL.moarvm:)
 from gen/moar/stage2/NQPHLL.nqp:2240  (/home/nick/Perl/nqp/NQPHLL.moarvm:compile)
 from gen/moar/stage2/NQPHLL.nqp:1915  (/home/nick/Perl/nqp/NQPHLL.moarvm:eval)
 from gen/moar/stage2/NQPHLL.nqp:2150  (/home/nick/Perl/nqp/NQPHLL.moarvm:evalfiles)
 from gen/moar/stage2/NQPHLL.nqp:2110  (/home/nick/Perl/nqp/NQPHLL.moarvm:command_eval)
 from gen/moar/stage2/NQPHLL.nqp:2035  (/home/nick/Perl/nqp/NQPHLL.moarvm:command_line)
 from src/vm/js/bin/cross-compile.nqp:50  (<ephemeral file>:MAIN)
 from src/vm/js/bin/cross-compile.nqp:1  (<ephemeral file>:<mainline>)
 from gen/moar/stage2/NQPHLL.nqp:1945  (/home/nick/Perl/nqp/NQPHLL.moarvm:eval)
 from gen/moar/stage2/NQPHLL.nqp:2150  (/home/nick/Perl/nqp/NQPHLL.moarvm:evalfiles)
 from gen/moar/stage2/NQPHLL.nqp:2080  (/home/nick/Perl/nqp/NQPHLL.moarvm:command_eval)
 from gen/moar/stage2/NQPHLL.nqp:2035  (/home/nick/Perl/nqp/NQPHLL.moarvm:command_line)
 from gen/moar/stage2/NQP.nqp:4176  (nqp.moarvm:MAIN)
 from gen/moar/stage2/NQP.nqp:1  (nqp.moarvm:<mainline>)
 from <unknown>:1  (nqp.moarvm:<main>)
 from <unknown>:1  (nqp.moarvm:<entry>)
Makefile:836: recipe for target '/home/nick/Perl/nqp/gen/js/stage2/NQPP5QRegex.moarvm' failed
make: *** [/home/nick/Perl/nqp/gen/js/stage2/NQPP5QRegex.moarvm] Error 1

With the above diff, the build instead fails like this:

./nqp-js-cross --target=js --shebang /home/nick/Perl/nqp/gen/js/stage2/NQP.nqp > nqp-js-on-js/nqp-bootstrapped.js
+++ Compiling MOAR default runner
306.26user 8.81system 3:59.42elapsed 131%CPU (0avgtext+0avgdata 288092maxresident)k
0inputs+269944outputs (0major+1502415minor)pagefaults 0swaps
/home/nick/Perl/nqp/src/vm/js/nqp-runtime/runtime.js:201
          throw e;
          ^

TypeError: Cannot read property '$$decont' of undefined
    at CodeRef.cuid216 (/home/nick/Perl/nqp/nqp-js-on-js/NQPHLL.js:19610:42)
    at CodeRef.$$call (/home/nick/Perl/nqp/src/vm/js/nqp-runtime/code-ref.js:88:26)
    at ObjConstructor.$$call (/home/nick/Perl/nqp/src/vm/js/nqp-runtime/sixmodel.js:210:29)
    at CodeRef.cuid53 (/home/nick/Perl/nqp/nqp-js-on-js/NQPCORE.setting.js:1692:71)
    at ObjConstructor.$$call (/home/nick/Perl/nqp/src/vm/js/nqp-runtime/sixmodel.js:210:29)
    at ObjConstructor.proto.(anonymous function) [as p6$BUILDALL] (/home/nick/Perl/nqp/src/vm/js/nqp-runtime/sixmodel.js:297:30)
    at CodeRef.cuid52 (/home/nick/Perl/nqp/nqp-js-on-js/NQPCORE.setting.js:4694:85)
    at ObjConstructor.$$call (/home/nick/Perl/nqp/src/vm/js/nqp-runtime/sixmodel.js:210:29)
    at ObjConstructor.proto.(anonymous function) [as p6$bless] (/home/nick/Perl/nqp/src/vm/js/nqp-runtime/sixmodel.js:297:30)

like 19610 of NQPHLL.js is the second /*await*/ in this:

cuid216.setInfo(cuid330,/*async*/ function cuid216(caller_ctx,_NAMED,param578) {
var TMP1,
TMP2,
TMP3,
TMP4,
TMP5,
TMP6,
TMP7,
TMP8,
TMP9,
TMP10,
TMP11,
TMP12,
TMP13;
var p6$____lowered__lex__604$local = nqp.Null,
p6$____lowered__lex__603$local = nqp.Null,
p6$defined__7$local = nqp.Null,
p6$____lowered__lex__602$local;
let ctx1 = this.getOuterCtx().$$outer;
var ctx577 = new nqp.Ctx(caller_ctx, this.getOuterCtx(), this);
if (_NAMED !== null) {nqp.noNamed(_NAMED)}
if (arguments.length > 3) nqp.tooManyPos(arguments.length, 3);if (arguments.length < 3) nqp.tooFewPos(arguments.length, 3);p6$____lowered__lex__602$local = nqp.arg(HLL, param578);
TMP1 = nqp.hash();
(/*await*/ p6$____lowered__lex__602$local.$$decont(ctx577)).$$bindattr(wval32, "%!build-config", TMP1);
/*await*/ (/*await*/ ctx1["&hll-config"].$$decont(ctx577)).$$call(ctx577,null,(/*await*/ p6$____lowered__lex__602$local.$$decont(ctx577)).$$getattr(wval32, "%!build-config"));
if ((/*await*/ (/*await*/ new nqp.NQPInt((((/*await*/ nqp.toStr(nqp.op.backendconfig().$$atkey("osname"), ctx577)) == "MSWin32") ? 1 : 0)).$$decont(ctx577)).$$toBool(ctx577))) {
TMP2 = new nqp.NQPStr("\\");
} else {
TMP2 = new nqp.NQPStr("/");
}
(/*await*/ p6$____lowered__lex__602$local.$$decont(ctx577)).$$bindattr(wval32, "$!path-sep", TMP2);
TMP3 = (p6$____lowered__lex__604$local = (new nqp.NQPStr(nqp.op.execname())));
;

which I can see generated code from the BUILD method here:

class HLL::SysConfig {
    has %!build-config;
    has $!nqp-home;
    has $!path-sep;

    method BUILD() {
        %!build-config := nqp::hash();
        hll-config(%!build-config);

        $!path-sep := nqp::backendconfig<osname> eq 'MSWin32' ?? '\\' !! '/';

        # Determine NQP home
#?if jvm
        # TODO could be replaced by nqp::execname() after the next bootstrap for JVM
        my $execname := nqp::atkey(nqp::jvmgetproperties,'nqp.execname') // '';
#?endif
#?if !jvm
        my $execname := nqp::execname();
#?endif
        my $install-dir := $execname eq ''
            ?? %!build-config<prefix>
            !! nqp::substr($execname, 0, nqp::rindex($execname, $!path-sep, nqp::rindex($execname, $!path-sep) - 1));

        $!nqp-home := nqp::getenvhash<NQP_HOME>
            // %!build-config<static-nqp-home>
            || $install-dir ~ '/share/nqp';
        if nqp::substr($!nqp-home, nqp::chars($!nqp-home) - 1) eq $!path-sep {
            $!nqp-home := nqp::substr($!nqp-home, 0, nqp::chars($!nqp-home) - 1);
        }
    }

    method path-sep() { $!path-sep }

    method nqp-build-config() { %!build-config }

    method nqp-home() { $!nqp-home }
}

added by the culprit commit d2a35ac

However, I don't know enough to know whether there is something subtle missing from the NQP code to cope with the fact that nqq-JS is a cross compiler, or if there is a bug in nqp-JS, or simply if this hits someting "Not Yet Implemented" in nqp-JS.

So I don't know how to continue.

@patrickbkr
Copy link
Member

@pmurias Maybe you can give some insight with this issue?

@Altai-man Altai-man added the BLOCKER Preventing the next release of NQP, or just needing attention before the release label Aug 18, 2020
@nwc10
Copy link
Contributor Author

nwc10 commented Aug 18, 2020

"I'm new round here" so I may not be the best judge of these things, but I wouldn't consider this bug to be a "blocker", given that the JS build has been broken since February and no-one had noticed or reported it until now.

@Altai-man
Copy link
Member

Well, maybe someone will find some time to look into it now and if not, a label always can be ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BLOCKER Preventing the next release of NQP, or just needing attention before the release JavaScript
Projects
None yet
Development

No branches or pull requests

3 participants