@@ -842,25 +842,41 @@ impl LiftIntrinsic {
842842
843843 let liftResults;
844844 if (knownLen !== undefined) {{ // list with known length
845-
846845 if (ctx.useDirectParams) {{
847- // list with known length w/ direct params
848- const dataPtr = ctx.params[0];
849- ctx.params = ctx.params.slice(1);
850-
851- // TODO(???): is it possible for all values to come in from params?
846+ if (ctx.memory === null) {{
847+ // If this lift should be using direct params,
848+ // and the memory is missing, we are in the case where
849+ // a fixed length list (or other value) is being passed only
850+ // via parameters to the function.
851+ //
852+ // Normally, we would expect to use the direct parameters as a
853+ // memory location + size, but in this case, *all* values are being passed directly,
854+ // via params.
855+ //
856+ {debug_log_fn}('memory unexpectedly missing while lifting unknown length list', {{ ctx }});
857+ liftResults = [ctx.params.slice(0, knownLen), ctx];
858+ ctx.params = ctx.params.slice(knownLen);
859+ }} else {{
860+ // in-memory list with unknown length w/ direct params
861+ const dataPtr = ctx.params[0];
862+ ctx.params = ctx.params.slice(1);
863+
864+ ctx.useDirectParams = false;
865+ const originalPtr = ctx.storagePtr;
866+ ctx.storageLen = knownLen * elemSize32;
867+
868+ liftResults = readValuesAndReset(ctx, originalPtr, dataPtr, knownLen);
869+
870+ ctx.useDirectParams = true;
871+ ctx.storagePtr = undefined;
872+ ctx.storageLen = undefined;
873+ }}
874+ }} else {{ // indirect params
875+ if (ctx.memory === null) {{
876+ {debug_log_fn}('memory unexpectedly missing while lifting known length list', {{ knownLen, ctx }});
877+ throw new Error(`memory missing while lifting known length (${{knownLen}}) list`);
878+ }}
852879
853- ctx.useDirectParams = false;
854- const originalPtr = ctx.storagePtr;
855- ctx.storageLen = knownLen * elemSize32;
856-
857- liftResults = readValuesAndReset(ctx, originalPtr, dataPtr, knownLen);
858-
859- ctx.useDirectParams = true;
860- ctx.storagePtr = null;
861- ctx.storageLen = null;
862-
863- }} else {{
864880 ctx.storageLen = knownLen * elemSize32;
865881 liftResults = readValuesAndReset(ctx, null, ctx.storagePtr, knownLen);
866882 }}
@@ -880,8 +896,8 @@ impl LiftIntrinsic {
880896 liftResults = readValuesAndReset(ctx, originalPtr, dataPtr, len);
881897
882898 ctx.useDirectParams = true;
883- ctx.storagePtr = null ;
884- ctx.storageLen = null ;
899+ ctx.storagePtr = undefined ;
900+ ctx.storageLen = undefined ;
885901
886902 }} else {{
887903 // unknown length list ptr w/ in-memory params
0 commit comments