Commit 1cf04e55 authored by Radford Neal's avatar Radford Neal

more eval optimizations regarding promises

parent b3a41a97
......@@ -759,7 +759,12 @@ static SEXP attribute_noinline evalv_sym (SEXP e, SEXP rho, int variant)
ret_grad = 1;
}
if (TYPEOF(res) == PROMSXP) {
if (TYPE_ETC(res) == PROMSXP + TYPE_ET_CETERA_VEC_DOTS_TR) {
/* forced promise, no gradient */
res = PRVALUE_PENDING_OK(res);
}
else if (TYPE_ETC(res) == PROMSXP) {
/* unforced promise, force here */
SEXP prom = res;
if (PRVALUE_PENDING_OK(prom) == R_UnboundValue)
res = forcePromiseUnbound(prom,variant);
......@@ -770,6 +775,16 @@ static SEXP attribute_noinline evalv_sym (SEXP e, SEXP rho, int variant)
ret_grad = 1;
}
}
else if (TYPE_ETC(res) ==
PROMSXP + TYPE_ET_CETERA_VEC_DOTS_TR + TYPE_ET_CETERA_HAS_ATTR) {
/* forced promise, with gradient */
SEXP prom = res;
res = PRVALUE_PENDING_OK(prom);
if (variant & VARIANT_GRADIENT) {
PROTECT (grad = ATTRIB(prom));
ret_grad = 1;
}
}
else if (TYPE_ETC(res) == SYMSXP) {
if (res == R_MissingArg) {
if ( ! (variant & VARIANT_MISSING_OK))
......@@ -918,29 +933,30 @@ static SEXP attribute_noinline evalv_other (SEXP e, SEXP rho, int variant)
WAIT_UNTIL_COMPUTED(res);
return res;
}
if (TYPE_ETC(e) ==
PROMSXP + TYPE_ET_CETERA_VEC_DOTS_TR + TYPE_ET_CETERA_HAS_ATTR) {
/* forced promise, with gradient */
res = PRVALUE_PENDING_OK(e);
if (variant & VARIANT_GRADIENT) {
if (TYPE_ETC(e) == PROMSXP) {
/* unforced promise, force here */
res = forcePromiseUnbound(e,variant);
if ((variant & VARIANT_GRADIENT) && HAS_ATTRIB(e)) {
R_variant_result = VARIANT_GRADIENT_FLAG;
R_gradient = ATTRIB(e);
}
if ( ! (variant & VARIANT_PENDING_OK))
WAIT_UNTIL_COMPUTED(res);
R_Visible = TRUE;
return res;
}
if (TYPE_ETC(e) == PROMSXP) { /* unforced promise, force here */
res = forcePromiseUnbound(e,variant);
if ((variant & VARIANT_GRADIENT) && HAS_ATTRIB(e)) {
if (TYPE_ETC(e) ==
PROMSXP + TYPE_ET_CETERA_VEC_DOTS_TR + TYPE_ET_CETERA_HAS_ATTR) {
/* forced promise, with gradient */
res = PRVALUE_PENDING_OK(e);
if (variant & VARIANT_GRADIENT) {
R_variant_result = VARIANT_GRADIENT_FLAG;
R_gradient = ATTRIB(e);
}
if ( ! (variant & VARIANT_PENDING_OK))
WAIT_UNTIL_COMPUTED(res);
R_Visible = TRUE;
return res;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment