fix(llvm): String/Plugin return value handling improvements by ChatGPT
Major fixes for LLVM backend string and plugin return value handling: 1. MIR Type Annotations: - Added StringBox method return types (substring/concat/replace/trim/toUpper/toLower) - Enhanced type inference for BoxCall operations 2. LLVM BinOp String Concatenation: - Added safe handle-to-pointer conversion paths - Support for ptr+i64 and i64+ptr concatenation patterns - Uses nyash.string.concat_hh for handle-based concatenation 3. ExternCall Selection: - Smart selection between C string (i8*) and handle (i64) variants - Improved print/log function selection based on argument types 4. StringBox Fast-path Optimization: - Direct AOT concatenation for StringBox.concat - Bypasses plugin path for better performance 5. Consistent String Representation: - AOT uses i8* (C string) as primary representation - Handles used for print/concat auxiliary paths 6. Build Fix: - Removed duplicate plugin.rs to resolve nyrt build conflicts Results: LLVM plugin return smoke tests now pass (NYASH_LLVM_PLUGIN_RET_SMOKE=1) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -117,6 +117,13 @@ impl MirBuilder {
|
||||
("StringBox", "length") | ("StringBox", "len") => Some(super::MirType::Integer),
|
||||
("StringBox", "is_empty") => Some(super::MirType::Bool),
|
||||
("StringBox", "charCodeAt") => Some(super::MirType::Integer),
|
||||
// String-producing methods (important for LLVM ret handling)
|
||||
("StringBox", "substring")
|
||||
| ("StringBox", "concat")
|
||||
| ("StringBox", "replace")
|
||||
| ("StringBox", "trim")
|
||||
| ("StringBox", "toUpper")
|
||||
| ("StringBox", "toLower") => Some(super::MirType::String),
|
||||
("ArrayBox", "length") => Some(super::MirType::Integer),
|
||||
_ => None,
|
||||
};
|
||||
@ -854,7 +861,8 @@ impl MirBuilder {
|
||||
self.value_origin_newbox.insert(dst, class.clone());
|
||||
|
||||
// For plugin/builtin boxes, call birth(...). For user-defined boxes, skip (InstanceBox already constructed)
|
||||
if !self.user_defined_boxes.contains(&class) {
|
||||
// Special-case: StringBox is already fully constructed via from_i8_string in LLVM lowering; skip birth
|
||||
if !self.user_defined_boxes.contains(&class) && class != "StringBox" {
|
||||
let birt_mid = resolve_slot_by_type_name(&class, "birth");
|
||||
self.emit_box_or_plugin_call(
|
||||
None,
|
||||
|
||||
Reference in New Issue
Block a user