Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔧 Improve error handling, return types, and add missing functions #12

Merged
merged 17 commits into from
Jul 11, 2024

Conversation

FlannyH
Copy link
Contributor

@FlannyH FlannyH commented May 7, 2024

This PR improves error handling, using thiserror to return clearer error messages to the user, and adds some of the missing raytracing-related functions. Additionally, this PR moves main.rs to Examples/compute-shader.rs

@FlannyH FlannyH requested a review from MarijnS95 May 7, 2024 13:08
@FlannyH FlannyH force-pushed the cleanup-new branch 4 times, most recently from 723ed8d to 886c394 Compare May 13, 2024 13:14
src/lib.rs Outdated
Comment on lines 78 to 89
bindings::IRBytecodeOwnership::None,
);
bindings::IRBytecodeOwnership::Copy,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should document why this is changing (with a comment what Copy means). Alternatively we could return an IRObject<'data> with _marker: PhantomData<&'data [u8]> :)

Copy link
Contributor Author

@FlannyH FlannyH Jun 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About the PhantomData: if I understand this correctly, we can use that to keep track of the lifetime of the bytecode data slice, by adding an empty dummy field to the struct, which means we won't have to copy the bytecode?

Comment on lines +478 to +481
// The documentation is inconsistent about this function.
// The docs say `You must cast this pointer to the appropriate error payload struct for the error code``
// but the example code just treats this as a char* like this: `printf("%s\n", (const char*)IRErrorGetPayload(pRootSigError));`
// Let's assume the example code is correct
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should request a clarification that explains for each IRErrorGetCode() how the payload should be interpreted. Maybe only linking gives an accompanying error message.

Besides, you're never using nor exposing this payload to the user, why?

src/lib.rs Outdated
// but the example code just treats this as a char* like this: `printf("%s\n", (const char*)IRErrorGetPayload(pRootSigError));`
// Let's assume the example code is correct
let payload = self.funcs.IRErrorGetPayload(self.me.as_ptr()) as *mut i8;
CString::from_raw(payload)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://doc.rust-lang.org/std/ffi/struct.CString.html#method.from_raw

Retakes ownership of a CString that was transferred to C via CString::into_raw.

So that's a no :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what to do with this one

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CStr::from_ptr(). See last commit.

@MarijnS95
Copy link
Member

I've manually applied the remainder of the review and am going to merge this.

There's still quite a lot wrong with the API, but that's something I'll solve in future PRs to not conflate this too much. Most notably:

  • Quite a lot of APIs take in an IRCompiler, when they only need the loaded function pointers from IRCompilerFactory. I am going to rename this struct and move these fn new(compiler) or variations onto that struct;
  • Specifically IRObject also stores IRCompiler with lifetime, making it impossible to call any &mut function on IRCompiler while an IRObject is around. Like the previous point, it only uses this to get access to function pointers.
  • More lifetimes solved in Replace Arc with original lifetime design #13.

This pointer:
- Wasn't created by `CString::into_raw()`;
- Isn't owned by us, hence shouldn't be freed by us.
@MarijnS95 MarijnS95 added this pull request to the merge queue Jul 11, 2024
Merged via the queue into main with commit fac0ee8 Jul 11, 2024
4 checks passed
@MarijnS95 MarijnS95 deleted the cleanup-new branch July 11, 2024 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants