You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Runtime builtin functions that throw errors use aster_error_set() (untyped) instead of aster_error_set_typed(class_tag, value). This means .catch(SpecificError e) arms never match because aster_error_get_tag() returns 0, which doesn't correspond to any class ID.
The typechecker correctly declares these functions as throws SpecificError, so the type system thinks typed catching should work, but at runtime the tag is missing and the catch arm falls through to the wildcard or re-raises.
Root cause
FIR class IDs are assigned dynamically during lowering. Runtime functions are compiled Rust code that doesn't know these IDs. There's no mechanism to pass the class tag from the FIR layer to the runtime function.
Affected builtins
File.read() - declares throws IOError, uses aster_error_set() in codegen/src/runtime/fs.rs
File.write() - declares throws IOError, uses aster_error_set() in codegen/src/runtime/fs.rs
File.append() - declares throws IOError, uses aster_error_set() in codegen/src/runtime/fs.rs
process.run() - declares throws ProcessError, uses aster_error_set() in codegen/src/runtime/process.rs
Pre-register builtin error classes with sentinel ClassIds in Lowerer::new() (like FieldInfo uses u32::MAX) and hardcode those sentinels in the runtime functions. Simple but couples magic constants across layers.
Emit error-set inline in FIR: Runtime functions signal failure via a return convention, and FIR lowering emits aster_error_set_typed(tag, 0) at the call site where the class tag is known.
Pass the class tag as an argument to each throwing runtime function so it can call aster_error_set_typed(tag, value) itself. The FIR lowering supplies the tag at each call site.
Impact
Users who write .catch(IOError e) or .catch(IntParseError e) on runtime builtins will silently fail to match. Only wildcard catches (!.catch { ... }) and !.or(default) work correctly today.
Problem
Runtime builtin functions that throw errors use
aster_error_set()(untyped) instead ofaster_error_set_typed(class_tag, value). This means.catch(SpecificError e)arms never match becauseaster_error_get_tag()returns 0, which doesn't correspond to any class ID.The typechecker correctly declares these functions as
throws SpecificError, so the type system thinks typed catching should work, but at runtime the tag is missing and the catch arm falls through to the wildcard or re-raises.Root cause
FIR class IDs are assigned dynamically during lowering. Runtime functions are compiled Rust code that doesn't know these IDs. There's no mechanism to pass the class tag from the FIR layer to the runtime function.
Affected builtins
File.read()- declaresthrows IOError, usesaster_error_set()incodegen/src/runtime/fs.rsFile.write()- declaresthrows IOError, usesaster_error_set()incodegen/src/runtime/fs.rsFile.append()- declaresthrows IOError, usesaster_error_set()incodegen/src/runtime/fs.rsprocess.run()- declaresthrows ProcessError, usesaster_error_set()incodegen/src/runtime/process.rsInt.from()(new, Add to_int() stdlib function for string-to-integer conversion #44) - declaresthrows IntParseError, will useaster_error_set()Possible solutions
Pre-register builtin error classes with sentinel ClassIds in
Lowerer::new()(likeFieldInfousesu32::MAX) and hardcode those sentinels in the runtime functions. Simple but couples magic constants across layers.Emit error-set inline in FIR: Runtime functions signal failure via a return convention, and FIR lowering emits
aster_error_set_typed(tag, 0)at the call site where the class tag is known.Pass the class tag as an argument to each throwing runtime function so it can call
aster_error_set_typed(tag, value)itself. The FIR lowering supplies the tag at each call site.Impact
Users who write
.catch(IOError e)or.catch(IntParseError e)on runtime builtins will silently fail to match. Only wildcard catches (!.catch { ... }) and!.or(default)work correctly today.