| use zerocopy::*; | ||
| #[path = "formats/coco_static_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_extend_vec_zeroed(v: &mut Vec<format::LocoPacket>, additional: usize) -> Option<()> { | ||
| FromZeros::extend_vec_zeroed(v, additional).ok() | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| use zerocopy::*; | ||
| #[path = "formats/coco_static_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_insert_vec_zeroed( | ||
| v: &mut Vec<format::LocoPacket>, | ||
| position: usize, | ||
| additional: usize, | ||
| ) -> Option<()> { | ||
| FromZeros::insert_vec_zeroed(v, position, additional).ok() | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| use zerocopy::*; | ||
| #[path = "formats/coco_dynamic_padding.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_new_box_zeroed_with_elems_dynamic_padding( | ||
| count: usize, | ||
| ) -> Option<Box<format::LocoPacket>> { | ||
| FromZeros::new_box_zeroed_with_elems(count).ok() | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| use zerocopy::*; | ||
| #[path = "formats/coco_dynamic_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_new_box_zeroed_with_elems_dynamic_size(count: usize) -> Option<Box<format::LocoPacket>> { | ||
| FromZeros::new_box_zeroed_with_elems(count).ok() | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| use zerocopy::*; | ||
| #[path = "formats/coco_static_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_new_box_zeroed() -> Option<Box<format::LocoPacket>> { | ||
| FromZeros::new_box_zeroed().ok() | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| use zerocopy::*; | ||
| #[path = "formats/coco_static_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_new_vec_zeroed(len: usize) -> Option<Vec<format::LocoPacket>> { | ||
| FromZeros::new_vec_zeroed(len).ok() | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| use zerocopy::*; | ||
| #[path = "formats/coco_static_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_new_zeroed() -> format::LocoPacket { | ||
| FromZeros::new_zeroed() | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| use zerocopy::*; | ||
| #[path = "formats/coco_dynamic_padding.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_zero_dynamic_padding(source: &mut format::LocoPacket) { | ||
| source.zero() | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| use zerocopy::*; | ||
| #[path = "formats/coco_dynamic_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_zero_dynamic_size(source: &mut format::LocoPacket) { | ||
| source.zero() | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| use zerocopy::*; | ||
| #[path = "formats/coco_static_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_zero_static_size(source: &mut format::LocoPacket) { | ||
| source.zero() | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| { | ||
| "git": { | ||
| "sha1": "a6a530d0b09bb6218b8b1d7471ad0157096aeaee" | ||
| "sha1": "aa7c31671cb5ce509551edafa23c6865df83b180" | ||
| }, | ||
| "path_in_vcs": "" | ||
| } |
+1
-0
@@ -96,2 +96,3 @@ // Copyright 2024 The Fuchsia Authors | ||
| println!("cargo:rustc-check-cfg=cfg(coverage_nightly)"); | ||
| println!("cargo:rustc-check-cfg=cfg(zerocopy_inline_always)"); | ||
| } | ||
@@ -98,0 +99,0 @@ |
+36
-3
@@ -6,2 +6,11 @@ # This file is automatically @generated by Cargo. | ||
| [[package]] | ||
| name = "aho-corasick" | ||
| version = "0.7.20" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" | ||
| dependencies = [ | ||
| "memchr", | ||
| ] | ||
| [[package]] | ||
| name = "either" | ||
@@ -28,2 +37,8 @@ version = "1.13.0" | ||
| [[package]] | ||
| name = "memchr" | ||
| version = "2.5.0" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" | ||
| [[package]] | ||
| name = "proc-macro2" | ||
@@ -62,2 +77,19 @@ version = "1.0.80" | ||
| [[package]] | ||
| name = "regex" | ||
| version = "1.7.3" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d" | ||
| dependencies = [ | ||
| "aho-corasick", | ||
| "memchr", | ||
| "regex-syntax", | ||
| ] | ||
| [[package]] | ||
| name = "regex-syntax" | ||
| version = "0.6.29" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" | ||
| [[package]] | ||
| name = "rustversion" | ||
@@ -93,3 +125,3 @@ version = "1.0.22" | ||
| name = "zerocopy" | ||
| version = "0.8.47" | ||
| version = "0.8.48" | ||
| dependencies = [ | ||
@@ -99,2 +131,3 @@ "elain", | ||
| "rand", | ||
| "regex", | ||
| "rustversion", | ||
@@ -107,5 +140,5 @@ "static_assertions", | ||
| name = "zerocopy-derive" | ||
| version = "0.8.47" | ||
| version = "0.8.48" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "0e8bc7269b54418e7aeeef514aa68f8690b8c0489a06b0136e5f57c4c5ccab89" | ||
| checksum = "70e3cd084b1788766f53af483dd21f93881ff30d7320490ec3ef7526d203bad4" | ||
| dependencies = [ | ||
@@ -112,0 +145,0 @@ "proc-macro2", |
+48
-4
@@ -16,3 +16,3 @@ # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO | ||
| name = "zerocopy" | ||
| version = "0.8.47" | ||
| version = "0.8.48" | ||
| authors = [ | ||
@@ -55,2 +55,3 @@ "Joshua Liebow-Feeser <joshlf@google.com>", | ||
| no-zerocopy-aarch64-simd-1-59-0 = "1.59.0" | ||
| no-zerocopy-aarch64-simd-be-1-87-0 = "1.87.0" | ||
| no-zerocopy-panic-in-const-and-vec-try-reserve-1-57-0 = "1.57.0" | ||
@@ -114,2 +115,30 @@ | ||
| [[bench]] | ||
| name = "extend_vec_zeroed" | ||
| path = "benches/extend_vec_zeroed.rs" | ||
| [[bench]] | ||
| name = "insert_vec_zeroed" | ||
| path = "benches/insert_vec_zeroed.rs" | ||
| [[bench]] | ||
| name = "new_box_zeroed" | ||
| path = "benches/new_box_zeroed.rs" | ||
| [[bench]] | ||
| name = "new_box_zeroed_with_elems_dynamic_padding" | ||
| path = "benches/new_box_zeroed_with_elems_dynamic_padding.rs" | ||
| [[bench]] | ||
| name = "new_box_zeroed_with_elems_dynamic_size" | ||
| path = "benches/new_box_zeroed_with_elems_dynamic_size.rs" | ||
| [[bench]] | ||
| name = "new_vec_zeroed" | ||
| path = "benches/new_vec_zeroed.rs" | ||
| [[bench]] | ||
| name = "new_zeroed" | ||
| path = "benches/new_zeroed.rs" | ||
| [[bench]] | ||
| name = "read_from_bytes" | ||
@@ -346,4 +375,16 @@ path = "benches/read_from_bytes.rs" | ||
| [[bench]] | ||
| name = "zero_dynamic_padding" | ||
| path = "benches/zero_dynamic_padding.rs" | ||
| [[bench]] | ||
| name = "zero_dynamic_size" | ||
| path = "benches/zero_dynamic_size.rs" | ||
| [[bench]] | ||
| name = "zero_static_size" | ||
| path = "benches/zero_static_size.rs" | ||
| [dependencies.zerocopy-derive] | ||
| version = "=0.8.47" | ||
| version = "=0.8.48" | ||
| optional = true | ||
@@ -362,2 +403,5 @@ | ||
| [dev-dependencies.regex] | ||
| version = "1.0" | ||
| [dev-dependencies.rustversion] | ||
@@ -370,5 +414,5 @@ version = "1.0" | ||
| [dev-dependencies.zerocopy-derive] | ||
| version = "=0.8.47" | ||
| version = "=0.8.48" | ||
| [target."cfg(any())".dependencies.zerocopy-derive] | ||
| version = "=0.8.47" | ||
| version = "=0.8.48" |
+2
-1
@@ -19,2 +19,3 @@ #!/usr/bin/env bash | ||
| find . -iname '*.rs' -type f -not -path './target/*' -not -iname '*.expected.rs' -not -path './vendor/*' -not -path './tools/vendor/*' -print0 | xargs -0 --no-run-if-empty ./cargo.sh +nightly fmt $FMT_FLAGS -- >&2 | ||
| find . -iname '*.rs' -type f -not -path './target/*' -not -iname '*.expected.rs' -not -path './vendor/*' -not -path './tools/vendor/*' -not -path './tools/hermes/*' -print0 | xargs -0 --no-run-if-empty ./cargo.sh +nightly fmt $FMT_FLAGS -- >&2 | ||
| find ./tools/hermes -iname '*.rs' -type f -not -path './tools/hermes/target/*' -not -iname '*.expected.rs' -not -path './tools/hermes/tests/fixtures/*' -not -path './tools/hermes/tests/ui/*' -print0 | xargs -0 --no-run-if-empty ./cargo.sh +nightly fmt $FMT_FLAGS --manifest-path tools/hermes/Cargo.toml -- >&2 |
@@ -13,24 +13,25 @@ #!/usr/bin/env bash | ||
| which yq > /dev/null | ||
| jobs=$(for i in $(find .github -iname '*.yaml' -or -iname '*.yml') | ||
| do | ||
| # Select jobs that are triggered by pull request. | ||
| if yq -e '.on | has("pull_request")' "$i" 2>/dev/null >/dev/null | ||
| then | ||
| # This gets the list of jobs that all-jobs-succeed does not depend on. | ||
| comm -23 \ | ||
| <(yq -r '.jobs | keys | .[]' "$i" | sort | uniq) \ | ||
| <(yq -r '.jobs["all-jobs-succeed"].needs[]' "$i" | sort | uniq) | ||
| failed=0 | ||
| for i in $(find .github -iname '*.yaml' -or -iname '*.yml'); do | ||
| # Select jobs that are triggered by pull request. | ||
| if yq -e '.on | has("pull_request")' "$i" 2>/dev/null >/dev/null; then | ||
| # Check if the file has an `all-jobs-succeed` job. | ||
| if yq -e '.jobs | has("all-jobs-succeed")' "$i" 2>/dev/null >/dev/null; then | ||
| # This gets the list of jobs that `all-jobs-succeed` does not depend on. | ||
| missing=$(comm -23 \ | ||
| <(yq -r '.jobs | keys | .[]' "$i" | grep -v '^all-jobs-succeed$' | sort | uniq) \ | ||
| <(yq -r '.jobs["all-jobs-succeed"].needs[]?' "$i" | sort | uniq)) | ||
| if [ -n "$missing" ]; then | ||
| missing_jobs="$(echo "$missing" | tr '\n' ' ')" | ||
| echo "$i: all-jobs-succeed missing dependencies on some jobs: $missing_jobs" | tee -a $GITHUB_STEP_SUMMARY >&2 | ||
| failed=1 | ||
| fi | ||
| fi | ||
| fi | ||
| done | ||
| # The grep call here excludes all-jobs-succeed from the list of jobs that | ||
| # all-jobs-succeed does not depend on. If all-jobs-succeed does | ||
| # not depend on itself, we do not care about it. | ||
| done | sort | uniq | (grep -v '^all-jobs-succeed$' || true) | ||
| ) | ||
| if [ -n "$jobs" ] | ||
| then | ||
| missing_jobs="$(echo "$jobs" | tr ' ' '\n')" | ||
| echo "all-jobs-succeed missing dependencies on some jobs: $missing_jobs" | tee -a $GITHUB_STEP_SUMMARY >&2 | ||
| if [ "$failed" -eq 1 ]; then | ||
| exit 1 | ||
| fi |
@@ -15,3 +15,2 @@ #!/usr/bin/env python3 | ||
| def main(): | ||
@@ -43,3 +42,3 @@ parser = argparse.ArgumentParser( | ||
| # REGEX: Strict path structure, prevents absolute paths and weird characters | ||
| VALID_PATH = re.compile(r"^([a-zA-Z0-9_.-]+/)+$") | ||
| VALID_PATH = re.compile(r"^([a-zA-Z0-9_.-]+/)*[a-zA-Z0-9_.-]+/?$") | ||
@@ -58,14 +57,14 @@ # Load and validate config | ||
| safe_rules = {} | ||
| for directory, users in rules.items(): | ||
| for rule_path, users in rules.items(): | ||
| if not isinstance(users, list): | ||
| print( | ||
| f"::error::❌ Users for '{directory}' must be a JSON array (list), not a string." | ||
| f"::error::❌ Users for '{rule_path}' must be a JSON array (list), not a string." | ||
| ) | ||
| sys.exit(TECHNICAL_ERROR) | ||
| if not VALID_PATH.match(directory) or ".." in directory.split("/"): | ||
| print(f"::error::❌ Invalid config path: {directory}") | ||
| if not VALID_PATH.match(rule_path) or ".." in rule_path.split("/"): | ||
| print(f"::error::❌ Invalid config path: {rule_path}") | ||
| sys.exit(TECHNICAL_ERROR) | ||
| safe_rules[directory] = [str(u).lower() for u in users] | ||
| safe_rules[rule_path] = [str(u).lower() for u in users] | ||
@@ -112,15 +111,18 @@ if not args.check_config: | ||
| # Find the most specific (longest) matching directory rule. | ||
| longest_match_dir = None | ||
| for directory in safe_rules.keys(): | ||
| if file_path.startswith(directory): | ||
| if longest_match_dir is None or len(directory) > len( | ||
| longest_match_dir | ||
| ): | ||
| longest_match_dir = directory | ||
| # Find the most specific (longest) matching rule. | ||
| longest_match_rule = None | ||
| for rule_path in safe_rules.keys(): | ||
| if rule_path.endswith('/'): | ||
| if file_path.startswith(rule_path): | ||
| if longest_match_rule is None or len(rule_path) > len(longest_match_rule): | ||
| longest_match_rule = rule_path | ||
| else: | ||
| if file_path == rule_path: | ||
| if longest_match_rule is None or len(rule_path) > len(longest_match_rule): | ||
| longest_match_rule = rule_path | ||
| # First, explicitly fail if the file isn't covered by ANY rule. | ||
| if not longest_match_dir: | ||
| if not longest_match_rule: | ||
| print( | ||
| f"::error::❌ File '{file_path}' does not fall under any configured auto-approve directory." | ||
| f"::error::❌ File '{file_path}' does not fall under any configured auto-approve rule." | ||
| ) | ||
@@ -131,3 +133,3 @@ sys.exit(NOT_APPROVED) | ||
| for user in contributors: | ||
| if user not in safe_rules[longest_match_dir]: | ||
| if user not in safe_rules[longest_match_rule]: | ||
| print( | ||
@@ -134,0 +136,0 @@ f"::error::❌ Contributor @{user} not authorized for '{file_path}'." |
+9
-0
@@ -144,2 +144,11 @@ <!-- Copyright 2024 The Fuchsia Authors | ||
| ## Build Tuning | ||
| ### `--cfg zerocopy_inline_always` | ||
| Upgrades `#[inline]` to `#[inline(always)]` on many of zerocopy's public | ||
| functions and methods. This provides a narrowly-scoped alternative that | ||
| *may* improve the optimization of hot paths using zerocopy without the broad | ||
| compile-time penalties of configuring `codegen-units=1`. | ||
| ## Security Ethos | ||
@@ -146,0 +155,0 @@ |
@@ -660,3 +660,6 @@ // Copyright 2024 The Fuchsia Authors | ||
| .iter() | ||
| .map(|ptr| unsafe { core::ptr::read_unaligned(ptr.as_ptr()) } as usize) | ||
| .map( | ||
| #[inline(always)] | ||
| |ptr| unsafe { core::ptr::read_unaligned(ptr.as_ptr()) } as usize, | ||
| ) | ||
| .sum(); | ||
@@ -668,3 +671,6 @@ // SAFETY: Points to a valid value by construction. | ||
| .iter() | ||
| .map(|ptr| unsafe { core::ptr::read_unaligned(ptr.as_ptr()) } as usize) | ||
| .map( | ||
| #[inline(always)] | ||
| |ptr| unsafe { core::ptr::read_unaligned(ptr.as_ptr()) } as usize, | ||
| ) | ||
| .sum(); | ||
@@ -671,0 +677,0 @@ assert_eq!(l_sum, i.get()); |
@@ -41,3 +41,6 @@ // Copyright 2023 The Fuchsia Authors | ||
| { | ||
| ptr.as_bytes().as_ref().iter().all(|&byte| byte == 0) | ||
| ptr.as_bytes().as_ref().iter().all( | ||
| #[inline(always)] | ||
| |&byte| byte == 0, | ||
| ) | ||
| } | ||
@@ -44,0 +47,0 @@ |
+4
-2
@@ -233,4 +233,6 @@ // Copyright 2024 The Fuchsia Authors | ||
| } | ||
| let (bytes, suffix) = | ||
| bytes.split_at(mem::size_of::<T>()).map_err(|b| SizeError::new(b).into())?; | ||
| let (bytes, suffix) = bytes.split_at(mem::size_of::<T>()).map_err( | ||
| #[inline(always)] | ||
| |b| SizeError::new(b).into(), | ||
| )?; | ||
| // SAFETY: We just validated alignment and that `bytes` is at least as | ||
@@ -237,0 +239,0 @@ // large as `T`. `bytes.split_at(mem::size_of::<T>())?` ensures that the |
+16
-10
@@ -768,12 +768,18 @@ // Copyright 2022 The Fuchsia Authors | ||
| ) | ||
| // SAFETY: By the preceding assert, `Dst` and `Wrapping<Dst>` have the | ||
| // same alignment. | ||
| .map(|dst| unsafe { crate::util::transmute_ref::<_, _, BecauseImmutable>(dst) }) | ||
| .map_err(|err| { | ||
| // SAFETY: By the preceding assert, `Src` and `Wrapping<Src>` have the | ||
| // same alignment. | ||
| ValidityError::new(unsafe { | ||
| crate::util::transmute_ref::<_, _, BecauseImmutable>(err.into_src()) | ||
| }) | ||
| }) | ||
| .map( | ||
| // SAFETY: By the preceding assert, `Dst` and `Wrapping<Dst>` have | ||
| // the same alignment. | ||
| #[inline(always)] | ||
| |dst| unsafe { crate::util::transmute_ref::<_, _, BecauseImmutable>(dst) }, | ||
| ) | ||
| .map_err( | ||
| #[inline(always)] | ||
| |err| { | ||
| // SAFETY: By the preceding assert, `Src` and `Wrapping<Src>` have the | ||
| // same alignment. | ||
| ValidityError::new(unsafe { | ||
| crate::util::transmute_ref::<_, _, BecauseImmutable>(err.into_src()) | ||
| }) | ||
| }, | ||
| ) | ||
| } | ||
@@ -780,0 +786,0 @@ } |
+4
-1
@@ -204,3 +204,6 @@ // Copyright 2023 The Fuchsia Authors | ||
| Ok(aligned) => Ok(aligned.as_ref()), | ||
| Err(err) => Err(err.map_src(|src| src.into_unalign().as_ref())), | ||
| Err(err) => Err(err.map_src( | ||
| #[inline(always)] | ||
| |src| src.into_unalign().as_ref(), | ||
| )), | ||
| } | ||
@@ -207,0 +210,0 @@ } |
+10
-8
@@ -13,2 +13,4 @@ // Copyright 2026 The Fuchsia Authors | ||
| use regex::Regex; | ||
| enum Directive { | ||
@@ -53,2 +55,3 @@ Asm, | ||
| target_dir, | ||
| "--all-features", | ||
| "--bench", | ||
@@ -66,12 +69,11 @@ bench_name, | ||
| let re = Regex::new(r"(\.Lanon\.)[0-z]+(\.\d+)").unwrap(); | ||
| let test_directive = |directive: Directive| { | ||
| let output = cargo_asm(&directive); | ||
| let actual_result = output.stdout; | ||
| let actual_result = String::from_utf8_lossy(&output.stdout); | ||
| let actual_result = re.replace_all(&actual_result, "${1}HASH${2}"); | ||
| if !(output.status.success()) { | ||
| panic!( | ||
| "{}\n{}", | ||
| String::from_utf8_lossy(&actual_result), | ||
| String::from_utf8_lossy(&output.stderr) | ||
| ); | ||
| panic!("{}\n{}", &actual_result, String::from_utf8_lossy(&output.stderr)); | ||
| } | ||
@@ -89,6 +91,6 @@ | ||
| if bless { | ||
| std::fs::write(expected_file_path, &actual_result).unwrap(); | ||
| std::fs::write(expected_file_path, actual_result.as_bytes()).unwrap(); | ||
| } else { | ||
| let expected_result = std::fs::read(expected_file_path).unwrap_or_default(); | ||
| if actual_result != expected_result { | ||
| if actual_result.as_bytes() != expected_result { | ||
| let expected = String::from_utf8_lossy(&expected_result[..]); | ||
@@ -95,0 +97,0 @@ panic!("Bless codegen tests with BLESS=1\nGot unexpected output:\n{}", expected); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet