Skip to content

Commit 7e39d6f

Browse files
committed
Merge remote-tracking branch 'upstream/main' into msrv
2 parents 1c1d7c2 + f00ad5b commit 7e39d6f

File tree

901 files changed

+58332
-48915
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

901 files changed

+58332
-48915
lines changed

.gemini/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ code_review:
44
comment_severity_threshold: MEDIUM
55
max_review_comments: -1
66
pull_request_opened:
7-
help: true
7+
help: false
88
summary: false
99
code_review: false
1010
ignore_patterns: []

.github/workflows/build-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
7272

7373
- name: Set MSRV toolchain
74-
run: rustup override set 1.82
74+
run: rustup override set 1.83
7575

7676
# Toolchain boilerplate
7777
- name: Potentially override rust version with nightly

Cargo.lock

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ exclude = [
108108

109109
[workspace.package]
110110
version = "2.0.0"
111-
rust-version = "1.82"
111+
rust-version = "1.83"
112112
authors = ["The ICU4X Project Developers"]
113113
edition = "2021"
114114
repository = "https://github.com/unicode-org/icu4x"
@@ -140,7 +140,7 @@ icu_pattern = { version = "0.4.0", path = "components/pattern", default-features
140140
icu = { version = "~2.0.0", path = "components/icu", default-features = false }
141141
icu_calendar = { version = "~2.0.0", path = "components/calendar", default-features = false }
142142
icu_casemap = { version = "~2.0.0", path = "components/casemap", default-features = false }
143-
icu_collator = { version = "~2.0.0", path = "components/collator", default-features = false }
143+
icu_collator = { version = "~2.1.0-dev", path = "components/collator", default-features = false }
144144
icu_collections = { version = "~2.0.0", path = "components/collections", default-features = false }
145145
icu_codepointtrie_builder = { version = "~0.5.0", path = "components/collections/codepointtrie_builder", default-features = false }
146146
icu_datetime = { version = "~2.0.0", path = "components/datetime", default-features = false }
@@ -172,7 +172,7 @@ icu_provider_registry = { version = "~2.0.0", path = "provider/registry", defaul
172172
# Baked data
173173
icu_calendar_data = { version = "~2.0.0", path = "provider/data/calendar", default-features = false }
174174
icu_casemap_data = { version = "~2.0.0", path = "provider/data/casemap", default-features = false }
175-
icu_collator_data = { version = "~2.0.1", path = "provider/data/collator", default-features = false }
175+
icu_collator_data = { version = "~2.1.0-dev", path = "provider/data/collator", default-features = false }
176176
icu_datetime_data = { version = "~2.0.0", path = "provider/data/datetime", default-features = false }
177177
icu_decimal_data = { version = "~2.0.0", path = "provider/data/decimal", default-features = false }
178178
icu_list_data = { version = "~2.0.0", path = "provider/data/list", default-features = false }

components/calendar/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,9 @@ harness = false
6666
name = "convert"
6767
harness = false
6868

69+
[[test]]
70+
name = "arithmetic"
71+
required-features = ["ixdtf"]
72+
6973
[package.metadata.cargo-semver-checks.lints]
7074
workspace = true

components/calendar/benches/date.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,27 @@ pub struct Test {
2020
use criterion::{
2121
black_box, criterion_group, criterion_main, measurement::WallTime, BenchmarkGroup, Criterion,
2222
};
23-
use icu_calendar::{AsCalendar, Calendar, Date, DateDuration};
23+
use icu_calendar::{
24+
options::{DateAddOptions, Overflow},
25+
types, AsCalendar, Calendar, Date,
26+
};
2427

2528
fn bench_date<A: AsCalendar>(date: &mut Date<A>) {
2629
// black_box used to avoid compiler optimization.
2730
// Arithmetic
28-
date.add(DateDuration {
29-
is_negative: false,
30-
years: black_box(1),
31-
months: black_box(2),
32-
weeks: black_box(3),
33-
days: black_box(4),
34-
});
31+
let mut options = DateAddOptions::default();
32+
options.overflow = Some(Overflow::Constrain);
33+
date.try_add_with_options(
34+
types::DateDuration {
35+
is_negative: false,
36+
years: black_box(1),
37+
months: black_box(2),
38+
weeks: black_box(3),
39+
days: black_box(4),
40+
},
41+
options,
42+
)
43+
.unwrap();
3544

3645
// Retrieving vals
3746
let _ = black_box(date.year());
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
target
2+
corpus
3+
artifacts
4+
coverage
5+
crash-*
6+
Cargo.lock
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This file is part of ICU4X. For terms of use, please see the file
2+
# called LICENSE at the top level of the ICU4X source tree
3+
# (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4+
5+
[package]
6+
name = "icu_calendar-fuzz"
7+
publish = false
8+
edition = "2021"
9+
autobins = false
10+
11+
[package.metadata]
12+
cargo-fuzz = true
13+
14+
[dependencies]
15+
libfuzzer-sys = "0.4"
16+
arbitrary = { version = "1.4", features = ["derive"] }
17+
icu_calendar = { path = "..", features = ["compiled_data"] }
18+
19+
# Prevent this from interfering with workspaces
20+
[workspace]
21+
22+
[[bin]]
23+
name = "construction"
24+
path = "fuzz_targets/construction.rs"
25+
test = false
26+
doc = false
27+
bench = false

components/calendar/fuzz/LICENSE

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
UNICODE LICENSE V3
2+
3+
COPYRIGHT AND PERMISSION NOTICE
4+
5+
Copyright © 2020-2024 Unicode, Inc.
6+
7+
NOTICE TO USER: Carefully read the following legal agreement. BY
8+
DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING DATA FILES, AND/OR
9+
SOFTWARE, YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE
10+
TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU DO NOT AGREE, DO NOT
11+
DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE THE DATA FILES OR SOFTWARE.
12+
13+
Permission is hereby granted, free of charge, to any person obtaining a
14+
copy of data files and any associated documentation (the "Data Files") or
15+
software and any associated documentation (the "Software") to deal in the
16+
Data Files or Software without restriction, including without limitation
17+
the rights to use, copy, modify, merge, publish, distribute, and/or sell
18+
copies of the Data Files or Software, and to permit persons to whom the
19+
Data Files or Software are furnished to do so, provided that either (a)
20+
this copyright and permission notice appear with all copies of the Data
21+
Files or Software, or (b) this copyright and permission notice appear in
22+
associated Documentation.
23+
24+
THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
25+
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
27+
THIRD PARTY RIGHTS.
28+
29+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE
30+
BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES,
31+
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
32+
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
33+
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE DATA
34+
FILES OR SOFTWARE.
35+
36+
Except as contained in this notice, the name of a copyright holder shall
37+
not be used in advertising or otherwise to promote the sale, use or other
38+
dealings in these Data Files or Software without prior written
39+
authorization of the copyright holder.
40+
41+
SPDX-License-Identifier: Unicode-3.0
42+
43+
44+
45+
Portions of ICU4X may have been adapted from ICU4C and/or ICU4J.
46+
ICU 1.8.1 to ICU 57.1 © 1995-2016 International Business Machines Corporation and others.
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// This file is part of ICU4X. For terms of use, please see the file
2+
// called LICENSE at the top level of the ICU4X source tree
3+
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4+
5+
#![no_main]
6+
7+
use arbitrary::Arbitrary;
8+
use icu_calendar::options::*;
9+
use icu_calendar::types::{DateFields, MonthCode};
10+
use icu_calendar::{AnyCalendar, Date};
11+
use libfuzzer_sys::fuzz_target;
12+
use std::num::NonZeroU8;
13+
14+
#[derive(Arbitrary, Debug)]
15+
struct FuzzInput {
16+
year: i32,
17+
month: u8,
18+
day: u8,
19+
month_interpretation: MonthInterpretation,
20+
overflow_constrain: bool,
21+
cal: AnyCalendarKind,
22+
}
23+
24+
#[derive(Arbitrary, Debug)]
25+
enum MonthInterpretation {
26+
Ordinal,
27+
CodeNormal,
28+
CodeLeap,
29+
}
30+
31+
#[derive(Arbitrary, Debug)]
32+
pub enum AnyCalendarKind {
33+
Buddhist,
34+
Chinese,
35+
Coptic,
36+
Dangi,
37+
Ethiopian,
38+
EthiopianAmeteAlem,
39+
Gregorian,
40+
Hebrew,
41+
Indian,
42+
HijriTabularTypeIIFriday,
43+
// Not needed by Temporal and has some bugs
44+
// https://github.com/unicode-org/icu4x/issues/7049#issuecomment-3384358307
45+
// HijriSimulatedMecca,
46+
HijriTabularTypeIIThursday,
47+
HijriUmmAlQura,
48+
Iso,
49+
Japanese,
50+
JapaneseExtended,
51+
Persian,
52+
Roc,
53+
// Note: This doesn't cover Julian, since it's not in AnyCalendar
54+
}
55+
56+
impl From<AnyCalendarKind> for icu_calendar::AnyCalendarKind {
57+
fn from(other: AnyCalendarKind) -> Self {
58+
match other {
59+
AnyCalendarKind::Buddhist => Self::Buddhist,
60+
AnyCalendarKind::Chinese => Self::Chinese,
61+
AnyCalendarKind::Coptic => Self::Coptic,
62+
AnyCalendarKind::Dangi => Self::Dangi,
63+
AnyCalendarKind::Ethiopian => Self::Ethiopian,
64+
AnyCalendarKind::EthiopianAmeteAlem => Self::EthiopianAmeteAlem,
65+
AnyCalendarKind::Gregorian => Self::Gregorian,
66+
AnyCalendarKind::Hebrew => Self::Hebrew,
67+
AnyCalendarKind::Indian => Self::Indian,
68+
AnyCalendarKind::HijriTabularTypeIIFriday => Self::HijriTabularTypeIIFriday,
69+
// AnyCalendarKind::HijriSimulatedMecca => Self::HijriSimulatedMecca,
70+
AnyCalendarKind::HijriTabularTypeIIThursday => Self::HijriTabularTypeIIThursday,
71+
AnyCalendarKind::HijriUmmAlQura => Self::HijriUmmAlQura,
72+
AnyCalendarKind::Iso => Self::Iso,
73+
AnyCalendarKind::Japanese => Self::Japanese,
74+
AnyCalendarKind::JapaneseExtended => Self::JapaneseExtended,
75+
AnyCalendarKind::Persian => Self::Persian,
76+
AnyCalendarKind::Roc => Self::Roc,
77+
}
78+
}
79+
}
80+
81+
macro_rules! unwrap_or_return(
82+
($e:expr) => {
83+
{
84+
let Some(r) = $e else {
85+
return;
86+
};
87+
r
88+
}
89+
}
90+
);
91+
92+
fuzz_target!(|data: FuzzInput| {
93+
let calendar = AnyCalendar::new(data.cal.into());
94+
95+
let mut options = DateFromFieldsOptions::default();
96+
97+
options.overflow = if data.overflow_constrain {
98+
Some(Overflow::Constrain)
99+
} else {
100+
Some(Overflow::Reject)
101+
};
102+
103+
let mut fields = DateFields::default();
104+
// Temporal only cares about validity in ±270k. We generously test outside of that.
105+
// We should error on these dates instead, or otherwise handle them: https://github.com/unicode-org/icu4x/issues/7049
106+
fields.extended_year = Some(data.year % (i32::MAX / 16));
107+
fields.day = Some(unwrap_or_return!(NonZeroU8::new(data.day)));
108+
match data.month_interpretation {
109+
MonthInterpretation::Ordinal => {
110+
fields.ordinal_month = Some(unwrap_or_return!(NonZeroU8::new(data.month)));
111+
}
112+
MonthInterpretation::CodeNormal => {
113+
fields.month_code = Some(unwrap_or_return!(MonthCode::new_normal(data.month)));
114+
}
115+
MonthInterpretation::CodeLeap => {
116+
fields.month_code = Some(unwrap_or_return!(MonthCode::new_leap(data.month)));
117+
}
118+
};
119+
let _date = Date::try_from_fields(fields, options, calendar);
120+
});

0 commit comments

Comments
 (0)