Bug 1623418 - Add env_logger to SmooshMonkey. r=arai
authorNicolas B. Pierron <nicolas.b.pierron@nbp.name>
Tue, 24 Mar 2020 17:59:12 +0000
changeset 520256 44cdc3311ba7c47f487235e7fd8a5f1fc428dec9
parent 520255 e22128209b5092c565c2a601ac82b706feeddd25
child 520257 c72b367c63445068a88b1269fd4f753a8b7a8973
push id37246
push useropoprus@mozilla.com
push dateWed, 25 Mar 2020 03:40:33 +0000
treeherdermozilla-central@14b59d4adc95 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersarai
bugs1623418
milestone76.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1623418 - Add env_logger to SmooshMonkey. r=arai Differential Revision: https://phabricator.services.mozilla.com/D67449
Cargo.lock
js/src/frontend/Frontend2.cpp
js/src/frontend/Frontend2.h
js/src/frontend/smoosh/Cargo.toml
js/src/frontend/smoosh/src/lib.rs
js/src/shell/js.cpp
third_party/rust/humantime/.cargo-checksum.json
third_party/rust/humantime/Cargo.toml
third_party/rust/humantime/README.md
third_party/rust/humantime/src/date.rs
third_party/rust/humantime/src/duration.rs
third_party/rust/humantime/src/lib.rs
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1905,19 +1905,19 @@ dependencies = [
 [[package]]
 name = "httparse"
 version = "1.3.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "e8734b0cfd3bc3e101ec59100e101c2eecd19282202e87808b3037b442777a83"
 
 [[package]]
 name = "humantime"
-version = "1.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0484fda3e7007f2a4a0d9c3a703ca38c71c54c55602ce4660c419fd32e188c9e"
+version = "1.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f"
 dependencies = [
  "quick-error",
 ]
 
 [[package]]
 name = "hyper"
 version = "0.12.19"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3968,17 +3968,19 @@ version = "1.2.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "5c2fb2ec9bcd216a5b0d0ccf31ab17b5ed1d627960edff65bbe95d3ce221cefc"
 
 [[package]]
 name = "smoosh"
 version = "0.1.0"
 dependencies = [
  "bumpalo",
+ "env_logger",
  "jsparagus",
+ "log",
 ]
 
 [[package]]
 name = "socket2"
 version = "0.3.10"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "df028e0e632c2a1823d920ad74895e7f9128e6438cbc4bc6fd1f180e644767b9"
 dependencies = [
--- a/js/src/frontend/Frontend2.cpp
+++ b/js/src/frontend/Frontend2.cpp
@@ -279,16 +279,18 @@ class AutoFreeSmooshParseResult {
       : result_(result) {}
   ~AutoFreeSmooshParseResult() {
     if (result_) {
       free_smoosh_parse_result(*result_);
     }
   }
 };
 
+void InitSmoosh() { init_smoosh(); }
+
 void ReportSmooshCompileError(JSContext* cx, ErrorMetadata&& metadata,
                               int errorNumber, ...) {
   va_list args;
   va_start(args, errorNumber);
   ReportCompileErrorUTF8(cx, std::move(metadata), /* notes = */ nullptr,
                          errorNumber, &args);
   va_end(args);
 }
--- a/js/src/frontend/Frontend2.h
+++ b/js/src/frontend/Frontend2.h
@@ -32,16 +32,19 @@ class GlobalScriptInfo;
 // declarations in the simple way.
 class Smoosh {
  public:
   static JSScript* compileGlobalScript(
       CompilationInfo& compilationInfo,
       JS::SourceText<mozilla::Utf8Unit>& srcBuf, bool* unimplemented);
 };
 
+// Initialize SmooshMonkey globals, such as the logging system.
+void InitSmoosh();
+
 // Use the SmooshMonkey frontend to parse and free the generated AST. Returns
 // true if no error were detected while parsing.
 MOZ_MUST_USE bool SmooshParseScript(JSContext* cx, const uint8_t* bytes,
                                     size_t length);
 MOZ_MUST_USE bool SmooshParseModule(JSContext* cx, const uint8_t* bytes,
                                     size_t length);
 
 }  // namespace frontend
--- a/js/src/frontend/smoosh/Cargo.toml
+++ b/js/src/frontend/smoosh/Cargo.toml
@@ -2,11 +2,16 @@
 name = "smoosh"
 version = "0.1.0"
 authors = ["The jsparagus Project Developers"]
 edition = "2018"
 license = "MIT/Apache-2.0"
 
 [dependencies]
 bumpalo = "2.6.0"
+log = "0.4"
+# Setup RUST_LOG logging.
+# Disable regex feature for code size.
+env_logger = {version = "0.6", default-features = false}
+# For non-jsparagus developers.
 jsparagus = { git = "https://github.com/mozilla-spidermonkey/jsparagus", rev = "1e747c70bd5b2e959880a57f57ed435660aaafe6" }
 # For local development, replace above with
 # jsparagus = { path = "{path to jsparagus}" }
--- a/js/src/frontend/smoosh/src/lib.rs
+++ b/js/src/frontend/smoosh/src/lib.rs
@@ -11,16 +11,17 @@
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the Licenses is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the Licenses for the specific language governing permissions and
  * limitations under the Licenses.
  */
 
 use bumpalo;
+use env_logger;
 use jsparagus::ast::source_atom_set::SourceAtomSet;
 use jsparagus::ast::types::Program;
 use jsparagus::emitter::{
     emit, BindingName, EmitError, EmitOptions, EmitResult, GCThing, ScopeData, ScopeNote,
 };
 use jsparagus::parser::{parse_module, parse_script, ParseError, ParseOptions};
 use std::boxed::Box;
 use std::cell::RefCell;
@@ -265,16 +266,30 @@ impl SmooshResult {
 }
 
 enum SmooshError {
     GenericError(String),
     NotImplemented,
 }
 
 #[no_mangle]
+pub unsafe extern "C" fn init_smoosh() {
+    // Gecko might set a logger before we do, which is all fine; try to
+    // initialize ours, and reset the FilterLevel env_logger::try_init might
+    // have set to what it was in case of initialization failure
+    let filter = log::max_level();
+    match env_logger::try_init() {
+        Ok(_) => {}
+        Err(_) => {
+            log::set_max_level(filter);
+        }
+    }
+}
+
+#[no_mangle]
 pub unsafe extern "C" fn run_smoosh(
     text: *const u8,
     text_len: usize,
     options: &SmooshCompileOptions,
 ) -> SmooshResult {
     let text = str::from_utf8(slice::from_raw_parts(text, text_len)).expect("Invalid UTF8");
     let allocator = Box::new(bumpalo::Bump::new());
     match smoosh(&allocator, text, options) {
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -10145,16 +10145,17 @@ static bool OptionFailure(const char* op
 }
 
 static MOZ_MUST_USE bool ProcessArgs(JSContext* cx, OptionParser* op) {
   ShellContext* sc = GetShellContext(cx);
 
 #ifdef JS_ENABLE_SMOOSH
   if (op->getBoolOption("smoosh")) {
     JS::ContextOptionsRef(cx).setTrySmoosh(true);
+    js::frontend::InitSmoosh();
   }
 
   if (const char* filename = op->getStringOption("not-implemented-watchfile")) {
     FILE* out = fopen(filename, "a");
     MOZ_RELEASE_ASSERT(out);
     setbuf(out, nullptr);  // Make unbuffered
     cx->runtime()->parserWatcherFile.init(out);
     JS::ContextOptionsRef(cx).setTrackNotImplemented(true);
--- a/third_party/rust/humantime/.cargo-checksum.json
+++ b/third_party/rust/humantime/.cargo-checksum.json
@@ -1,1 +1,1 @@
-{"files":{"Cargo.toml":"834d5faba5920aaf480fb085fed13244b16559aa8471b67c7412b105df369d1d","LICENSE-APACHE":"c6596eb7be8581c18be736c846fb9173b69eccf6ef94c5135893ec56bd92ba08","LICENSE-MIT":"f6deca8261a8f4a3403dc74c725c46051157fd36c27cd4b100277eb1f303ad11","README.md":"4ff0d6dacf16da81b2d856f96b2a4f1210d82fe43048899a7da9bb0dc5ecc693","benches/datetime_format.rs":"a44c7ffb3c9515e92828564df8f91a86470343a2fa7e1a08bc2bc7397ba2591c","benches/datetime_parse.rs":"336a241755ccfa546d1840e56a40218c4f98f22d7d274829c5102ec280f2d963","bulk.yaml":"17c2548388e0cd3a63473021a2f1e4ddedee082d79d9167cb31ad06a1890d3fc","src/date.rs":"2fef2fa1fdd30086557f44d2f4fae6be1ee65e21c61d9eb40f1e51a9148b970f","src/duration.rs":"300e01c4e61a3495ebb31fb3a752204c5955d58f53c283deb87782a867fd2f45","src/lib.rs":"9f6637ccc38c00b4a90ebf4fcc16a0af070984658c205f579518c355fdbeb5f6","src/wrapper.rs":"5bbdaf43256b445a8ca3a6b3eded9dd4fa8fb4dadf3683a5bac9648d91117396","vagga.yaml":"59761e5138a3015ef5654fec095ac8f1587cd23529b37822dd540b866fe4cd5b"},"package":"0484fda3e7007f2a4a0d9c3a703ca38c71c54c55602ce4660c419fd32e188c9e"}
\ No newline at end of file
+{"files":{"Cargo.toml":"ae7f884d13f5d849afd58b5db15510396832df7f648b0095e43bfdfa600b2ba3","LICENSE-APACHE":"c6596eb7be8581c18be736c846fb9173b69eccf6ef94c5135893ec56bd92ba08","LICENSE-MIT":"f6deca8261a8f4a3403dc74c725c46051157fd36c27cd4b100277eb1f303ad11","README.md":"e4bb65f28ddffb11d7eb337e9585947651f2fc11a5e4290f0ca126e21c582c1e","benches/datetime_format.rs":"a44c7ffb3c9515e92828564df8f91a86470343a2fa7e1a08bc2bc7397ba2591c","benches/datetime_parse.rs":"336a241755ccfa546d1840e56a40218c4f98f22d7d274829c5102ec280f2d963","bulk.yaml":"17c2548388e0cd3a63473021a2f1e4ddedee082d79d9167cb31ad06a1890d3fc","src/date.rs":"ea9924869a2484e333df2a845009593dd0062bb3b3e1a5ef9cefc05ec0a41196","src/duration.rs":"a5d4756451f495a3d5df0c872caa6304dd81ae075f0e204c8145c11c7c8f698b","src/lib.rs":"59dcc8a1ed89ecde199d59a7f71e550b461f87858b4becffb0a183994bafdd7c","src/wrapper.rs":"5bbdaf43256b445a8ca3a6b3eded9dd4fa8fb4dadf3683a5bac9648d91117396","vagga.yaml":"59761e5138a3015ef5654fec095ac8f1587cd23529b37822dd540b866fe4cd5b"},"package":"df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f"}
\ No newline at end of file
--- a/third_party/rust/humantime/Cargo.toml
+++ b/third_party/rust/humantime/Cargo.toml
@@ -1,23 +1,23 @@
 # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
 #
 # When uploading crates to the registry Cargo will automatically
 # "normalize" Cargo.toml files for maximal compatibility
 # with all versions of Cargo and also rewrite `path` dependencies
-# to registry (e.g. crates.io) dependencies
+# to registry (e.g., crates.io) dependencies
 #
 # If you believe there's an error in this file please file an
 # issue against the rust-lang/cargo repository. If you're
 # editing this file be aware that the upstream Cargo.toml
 # will likely look very different (and much more reasonable)
 
 [package]
 name = "humantime"
-version = "1.1.1"
+version = "1.3.0"
 authors = ["Paul Colomiets <paul@colomiets.name>"]
 description = "    A parser and formatter for std::time::{Duration, SystemTime}\n"
 homepage = "https://github.com/tailhook/humantime"
 documentation = "https://docs.rs/humantime"
 readme = "README.md"
 keywords = ["time", "human", "human-friendly", "parser", "duration"]
 categories = ["date-and-time"]
 license = "MIT/Apache-2.0"
--- a/third_party/rust/humantime/README.md
+++ b/third_party/rust/humantime/README.md
@@ -39,19 +39,20 @@ test datetime_utc_parse_nanos   ... benc
 test datetime_utc_parse_seconds ... bench:         204 ns/iter (+/- 18)
 test rfc3339_humantime_millis   ... bench:          28 ns/iter (+/- 1)
 test rfc3339_humantime_nanos    ... bench:          36 ns/iter (+/- 2)
 test rfc3339_humantime_seconds  ... bench:          24 ns/iter (+/- 1)
 
 test result: ok. 0 passed; 0 failed; 0 ignored; 6 measured; 0 filtered out
 ```
 
-See [serde-humantime] for serde integration.
+See [humantime-serde] for serde integration (previous crate [serde-humantime] looks unmaintained).
 
 [serde-humantime]: https://docs.rs/serde-humantime/0.1.1/serde_humantime/
+[humantime-serde]: https://docs.rs/humantime-serde
 
 License
 =======
 
 Licensed under either of
 
 * Apache License, Version 2.0, (./LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
 * MIT license (./LICENSE-MIT or http://opensource.org/licenses/MIT)
--- a/third_party/rust/humantime/src/date.rs
+++ b/third_party/rust/humantime/src/date.rs
@@ -45,25 +45,27 @@ quick_error! {
         }
         /// Other formatting errors
         InvalidFormat {
             display("timestamp format is invalid")
         }
     }
 }
 
-#[derive(Debug, PartialEq, Eq)]
+#[derive(Debug, Clone, PartialEq, Eq)]
 enum Precision {
     Smart,
     Seconds,
+    Millis,
+    Micros,
     Nanos,
 }
 
 /// A wrapper type that allows you to Display a SystemTime
-#[derive(Debug)]
+#[derive(Debug, Clone)]
 pub struct Rfc3339Timestamp(SystemTime, Precision);
 
 #[inline]
 fn two_digits(b1: u8, b2: u8) -> Result<u64, Error> {
     if b1 < b'0' || b2 < b'0' || b1 > b'9' || b2 > b'9' {
         return Err(Error::InvalidDigit);
     }
     Ok(((b1 - b'0')*10 + (b2 - b'0')) as u64)
@@ -203,16 +205,34 @@ pub fn format_rfc3339(system_time: Syste
 ///
 /// This format always shows timestamp without fractional seconds.
 ///
 /// The value is always UTC and ignores system timezone.
 pub fn format_rfc3339_seconds(system_time: SystemTime) -> Rfc3339Timestamp {
     return Rfc3339Timestamp(system_time, Precision::Seconds);
 }
 
+/// Format an RFC3339 timestamp `2018-02-14T00:28:07.000Z`
+///
+/// This format always shows milliseconds even if millisecond value is zero.
+///
+/// The value is always UTC and ignores system timezone.
+pub fn format_rfc3339_millis(system_time: SystemTime) -> Rfc3339Timestamp {
+    return Rfc3339Timestamp(system_time, Precision::Millis);
+}
+
+/// Format an RFC3339 timestamp `2018-02-14T00:28:07.000000Z`
+///
+/// This format always shows microseconds even if microsecond value is zero.
+///
+/// The value is always UTC and ignores system timezone.
+pub fn format_rfc3339_micros(system_time: SystemTime) -> Rfc3339Timestamp {
+    return Rfc3339Timestamp(system_time, Precision::Micros);
+}
+
 /// Format an RFC3339 timestamp `2018-02-14T00:28:07.000000000Z`
 ///
 /// This format always shows nanoseconds even if nanosecond value is zero.
 ///
 /// The value is always UTC and ignores system timezone.
 pub fn format_rfc3339_nanos(system_time: SystemTime) -> Rfc3339Timestamp {
     return Rfc3339Timestamp(system_time, Precision::Nanos);
 }
@@ -295,44 +315,64 @@ impl fmt::Display for Rfc3339Timestamp {
         buf[9] = b'0' + (mday % 10) as u8;
         buf[11] = b'0' + (secs_of_day / 3600 / 10) as u8;
         buf[12] = b'0' + (secs_of_day / 3600 % 10) as u8;
         buf[14] = b'0' + (secs_of_day / 60 / 10 % 6) as u8;
         buf[15] = b'0' + (secs_of_day / 60 % 10) as u8;
         buf[17] = b'0' + (secs_of_day / 10 % 6) as u8;
         buf[18] = b'0' + (secs_of_day % 10) as u8;
 
-        if self.1 == Seconds || nanos == 0 && self.1 == Smart {
+        let offset = if self.1 == Seconds || nanos == 0 && self.1 == Smart {
             buf[19] = b'Z';
-            f.write_str(unsafe { str::from_utf8_unchecked(&buf[..20]) })
+            19
+        } else if self.1 == Millis {
+            buf[20] = b'0' + (nanos / 100_000_000) as u8;
+            buf[21] = b'0' + (nanos / 10_000_000 % 10) as u8;
+            buf[22] = b'0' + (nanos / 1_000_000 % 10) as u8;
+            buf[23] = b'Z';
+            23
+        } else if self.1 == Micros {
+            buf[20] = b'0' + (nanos / 100_000_000) as u8;
+            buf[21] = b'0' + (nanos / 10_000_000 % 10) as u8;
+            buf[22] = b'0' + (nanos / 1_000_000 % 10) as u8;
+            buf[23] = b'0' + (nanos / 100_000 % 10) as u8;
+            buf[24] = b'0' + (nanos / 10_000 % 10) as u8;
+            buf[25] = b'0' + (nanos / 1_000 % 10) as u8;
+            buf[26] = b'Z';
+            26
         } else {
             buf[20] = b'0' + (nanos / 100_000_000) as u8;
             buf[21] = b'0' + (nanos / 10_000_000 % 10) as u8;
             buf[22] = b'0' + (nanos / 1_000_000 % 10) as u8;
             buf[23] = b'0' + (nanos / 100_000 % 10) as u8;
             buf[24] = b'0' + (nanos / 10_000 % 10) as u8;
             buf[25] = b'0' + (nanos / 1_000 % 10) as u8;
             buf[26] = b'0' + (nanos / 100 % 10) as u8;
             buf[27] = b'0' + (nanos / 10 % 10) as u8;
             buf[28] = b'0' + (nanos / 1 % 10) as u8;
-            // we know our chars are all ascii
-            f.write_str(unsafe { str::from_utf8_unchecked(&buf[..]) })
-        }
+            // 29th is 'Z'
+            29
+        };
+
+        // we know our chars are all ascii
+        f.write_str(unsafe { str::from_utf8_unchecked(&buf[..offset+1]) })
     }
 }
 
 #[cfg(test)]
 mod test {
     extern crate time;
     extern crate rand;
 
     use std::str::from_utf8;
     use self::rand::Rng;
     use std::time::{UNIX_EPOCH, SystemTime, Duration};
     use super::{parse_rfc3339, parse_rfc3339_weak, format_rfc3339};
+    use super::{format_rfc3339_millis, format_rfc3339_micros};
+    use super::{format_rfc3339_nanos};
     use super::max;
 
     fn from_sec(sec: u64) -> (String, SystemTime) {
         let s = time::at_utc(time::Timespec { sec: sec as i64, nsec: 0 })
                   .rfc3339().to_string();
         let time = UNIX_EPOCH + Duration::new(sec, 0);
         return (s, time)
     }
@@ -371,16 +411,60 @@ mod test {
             format_rfc3339(UNIX_EPOCH + Duration::new(1518563312, 0)).to_string(),
             "2018-02-13T23:08:32Z");
         assert_eq!(
             format_rfc3339(UNIX_EPOCH + Duration::new(1325376000, 0)).to_string(),
             "2012-01-01T00:00:00Z");
     }
 
     #[test]
+    fn smoke_tests_format_millis() {
+        assert_eq!(
+            format_rfc3339_millis(UNIX_EPOCH +
+                Duration::new(0, 0)).to_string(),
+            "1970-01-01T00:00:00.000Z");
+        assert_eq!(
+            format_rfc3339_millis(UNIX_EPOCH +
+                Duration::new(1518563312, 123_000_000)).to_string(),
+            "2018-02-13T23:08:32.123Z");
+    }
+
+    #[test]
+    fn smoke_tests_format_micros() {
+        assert_eq!(
+            format_rfc3339_micros(UNIX_EPOCH +
+                Duration::new(0, 0)).to_string(),
+            "1970-01-01T00:00:00.000000Z");
+        assert_eq!(
+            format_rfc3339_micros(UNIX_EPOCH +
+                Duration::new(1518563312, 123_000_000)).to_string(),
+            "2018-02-13T23:08:32.123000Z");
+        assert_eq!(
+            format_rfc3339_micros(UNIX_EPOCH +
+                Duration::new(1518563312, 456_123_000)).to_string(),
+            "2018-02-13T23:08:32.456123Z");
+    }
+
+    #[test]
+    fn smoke_tests_format_nanos() {
+        assert_eq!(
+            format_rfc3339_nanos(UNIX_EPOCH +
+                Duration::new(0, 0)).to_string(),
+            "1970-01-01T00:00:00.000000000Z");
+        assert_eq!(
+            format_rfc3339_nanos(UNIX_EPOCH +
+                Duration::new(1518563312, 123_000_000)).to_string(),
+            "2018-02-13T23:08:32.123000000Z");
+        assert_eq!(
+            format_rfc3339_nanos(UNIX_EPOCH +
+                Duration::new(1518563312, 789_456_123)).to_string(),
+            "2018-02-13T23:08:32.789456123Z");
+    }
+
+    #[test]
     fn upper_bound() {
         let max = UNIX_EPOCH + Duration::new(max::SECONDS, 0);
         assert_eq!(parse_rfc3339(&max::TIMESTAMP).unwrap(), max);
         assert_eq!(format_rfc3339(max).to_string(), max::TIMESTAMP);
     }
 
     #[test]
     fn leap_second() {
--- a/third_party/rust/humantime/src/duration.rs
+++ b/third_party/rust/humantime/src/duration.rs
@@ -53,17 +53,17 @@ quick_error! {
             display(self_) -> ("{}", self_.description())
             description("value was empty")
         }
     }
 
 }
 
 /// A wrapper type that allows you to Display a Duration
-#[derive(Debug)]
+#[derive(Debug, Clone)]
 pub struct FormattedDuration(Duration);
 
 trait OverflowOp: Sized {
     fn mul(self, other: Self) -> Result<Self, Error>;
     fn add(self, other: Self) -> Result<Self, Error>;
 }
 
 impl OverflowOp for u64 {
--- a/third_party/rust/humantime/src/lib.rs
+++ b/third_party/rust/humantime/src/lib.rs
@@ -21,10 +21,13 @@
 mod duration;
 mod wrapper;
 mod date;
 
 pub use duration::{parse_duration, Error as DurationError};
 pub use duration::{format_duration, FormattedDuration};
 pub use wrapper::{Duration, Timestamp};
 pub use date::{parse_rfc3339, parse_rfc3339_weak, Error as TimestampError};
-pub use date::{format_rfc3339, format_rfc3339_seconds, format_rfc3339_nanos};
+pub use date::{
+    format_rfc3339, format_rfc3339_micros, format_rfc3339_millis, format_rfc3339_nanos,
+    format_rfc3339_seconds,
+};
 pub use date::{Rfc3339Timestamp};