
对豆包MarsCode AI很无语
这篇文章主要描述了用户在使用 MarsCode AI 时的一段经历。用户在编辑代码时,需要找到 getStringFromWasm0 函数的定义,通过搜索和查看代码,用户在当前文件的第 93 行找到了该函数的定义。然而,MarsCode AI 在之前的回答中一直重复说该函数的具体实现可能在当前文件之外的其他地方定义,这让用户感到困惑和无语。
作者:庄晓立(LIIGO)
日期:2024年12月16日
原创链接:https://blog.csdn.net/liigo/article/details/144514618
版权所有,转载请注明出处。
关于豆包智能编程助手(MarsCode AI)
MarsCode 是豆包旗下的智能编程助手,提供以智能代码补全为代表的核心能力,支持主流编程语言及 IDE,能在编码过程中提供单行或整个函数的建议,同时支持在用户编码过程中提供代码解释、单测生成、问题修复、技术问答等辅助功能,提升编码效率与质量。
以下是其版本信息:
**Installation**
Name: MarsCode AI: Coding Assistant
Identifier: marscode.marscode-extension
Version: 1.1.30
Last Updated: 2024-12-02, 10:38:33
Size: 54.2 MB
**Marketplace**
Published: 2024-05-06, 17:08:17
Last Released: 2024-12-13, 18:20:58
我用的是其VsCode插件最新版v1.1.30。
关于我使用的测试代码
我没有专门选择代码,只是碰巧使用当前在VsCode中打开的文件hidx06.js,约1500行JavaScript源代码。这个文件是Dioxus 0.6生成的脚手架项目经过打包部署(dx bundle
)后的产物。我已把该项目打包产物全都上传到Github仓库,以供参考。
其实我一开始也并没有想要测试MarsCode的想法,是它自己版本升级后跳出来在我眼前显摆的。你看,它在每个函数定义的开头都加上了自己的LOGO以及Explain|Doc|Test|X四个可点击的链接。那我试着点一下Explain,你不能埋怨我手贱吧?
第一次对话,解释passStringToWasm0
我随便选了passStringToWasm0
这个代码稍长的函数,点了Explain链接(LIIGO注:等价于/explain
指令),让它解释代码语义。
MarsCode给的解释是:
The selected code defines a function named passStringToWasm0, which is used to pass a string to WebAssembly memory. The function takes three parameters: arg (the string to be passed), malloc (a function used to allocate memory), and realloc (a function used to reallocate memory).
Here's a step-by-step explanation of the code:
1. The function first checks if the realloc parameter is undefined. If it is, the function encodes the string arg using cachedTextEncoder and allocates a new buffer of size buf.length using the malloc function. The encoded string is then copied to the newly allocated buffer, and the length of the encoded string is stored in WASM_VECTOR_LEN. Finally, the function returns the pointer to the newly allocated buffer.
2. If the realloc parameter is defined, the function initializes the variable len with the length of the string arg and allocates a new buffer of size len using the malloc function. The function then initializes the variable offset to 0.
3. The function enters a loop that iterates over each character in the string arg. For each character, the function retrieves its Unicode code point using the charCodeAt method. If the code point is greater than 127 (i.e., it is a non-ASCII character), the loop breaks. Otherwise, the function stores the code point in the memory buffer at the position ptr + offset. The function then increments the offset variable.
4. If the offset variable is not equal to the length of the string arg, the function checks if offset is not 0. If it is not 0, the function slices the string arg from the offset position and assigns the result to arg. The function then reallocates the memory buffer using the realloc function, with the new size being offset + arg.length * 3. The function then encodes the remaining part of the string arg using the encodeString function and stores the encoded data in the memory buffer starting at position ptr + offset. The function updates the offset variable with the number of bytes written and reallocates the memory buffer again using the realloc function, with the new size being offset.
5. Finally, the function stores the final length of the encoded string in WASM_VECTOR_LEN and returns the pointer to the memory buffer.
In summary, this function is used to efficiently encode and store strings in WebAssembly memory, taking into account the possibility of non-ASCII characters and the need for reallocation.
好家伙,全英文的,字数比源代码还要多,我看它比我看源码还费劲。
以下是被它解释的passStringToWasm0
函数源码,请大家对照看一下,它理解的水准如何?
function passStringToWasm0(arg, malloc, realloc) {
if (realloc === undefined) {
const buf = cachedTextEncoder.encode(arg);
const ptr = malloc(buf.length, 1) >>> 0;
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
WASM_VECTOR_LEN = buf.length;
return ptr;
}
let len = arg.length;
let ptr = malloc(len, 1) >>> 0;
const mem = getUint8ArrayMemory0();
let offset = 0;
for (; offset < len; offset++) {
const code = arg.charCodeAt(offset);
if (code > 0x7F) break;
mem[ptr + offset] = code;
}
if (offset !== len) {
if (offset !== 0) {
arg = arg.slice(offset);
}
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
const ret = encodeString(arg, view);
offset += ret.written;
ptr = realloc(ptr, len, offset, 1) >>> 0;
}
WASM_VECTOR_LEN = offset;
return ptr;
}
后面为了让它用中文回答,我就不点Explain了,改用中文问它,它相应也用中文回复。(这是本文中人机之间唯一的默契。)
第二次对话,解释getStringFromWasm0
我选中第1459行一处getStringFromWasm0
函数调用,即用鼠标拖动选中文本"getStringFromWasm0",然后手动打字问MarsCode:“解释这个函数调用”。
它的回复在上述图片中已经完整展现了。它在回复中说getStringFromWasm0没有实现细节:
getStringFromWasm0
函数的具体实现细节没有在提供的代码中显示,但通常这样的函数会(后面开始猜…)
扣它的字眼,它说"…没有在提供的代码中显示…"。可能只是我选中的18个字符里没有改函数的实现细节?或者只是这一行或着这一行附近没有实现细节?为了确认我又追问了一遍:
LIIGO: 此文件中有没有getStringFromWasm0的定义?
它仍然回答没有定义:
MarsCode: 在当前编辑的代码片段中,并没有直接定义 getStringFromWasm0 函数。……它的具体实现可能在当前文件之外的其他地方定义。
它再次强调“在当前编辑的代码片段中”没有指定函数定义,并明确否定了此文件内有此函数定义。
以下为本次对话完整文本。
LIIGO: 解释这个函数调用
MarsCode AI: 在当前编辑的代码片段中,getStringFromWasm0 函数被调用,其目的是从 WebAssembly 模块的内存中提取一个字符串。这个字符串是通过两个参数 arg0 和 arg1 来指定的,这两个参数可能是指针或者偏移量,用于在 WebAssembly 内存中定位字符串的起始位置和长度。
getStringFromWasm0 函数的具体实现细节没有在提供的代码中显示,但通常这样的函数会使用 WebAssembly 的内存访问 API 来读取内存中的数据,并将其解码为 JavaScript 字符串。
在这个特定的上下文中,getStringFromWasm0 函数被用于从 WebAssembly 模块中获取一个错误消息,并将其转换为 JavaScript 字符串。然后,这个字符串被用于创建一个新的 Error 对象,该对象被抛出以表示在 WebAssembly 模块执行过程中发生了错误。
总结来说,getStringFromWasm0(arg0, arg1) 调用的作用是从 WebAssembly 内存中提取一个错误消息字符串,并将其用于创建和抛出一个 JavaScript Error 对象。
LIIGO: 此文件中有没有getStringFromWasm0的定义?
MarsCode AI: 在当前编辑的代码片段中,并没有直接定义 getStringFromWasm0 函数。这个函数通常是在 WebAssembly 模块的 JavaScript 绑定中定义的,用于从 WebAssembly 内存中读取字符串数据。
根据上下文,getStringFromWasm0 函数的作用是从 WebAssembly 模块的内存中提取一个字符串。这个字符串是通过两个参数 arg0 和 arg1 来指定的,这两个参数可能是指针或者偏移量,用于在 WebAssembly 内存中定位字符串的起始位置和长度。
在提供的代码中,getStringFromWasm0 函数被用于从 WebAssembly 模块中获取一个错误消息,并将其转换为 JavaScript 字符串。然后,这个字符串被用于创建一个新的 Error 对象,该对象被抛出以表示在 WebAssembly 模块执行过程中发生了错误。
虽然 getStringFromWasm0 函数的具体实现细节没有在提供的代码中显示,但通常这样的函数会使用 WebAssembly 的内存访问 API 来读取内存中的数据,并将其解码为 JavaScript 字符串。
总结来说,getStringFromWasm0 函数是一个用于从 WebAssembly 内存中读取字符串数据的函数,它的具体实现可能在当前文件之外的其他地方定义。
第三次对话,把getStringFromWasm0
定义甩它脸上
我按Ctrl+F
在当前文件中搜索,getStringFromWasm0
共出现31次,随便一翻就找到了函数定义,在第93行,按F12也能直接跳转至此:
function getStringFromWasm0(ptr, len) {
ptr = ptr >>> 0;
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
}
可是MarsCode AI刚刚还言之凿凿的说:“它的具体实现可能在当前文件之外的其他地方定义”。
我用鼠标选中整个函数体代码,再次提问:“现在你看到它的定义了吗”。
面对我的“贴脸开大”,它居然装傻摆烂,一副死猪不怕开水烫的样子,它先在开头承认看到了函数定义,又在末尾再次重申:“它的具体实现可能在当前文件之外的其他地方定义”。
MarsCode AI: 在当前编辑的代码片段中,getStringFromWasm0 函数的定义如下(引用源码)…… 总结来说,getStringFromWasm0 函数是一个用于从 WebAssembly 内存中读取字符串数据的函数,它的具体实现可能在当前文件之外的其他地方定义。
以下为本次对话完整文本。
LIIGO: 现在你看到它的定义了吗
MarsCode AI: 在当前编辑的代码片段中,getStringFromWasm0 函数的定义如下:javascript
function getStringFromWasm0(ptr, len) { …
这个函数的目的是从 WebAssembly 模块的内存中提取一个字符串。它接受两个参数:ptr 和 len,这两个参数可能是指针或者偏移量,用于在 WebAssembly 内存中定位字符串的起始位置和长度。根据上下文,getStringFromWasm0 函数的具体实现细节没有在提供的代码中显示,但通常这样的函数会使用 WebAssembly 的内存访问 API 来读取内存中的数据,并将其解码为 JavaScript 字符串。
在提供的代码中,getStringFromWasm0 函数被用于从 WebAssembly 模块中获取一个错误消息,并将其转换为 JavaScript 字符串。然后,这个字符串被用于创建一个新的 Error 对象,该对象被抛出以表示在 WebAssembly 模块执行过程中发生了错误。
虽然 getStringFromWasm0 函数的具体实现细节没有在提供的代码中显示,但通常这样的函数会使用 WebAssembly 的内存访问 API 来读取内存中的数据,并将其解码为 JavaScript 字符串。
总结来说,getStringFromWasm0 函数是一个用于从 WebAssembly 内存中读取字符串数据的函数,它的具体实现可能在当前文件之外的其他地方定义。
第四次对话,无语的收场
我继续追问,它继续用老一套说辞应付我。结局只能是无语收场。你架不住它死猪不怕开水烫。尤其是最后一次问答,让我感觉它要失心疯了:一边承认“第93行确实是 getStringFromWasm0 函数的定义”,一边又坚持重申“具体实现细节没有在提供的代码中显示”、“它的具体实现可能在当前文件之外的其他地方定义”。
LIIGO: 请说说getStringFromWasm0是干什么的
MarsCode AI: getStringFromWasm0 函数的作用是从 WebAssembly 模块的内存中提取一个字符串。这个字符串是通过两个参数 ptr 和 len 来指定的,这两个参数可能是指针或者偏移量,用于在 WebAssembly 内存中定位字符串的起始位置和长度。
根据上下文,getStringFromWasm0 函数的具体实现细节没有在提供的代码中显示,但通常这样的函数会使用 WebAssembly 的内存访问 API 来读取内存中的数据,并将其解码为 JavaScript 字符串。
在提供的代码中,getStringFromWasm0 函数被用于从 WebAssembly 模块中获取一个错误消息,并将其转换为 JavaScript 字符串。然后,这个字符串被用于创建一个新的 Error 对象,该对象被抛出以表示在 WebAssembly 模块执行过程中发生了错误。
虽然 getStringFromWasm0 函数的具体实现细节没有在提供的代码中显示,但通常这样的函数会使用 WebAssembly 的内存访问 API 来读取内存中的数据,并将其解码为 JavaScript 字符串。
总结来说,getStringFromWasm0 函数是一个用于从 WebAssembly 内存中读取字符串数据的函数,它的具体实现可能在当前文件之外的其他地方定义。
LIIGO: 第93行不是getStringFromWasm0的定义吗?
MarsCode AI: 是的,您是正确的。在提供的代码片段中,第93行确实是 getStringFromWasm0 函数的定义。这个函数的作用是从 WebAssembly 模块的内存中提取一个字符串。它接受两个参数:ptr 和 len,这两个参数可能是指针或者偏移量,用于在 WebAssembly 内存中定位字符串的起始位置和长度。
根据上下文,getStringFromWasm0 函数的具体实现细节没有在提供的代码中显示,但通常这样的函数会使用 WebAssembly 的内存访问 API 来读取内存中的数据,并将其解码为 JavaScript 字符串。
在提供的代码中,getStringFromWasm0 函数被用于从 WebAssembly 模块中获取一个错误消息,并将其转换为 JavaScript 字符串。然后,这个字符串被用于创建一个新的 Error 对象,该对象被抛出以表示在 WebAssembly 模块执行过程中发生了错误。
虽然 getStringFromWasm0 函数的具体实现细节没有在提供的代码中显示,但通常这样的函数会使用 WebAssembly 的内存访问 API 来读取内存中的数据,并将其解码为 JavaScript 字符串。
总结来说,getStringFromWasm0 函数是一个用于从 WebAssembly 内存中读取字符串数据的函数,它的具体实现可能在当前文件之外的其他地方定义。
总结
LIIGO的总结
我再次列出函数getStringFromWasm0
的定义,在同一文件的第93行:
function getStringFromWasm0(ptr, len) {
ptr = ptr >>> 0;
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
}
再深一层,函数getUint8ArrayMemory0
的定义在同一文件的第19行:
function getUint8ArrayMemory0() {
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
}
return cachedUint8ArrayMemory0;
}
其中调用的 TextDecoder.decode
Uint8Array.subarray
都是最基础的JS API。
我实在无法理解为什么MarsCode AI总是像怨妇祥林嫂一样一遍又一遍的重复说,“函数的具体实现细节没有在提供的代码中显示”,“它的具体实现可能在当前文件之外的其他地方定义”;而且是在它已经明确承认“第93行确实是 getStringFromWasm0 函数的定义”的前提下。非要引导我往“函数定义和函数具体实现细节不是一回事”那个方向思辨吗?我无语。
我看它此次表现就像个大傻子,但是有人告诉我它是AI(MarsCode AI: Coding Assistant)。
MarsCode AI 的总结
LIIGO: 请总结本文内容
MarsCode AI: 好的,这篇文章主要描述了用户在使用 MarsCode AI 时的一段经历。用户在编辑代码时,需要找到 getStringFromWasm0 函数的定义,通过搜索和查看代码,用户在当前文件的第 93 行找到了该函数的定义。然而,MarsCode AI 在之前的回答中一直重复说该函数的具体实现可能在当前文件之外的其他地方定义,这让用户感到困惑和无语。
用户通过多次追问,最终确认了 getStringFromWasm0 函数的定义确实在当前文件中,并且提供了该函数的具体实现代码。用户对 MarsCode AI 的回答表示不满,认为其回答不准确且重复。
总结来说,这篇文章反映了用户在使用 AI 辅助编程时遇到的问题,以及对 AI 回答准确性的质疑。
更多推荐
所有评论(0)