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

snipe off some unsafe code #922

Merged
merged 1 commit into from
Aug 24, 2023
Merged

snipe off some unsafe code #922

merged 1 commit into from
Aug 24, 2023

Conversation

davidhewitt
Copy link
Contributor

@davidhewitt davidhewitt commented Aug 24, 2023

Change Summary

The goal here is to remove all uses of unsafe which I could replace with safe code, or alternatively justify with a Safety comment. The changes make use of safe abstractions which should completely optimize away (especially with full LTO) so no performance impact is expected.

The only exception is that there were some uses of PyByteArray::as_bytes which I didn't agree with as appropriate, and I copied the output of those cases into a new allocation. This is a necessary performance loss in exchange for correctness.

Related issue number

Related to pydantic/pydantic#7211 - doing some due diligence here felt worthwhile.

Checklist

  • Unit tests for the changes exist
  • Documentation reflects the changes where applicable
  • Pydantic tests pass with this pydantic-core (except for expected changes)
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Selected Reviewer: @samuelcolvin

@codecov
Copy link

codecov bot commented Aug 24, 2023

Codecov Report

Merging #922 (0a93ee4) into main (882b57f) will decrease coverage by 0.02%.
The diff coverage is 78.31%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #922      +/-   ##
==========================================
- Coverage   93.84%   93.82%   -0.02%     
==========================================
  Files         105      105              
  Lines       15459    15436      -23     
  Branches       25       25              
==========================================
- Hits        14507    14483      -24     
- Misses        946      947       +1     
  Partials        6        6              
Files Changed Coverage Δ
src/serializers/infer.rs 95.00% <44.44%> (-0.74%) ⬇️
src/input/return_enums.rs 85.29% <53.84%> (-0.30%) ⬇️
src/errors/validation_exception.rs 93.68% <95.00%> (-0.16%) ⬇️
src/input/input_python.rs 98.29% <100.00%> (-0.01%) ⬇️
src/serializers/ob_type.rs 80.80% <100.00%> (-0.08%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 882b57f...0a93ee4. Read the comment docs.

@codspeed-hq
Copy link

codspeed-hq bot commented Aug 24, 2023

CodSpeed Performance Report

Merging #922 will not alter performance

Comparing dh/safer (0a93ee4) with main (882b57f)

Summary

✅ 138 untouched benchmarks

@davidhewitt
Copy link
Contributor Author

Integration test failures are due to #911

@davidhewitt
Copy link
Contributor Author

please review

@davidhewitt davidhewitt merged commit 34fbd84 into main Aug 24, 2023
29 of 30 checks passed
@davidhewitt davidhewitt deleted the dh/safer branch August 24, 2023 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants