Skip to content

Commit

Permalink
address review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
tshepang committed Jul 30, 2022
1 parent f4803a7 commit e82c245
Show file tree
Hide file tree
Showing 28 changed files with 178 additions and 80 deletions.
171 changes: 128 additions & 43 deletions ci/date-check/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{

use chrono::{Datelike as _, Month, TimeZone as _, Utc};
use glob::glob;
use regex::Regex;
use regex::{Regex, RegexSet};

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
struct Date {
Expand Down Expand Up @@ -36,41 +36,56 @@ impl fmt::Display for Date {
}
}

fn make_date_regex() -> Regex {
Regex::new(r"[aA]s\s+of\s+(\w+)\s+(\d{4})").unwrap()
fn make_date_regex() -> Vec<Regex> {
let patterns = [
r"<!--\s+date-check:\s+(\w+)\s+(\d+{4})\s+-->",
r"<!--\s+date-check\s+-->\s+(\w+)\s+(\d+{4})",
];
let set = RegexSet::new(&patterns).unwrap();
set.patterns()
.iter()
.map(|pattern| Regex::new(pattern).unwrap())
.collect()
}

fn collect_dates_from_file(date_regex: &Regex, text: &str) -> Vec<(usize, Date)> {
let mut line = 1;
let mut end_of_last_cap = 0;
date_regex
.captures_iter(text)
.map(|cap| {
(
cap.get(0).unwrap().range(),
Date {
year: cap[2].parse().unwrap(),
month: Month::from_str(&cap[1]).unwrap().number_from_month(),
},
)
})
.map(|(byte_range, date)| {
line += text[end_of_last_cap..byte_range.end]
.chars()
.filter(|c| *c == '\n')
.count();
end_of_last_cap = byte_range.end;
(line, date)
})
.collect()
fn collect_dates_from_file(date_regexes: &[Regex], text: &str) -> Vec<(usize, Date)> {
let mut output = Vec::new();
for date_regex in date_regexes {
let mut line = 1;
let mut end_of_last_cap = 0;
let results: Vec<_> = date_regex
.captures_iter(text)
.filter_map(|cap| {
if let (Some(year), Some(month)) = (cap.get(2), cap.get(1)) {
let year = year.as_str().parse().expect("year");
let month = Month::from_str(month.as_str())
.expect("month")
.number_from_month();
Some((cap.get(0).expect("all").range(), Date { year, month }))
} else {
None
}
})
.map(|(byte_range, date)| {
line += text[end_of_last_cap..byte_range.end]
.chars()
.filter(|c| *c == '\n')
.count();
end_of_last_cap = byte_range.end;
(line, date)
})
.collect();
output.extend(results);
}
output
}

fn collect_dates(paths: impl Iterator<Item = PathBuf>) -> BTreeMap<PathBuf, Vec<(usize, Date)>> {
let date_regex = make_date_regex();
let date_regexes = make_date_regex();
let mut data = BTreeMap::new();
for path in paths {
let text = fs::read_to_string(&path).unwrap();
let dates = collect_dates_from_file(&date_regex, &text);
let dates = collect_dates_from_file(&date_regexes, &text);
if !dates.is_empty() {
data.insert(path, dates);
}
Expand Down Expand Up @@ -174,59 +189,129 @@ mod tests {

#[test]
fn test_date_regex() {
let regex = make_date_regex();
assert!(regex.is_match("As of July 2022"));
assert!(regex.is_match("As of Jul 2022"));
assert!(regex.is_match("As of july 2022"));
assert!(regex.is_match("As of jul 2022"));
assert!(regex.is_match("as of jul 2022"));
let regexes = &make_date_regex();
assert!(regexes[0].is_match("<!-- date-check: jan 2021 -->"));
assert!(regexes[0].is_match("<!-- date-check: january 2021 -->"));
assert!(regexes[0].is_match("<!-- date-check: Jan 2021 -->"));
assert!(regexes[0].is_match("<!-- date-check: January 2021 -->"));
assert!(regexes[1].is_match("<!-- date-check --> jan 2021"));
assert!(regexes[1].is_match("<!-- date-check --> january 2021"));
assert!(regexes[1].is_match("<!-- date-check --> Jan 2021"));
assert!(regexes[1].is_match("<!-- date-check --> January 2021"));
}

#[test]
fn test_collect_dates_from_file() {
let text = "Test1\nAs of Jan 2021\nTest2\nAs of Feb 2021 \
\nTest3\nTest4\nAs of march 2021Bar\nas of apr 2021 \
\nTest5\nTest6\nTest7\n\n\nas of\n\n may 2021\nTest8
let text = r"
Test1
<!-- date-check: jan 2021 -->
Test2
Foo<!-- date-check: february 2021
-->
Test3
Test4
Foo<!-- date-check: Mar 2021 -->Bar
<!-- date-check: April 2021
-->
Test5
Test6
Test7
<!-- date-check:
may 2021 -->
Test8
Test1
<!-- date-check --> jan 2021
Test2
Foo<!-- date-check
--> february 2021
Test3
Test4
Foo<!-- date-check --> mar 2021 Bar
<!-- date-check
--> apr 2021
Test5
Test6
Test7
<!-- date-check
--> may 2021
Test8 \
";
assert_eq!(
collect_dates_from_file(&make_date_regex(), text),
vec![
(
2,
3,
Date {
year: 2021,
month: 1,
}
),
(
6,
Date {
year: 2021,
month: 2,
}
),
(
9,
Date {
year: 2021,
month: 3,
}
),
(
11,
Date {
year: 2021,
month: 4,
}
),
(
17,
Date {
year: 2021,
month: 5,
}
),
(
20,
Date {
year: 2021,
month: 1,
}
),
(
4,
23,
Date {
year: 2021,
month: 2,
}
),
(
7,
26,
Date {
year: 2021,
month: 3,
}
),
(
8,
28,
Date {
year: 2021,
month: 4,
}
),
(
16,
34,
Date {
year: 2021,
month: 5,
}
),
]
],
);
}
}
2 changes: 1 addition & 1 deletion src/backend/backend-agnostic.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- toc -->

As of October 2021, `rustc_codegen_ssa` provides an
As of <!-- date-check --> October 2021, `rustc_codegen_ssa` provides an
abstract interface for all backends to implement, to allow other codegen
backends (e.g. [Cranelift]).

Expand Down
4 changes: 2 additions & 2 deletions src/backend/updating-llvm.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ Example PRs look like:

## Feature updates

> Note that this information is as of the time of this writing <!-- date:
2021-10 --> (October 2021). The process for updating LLVM changes with
> Note that this information is as of the time of this writing,
<!-- date-check --> October 2021. The process for updating LLVM changes with

This comment has been minimized.

Copy link
@camelid

camelid Jul 31, 2022

Member

In this and other places, you need to put the comment at the end of the previous line or split it somehow. The reason it was split before is because Markdown goes awry when a line starts with a comment.

This comment has been minimized.

Copy link
@tshepang

tshepang Jul 31, 2022

Author Member

fixed by df6b805

practically all LLVM updates, so this may be out of date!

Unlike bugfixes, updating to pick up a new feature of LLVM typically requires a
Expand Down
2 changes: 1 addition & 1 deletion src/borrow_check/region_inference/member_constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ member constraints come in.
## Choices are always lifetime parameters

At present, the "choice" regions from a member constraint are always lifetime
parameters from the current function. As of October 2021,
parameters from the current function. As of <!-- date-check --> October 2021,
this falls out from the placement of impl Trait, though in the future it may not
be the case. We take some advantage of this fact, as it simplifies the current
code. In particular, we don't have to consider a case like `'0 member of ['1,
Expand Down
24 changes: 18 additions & 6 deletions src/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,17 +437,29 @@ Just a few things to keep in mind:
the project.

- The date the comment was added, e.g. instead of writing _"Currently, ..."_
or _"As of now, ..."_, consider writing
_"As of January 2021, ..."_.
We have a CI action (in `~/.github/workflows/date-check.yml`)
that generates a monthly issue with any of these that are over 6 months old.

The following formats are accepted:
or _"As of now, ..."_,
consider adding the date, in one of the following formats:
- Jan 2021
- January 2021
- jan 2021
- january 2021

There is a CI action (in "~/.github/workflows/date-check.yml")
that generates a monthly issue with any of these that are over 6 months old.

For the action to pick the date, add this annotation:

<!-- date-check -->

Example:

As of <!-- date-check --> Jul 2022, the foo did the bar.

For cases where the date should not be part of the visible rendered output,
use the following instead:

<!-- date-check: Jul 2022 -->

- A link to a relevant WG, tracking issue, `rustc` rustdoc page, or similar, that may provide
further explanation for the change process or a way to verify that the information is not
outdated.
Expand Down
2 changes: 1 addition & 1 deletion src/conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Formatting is checked by the `tidy` script. It runs automatically when you do

If you want to use format-on-save in your editor, the pinned version of
`rustfmt` is built under `build/<target>/stage0/bin/rustfmt`. You'll have to
pass the <!-- as of April 2022 --> `--edition=2021` argument yourself when calling
pass the <!-- date-check: April 2022 --> `--edition=2021` argument yourself when calling
`rustfmt` directly.

[fmt]: https://github.com/rust-dev-tools/fmt-rfcs
Expand Down
2 changes: 1 addition & 1 deletion src/crates-io.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ reasons:
- The dependency may have transitive dependencies that have one of the above
problems.

As of February 2022, there is no official policy for vetting
As of <!-- date-check --> February 2022, there is no official policy for vetting
new dependencies to the compiler. Generally, new dependencies are not added
to the compiler unless there is a good reason to do so.

Expand Down
2 changes: 1 addition & 1 deletion src/diagnostics/diagnostic-items.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ A new diagnostic item can be added with these two steps:
For the naming conventions of diagnostic items, please refer to
[*Naming Conventions*](#naming-conventions).

2. As of February 2022, diagnostic items in code are
2. As of <!-- date-check --> February 2022, diagnostic items in code are
accessed via symbols in [`rustc_span::symbol::sym`]. To add your newly
created diagnostic item simply open the module file and add the name (In
this case `Cat`) at the correct point in the list.
Expand Down
2 changes: 1 addition & 1 deletion src/diagnostics/lintstore.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ default lint level and other metadata come from. These are normally defined by
way of the [`declare_lint!`] macro, which boils down to a static with type
`&rustc_session::lint::Lint`.

As of February 2022, we lint against direct declarations
As of <!-- date-check --> February 2022, we lint against direct declarations
without the use of the macro today (although this may change in the future, as
the macro is somewhat unwieldy to add new fields to, like all macros).

Expand Down
2 changes: 1 addition & 1 deletion src/diagnostics/translation.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ returned by `Emitter::fluent_bundle`. This bundle is used preferentially when
translating messages, the fallback bundle is only used if the primary bundle is
missing a message or not provided.

As of June 2022, there are no locale bundles
As of <!-- date-check --> June 2022, there are no locale bundles
distributed with the compiler, but mechanisms are implemented for loading
bundles.

Expand Down
2 changes: 1 addition & 1 deletion src/git.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ no changes added to commit (use "git add" and/or "git commit -a")
These changes are not changes to files: they are changes to submodules (more on
this [later](#git-submodules)). To get rid of those, run `git submodule update`
(or run any `x.py` command, which will automatically update the submodules).
Note that there is (as of February 2022) a [bug][#77620] if you use
Note that there is (as of <!-- date-check --> February 2022) a [bug][#77620] if you use
worktrees, submodules, and `x.py` in a commit hook. If you run into an error
like:

Expand Down
5 changes: 3 additions & 2 deletions src/llvm-coverage-instrumentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,10 @@ properly-configured variables in LLVM IR, according to very specific
details of the [_LLVM Coverage Mapping Format_][coverage-mapping-format]
(Version 6).[^llvm-and-covmap-versions]

[^llvm-and-covmap-versions]: The Rust compiler (as of December 2021)
[^llvm-and-covmap-versions]: The Rust compiler (as of <!-- date-check --> December 2021)
supports _LLVM Coverage Mapping Format_ Version 5 or 6. Version 5
was introduced in _LLVM 12_, which is (as of this writing) the minimum LLVM
was introduced in _LLVM 12_,
which is (as of <!-- date-check: December 2021--> this writing) the minimum LLVM
version supported by the current version of Rust. Version 6 was introduced in
_LLVM 13_, which is currently the default LLVM version for Rust. The Rust
compiler will automatically use the most up-to-date coverage mapping format
Expand Down
2 changes: 1 addition & 1 deletion src/opaque-types-type-alias-impl-trait.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ it implements `Bar`. Therefore, any of `Bar`'s interface can be used on a `Foo`,
but nothing else (regardless of whether it implements any other traits).

Since there needs to be a concrete background type,
you can (as of January 2021) express that type
you can (as of <!-- date-check --> January 2021) express that type
by using the opaque type in a "defining use site".

```rust,ignore
Expand Down
2 changes: 1 addition & 1 deletion src/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ Moreover, the compiler wasn't originally built to use a query system; the query
system has been retrofitted into the compiler, so parts of it are not query-fied
yet. Also, LLVM isn't our code, so that isn't querified either. The plan is to
eventually query-fy all of the steps listed in the previous section,
but as of November 2021, only the steps between HIR and
but as of <!-- date-check --> November 2021, only the steps between HIR and
LLVM IR are query-fied. That is, lexing, parsing, name resolution, and macro
expansion are done all at once for the whole program.

Expand Down
Loading

0 comments on commit e82c245

Please sign in to comment.