Skip to content

Commit

Permalink
[JVM] Make generics work with return type in sigs (#5080)
Browse files Browse the repository at this point in the history
This intends to port the changes to src/vm/moar/Perl6/Ops.nqp from
#5048 to the JVM backend.
  • Loading branch information
usev6 committed Oct 14, 2022
1 parent feb04db commit 4cdb558
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/vm/jvm/runtime/org/raku/rakudo/RakOps.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,34 @@ public static SixModelObject p6store(SixModelObject cont, SixModelObject value,
return cont;
}

private static final CallSiteDescriptor genIns = new CallSiteDescriptor(
new byte[] { CallSiteDescriptor.ARG_OBJ, CallSiteDescriptor.ARG_OBJ, CallSiteDescriptor.ARG_OBJ }, null);
private static final CallSiteDescriptor rvThrower = new CallSiteDescriptor(
new byte[] { CallSiteDescriptor.ARG_OBJ, CallSiteDescriptor.ARG_OBJ }, null);
public static SixModelObject p6typecheckrv(SixModelObject rv, SixModelObject routine, SixModelObject bypassType, ThreadContext tc) {
GlobalExt gcx = key.getGC(tc);
SixModelObject sig = routine.get_attribute_boxed(tc, gcx.Code, "$!signature", HINT_CODE_SIG);
SixModelObject rtype = sig.get_attribute_boxed(tc, gcx.Signature, "$!returns", HINT_SIG_RETURNS);
if (rtype != null) {
/* The return type could be generic. In that case we have
* to call instantiate_generic before doing the type check. */
SixModelObject HOW = rtype.st.HOW;
SixModelObject archetypesMeth = Ops.findmethod(HOW, "archetypes", tc);
Ops.invokeDirect(tc, archetypesMeth, Ops.invocantCallSite, new Object[] { HOW, rtype });
SixModelObject Archetypes = Ops.result_o(tc.curFrame);
SixModelObject genericMeth = Ops.findmethodNonFatal(Archetypes, "generic", tc);
if (genericMeth != null) {
Ops.invokeDirect(tc, genericMeth, Ops.invocantCallSite, new Object[] { Archetypes });
if (Ops.istrue(Ops.result_o(tc.curFrame), tc) == 1) {
SixModelObject ig = Ops.findmethod(HOW, "instantiate_generic", tc);
SixModelObject ContextRef = tc.gc.ContextRef;
SixModelObject cc = ContextRef.st.REPR.allocate(tc, ContextRef.st);
((ContextRefInstance)cc).context = tc.curFrame;
Ops.invokeDirect(tc, ig, genIns, new Object[] { HOW, rtype, cc });
rtype = Ops.result_o(tc.curFrame);
}
}

SixModelObject decontValue = Ops.decont(rv, tc);
if (Ops.istype(decontValue, rtype, tc) == 0) {
/* Straight type check failed, but it's possible we're returning
Expand Down

0 comments on commit 4cdb558

Please sign in to comment.