# New Ticket Created by "Carl Mäsak" # Please include the string: [perl #75376] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=75376 >
<masak> rakudo: my class A {}; our class B is A {} # via jnthn++ <p6eval> rakudo 982e8e: OUTPUT«Lexical 'A' not foundcurrent instr.: 'perl6;B;!class_init_11' pc 476 (EVAL_1:212)» * masak submits rakudobug The thinking about this issue can be found in the backlog: 00:41 jnthn my class Foo { }; our class Bar is Foo { } # oh noes. 00:42 This explodes now and I don't have a good way to fix it. 00:42 Because right now, my class Foo gets installed into the lexpad just like we install subs, etc. 00:42 pmichaud protolexpads would help, or we need a way to invoke a sub such that we keep the lexpad that has already been created for it 00:42 jnthn Whereas our Bar gets set up in the loadinit 00:42 Which happens...before Foo 00:42 pmichaud instead of creating a new one 00:43 anyway, I have two knee-jerk reactions 00:43 (1) making things happen more like BEGIN brings us closer to the right way of doing things (i.e., I'd think that using phasers is better than :loadinit) 00:44 (2) I don't see that moving :loadinit to phasers really solves the problem (but perhaps you've thought of something I haven't there) 00:45 jnthn pmichaud: You may be right on (2). At least it's not the only thing that will need doing. 00:45 pmichaud: Maybe I should spend the tuits on protolexpad-ish stuff instead. 00:45 pmichaud the problem is really Parrot's model of lexpads 00:46 jnthn Aye, it's not quite what we want. 00:46 pmichaud from a Parrot perspective, the symbol Foo doesn't get bound until the scope containing Foo is invoked 00:46 i.e., the lexpad entry for Foo doesn't exist until the outer scope is invoked 00:47 it's easier to imagine with something like: 00:47 sub xyz() { my class Foo { }; our class Bar is Foo { } } 00:47 jnthn Well, it affects the mainline too 00:48 But yes, that's pretty much it. 00:48 pmichaud the mainline is just another scope, yes. 00:48 and from a Parrot perspective, the lexical symbols in the mainline don't really exist before the mainline is invoked 00:48 sorear in a perl6 model, lexpads are cloned 00:48 we can do that with a custom lexinfo 00:48 I think 00:49 jnthn sorear: Last time I worked through what it might take, I think I maybe ended up with us needing a custom Sub too, but it may be avoidable. 00:49 pmichaud let me look again 00:49 just a sec 00:49 jnthn I'd *really* like to see if we couldn't put this mess to bed at least somewhat ahead of R* though. It's kinda...embarassing. 00:49 pmichaud Personally, I'm not too concerned if one can't mix lexical and packaged scoped classes in R* 00:50 maybe I should be... but I'm not. 00:50 jnthn pmichaud: I didn't mean that specific example. I meant the whole plethora of issues. 00:50 like 00:50 rakudo: my role Foo { method lol { say 42 } }; Foo.lol # fine 00:50 p6eval rakudo edb448: OUTPUT«42» 00:50 jnthn rakudo: our role Foo { method lol { say 42 } }; Foo.lol # not 00:50 p6eval rakudo edb448: OUTPUT«42» 00:50 jnthn ...oh. 00:51 oh, I know what's not 00:51 spinclad would one want a wall to prevent such mixed times, or delay class Bar till Foo is ready? 00:51 pugssvn r30828 | sorear++ | [viv] Implement basic signature translation 00:51 jnthn rakudo: role Foo { method lol { say 42 } }; class Bar does Foo { }; Bar.lol 00:51 p6eval rakudo edb448: OUTPUT«Could not find sub &saycurrent instr.: 'lol' pc 563 (EVAL_1:217)» 00:51 jnthn That one. 00:51 pmichaud technically, Foo can be ready at BEGIN time also, as long as we have a way to bind it into the lexpad at runtime 00:52 plobsing joined #perl6 00:52 jnthn This happens because when you do a role, it has to go and clone the role body. 00:52 And thus its methods 00:52 (for type parameters to be captured) 00:52 And if that happens from within a callchain involving loadinit, we appear to be in a mess. 00:53 pmichaud: Yes, that would be ideal. 00:54 * lue can only hope to aspire to your level of knowledge of rakudo/perl6 someday. 00:55 jnthn lue: Needs time, minor loss of sanity, beer and hanging around here soaking up the knowledge of @other. :-) 00:55 jaldhar joined #perl6 00:55 spinclad lue: you need not just hope; you may fully aspire 00:55 pmichaud sorear: custom lexinfo is a good idea... we'd also need custom lexpads 00:55 jnthn (Or tht's how I did it. :-)) 00:56 The only reason I think we may be able to get away with Sub also being custom is that lexpad when created gets the lexinfo. 00:56 lue [and a well-detailed spec :P] 00:56 jnthn If we can hang the "pernament stuff" in the lexinfo perhaps... 00:56 ...then the lexpad on creation and copy those things into itself. 00:56 s/and/can/ 00:56 pmichaud well, the Sub doesn't actually use the lexinfo directly -- it just passes the lexinfo to the lexpad when it's created 00:56 jnthn pmichaud: Yes. 00:57 pmichaud so, it'd have to be a custom lexpad to be able to do something different with the custom lexinfo 00:57 jnthn pmichaud: My worry was more that we'd need something to trigger the clone of the stuff we already knew. 00:57 pmichaud oh, I think that would just be OurLexPad.new that does that 00:57 i.e., our custom LexPad would have a custom init_pmc 00:57 jnthn pmichaud: But I suspect between a custom lexinfo and custom lexpad, we don't need a custom sub. 00:58 pmichaud it would be tricky because the LexPad doesn't learn about its context until a subsequent step after it's been created 00:58 so we'd have to create the LexPad, and then trigger any cloning as part of the set_pointer 00:59 i.e., when we attach a context to the LexPad, *then* it could start populating the context with the items from the LexInfo 00:59 if (!PMC_IS_NULL(sub->lex_info)) { 00:59 Parrot_pcc_set_lex_pad(INTERP, context, Parrot_pmc_new_init(INTERP, 00:59 Parrot_get_ctx_HLL_type(INTERP, enum_class_LexPad), 00:59 sub->lex_info)); 00:59 VTABLE_set_pointer(INTERP, Parrot_pcc_get_lex_pad(INTERP, context), context); 00:59 } 00:59 sorear lue: try aspiring to my level of understanding 00:59 jnthn pmichaud: ah yes 00:59 But that's do-able. 01:00 If messy. 01:00 pmichaud not sure I'd want to do this for R*, though. 01:00 tough call. 01:00 jnthn Worth prototyping in a branch perhaps? 01:00 pmichaud were you able to move our existing BEGINs to phasers yet? 01:00 jnthn No, that's high on my todo list. 01:01 pmichaud or does this affect that directly? 01:01 jnthn No, it's not related to that. 01:01 pmichaud I think I'd want to see BEGINs as true phasers first. 01:01 jnthn I brought this up because I just ran into it yet again. 01:01 In a sense, the proto lex pad thing may well be the real fix we need 01:01 And doing everything else as phasers could come later 01:01 I'm not sure. 01:01 pmichaud I think moving BEGIN to be phasers will tell us a lot, though.