Returns a copy of this closure with refined parameter types. @param argTypes argument types @param cc compilation context @return original or refined closure @throws QueryException query exception @see FuncItem#refine(SeqType[], CompileContext)
(final SeqType[] argTypes, final CompileContext cc)
| 241 | * @see FuncItem#refine(SeqType[], CompileContext) |
| 242 | */ |
| 243 | public Expr refine(final SeqType[] argTypes, final CompileContext cc) throws QueryException { |
| 244 | // skip refinement if function has too many parameters |
| 245 | final int arity = arity(); |
| 246 | if(argTypes.length < arity) return this; |
| 247 | |
| 248 | // skip if no parameter type can be narrowed |
| 249 | boolean narrow = false; |
| 250 | for(int a = 0; a < arity; a++) { |
| 251 | final SeqType at = argTypes[a], pt = params[a].seqType(); |
| 252 | if(at.instanceOf(pt) && !at.eq(pt)) { |
| 253 | narrow = true; |
| 254 | break; |
| 255 | } |
| 256 | } |
| 257 | if(!narrow) return this; |
| 258 | |
| 259 | // clone the closure, narrow the cloned params, re-compile the body |
| 260 | final Closure copy = (Closure) copy(cc, new IntObjectMap<>()); |
| 261 | for(int a = 0; a < arity; a++) copy.params[a].refineType(argTypes[a], cc); |
| 262 | return copy.optimize(cc); |
| 263 | } |
| 264 | |
| 265 | @Override |
| 266 | public Expr inline(final InlineContext ic) throws QueryException { |
nothing calls this directly
no test coverage detected