@@ -39,6 +39,12 @@ In Tile IR codegen, only ghost types (zero-size immutables like `Val{V}`,
3939function emit_new! (ctx:: CGCtx , expr:: Expr , @nospecialize (result_type))
4040 T = CC. widenconst (result_type)
4141 is_ghost_type (T) && return ghost_value (T)
42+ # On older Julia versions, method errors are emitted as
43+ # %new(MethodError, func, args_tuple, world) instead of Core.throw_methoderror
44+ if T === MethodError
45+ # expr.args: (MethodError, func, args_tuple, world)
46+ _throw_method_error (ctx, expr. args[2 : end - 1 ])
47+ end
4248 throw (IRError (" Struct construction not supported in Tile IR: $T " ))
4349end
4450
@@ -103,7 +109,7 @@ function emit_call!(ctx::CGCtx, expr::Expr, @nospecialize(result_type))
103109 end
104110
105111 result = emit_intrinsic! (ctx, func, call_args)
106- result === missing && _unsupported_call (ctx, func, call_args)
112+ result === missing && _throw_method_error (ctx, [ func; call_args] )
107113 validate_result_type (result, result_type, func)
108114 return result
109115end
@@ -125,7 +131,7 @@ function emit_invoke!(ctx::CGCtx, expr::Expr, @nospecialize(result_type))
125131 end
126132
127133 result = emit_intrinsic! (ctx, func, call_args)
128- result === missing && _unsupported_call (ctx, func, call_args)
134+ result === missing && _throw_method_error (ctx, [ func; call_args] )
129135 validate_result_type (result, result_type, func)
130136 return result
131137end
@@ -138,7 +144,6 @@ Assert that the intrinsic returned a type compatible with what the IR expects.
138144function validate_result_type (@nospecialize (result), @nospecialize (expected_type), @nospecialize (func))
139145 result === nothing && return # void return
140146 result isa CGVal || return
141-
142147 actual = CC. widenconst (result. jltype)
143148 expected = CC. widenconst (expected_type)
144149
@@ -151,13 +156,15 @@ end
151156"""
152157 _throw_method_error(ctx, call_args)
153158
154- Provide a clear error message when Julia inserts a `throw_methoderror` call,
155- indicating that type inference found no matching method for a function call.
159+ Provide a clear error message when an unsupported function is encountered during
160+ Tile IR compilation, either from an explicit `throw_methoderror` / `MethodError`
161+ construction, or from a function call with no Tile IR intrinsic mapping.
162+
163+ `call_args` contains `(function, arg1, arg2, ...)`.
156164"""
157165function _throw_method_error (ctx:: CGCtx , call_args)
158- # call_args typically contains: (function, arg1, arg2, ...)
159166 if isempty (call_args)
160- throw (IRError (" MethodError during Tile IR compilation" ))
167+ throw (IRError (" Unsupported function call during Tile IR compilation" ))
161168 end
162169
163170 func_val = try
@@ -168,18 +175,7 @@ function _throw_method_error(ctx::CGCtx, call_args)
168175
169176 argtypes = argextype .(Ref (ctx), call_args[2 : end ])
170177 typestr = isempty (argtypes) ? " " : " with argument types ($(join (argtypes, " , " )) )"
171- throw (IRError (" MethodError during Tile IR compilation: no matching method for $func_val$typestr " ))
172- end
173-
174- """
175- _unsupported_call(ctx, func, call_args)
176-
177- Provide a clear error message when a function has no Tile IR intrinsic mapping.
178- """
179- function _unsupported_call (ctx:: CGCtx , @nospecialize (func), call_args)
180- argtypes = argextype .(Ref (ctx), call_args)
181- typestr = isempty (argtypes) ? " " : " with argument types ($(join (argtypes, " , " )) )"
182- throw (IRError (" Unsupported function call during Tile IR compilation: $func$typestr has no Tile IR equivalent" ))
178+ throw (IRError (" Unsupported function call during Tile IR compilation: $func_val$typestr has no Tile IR equivalent" ))
183179end
184180
185181"""
0 commit comments