Commit 6abadd57 authored by Mark Hammond's avatar Mark Hammond
Browse files

Bug 1639449 - Vendor new application-services to expose kinto migration and...

Bug 1639449 - Vendor new application-services to expose kinto migration and sync change notifications. r=lina

Differential Revision: https://phabricator.services.mozilla.com/D76092
parent f43c78c2
......@@ -25,7 +25,7 @@ rev = "0dc3e6e7c5371fe21f69b847f61c65fe6d6dc317"
[source."https://github.com/mozilla/application-services"]
git = "https://github.com/mozilla/application-services"
replace-with = "vendored-sources"
rev = "77a7f5eb12a8d93f2bd71bd4d844405e06743365"
rev = "57a07e89e9ac92756b60b67c4a6ee06975b86288"
[source."https://github.com/mozilla-spidermonkey/jsparagus"]
git = "https://github.com/mozilla-spidermonkey/jsparagus"
......
......@@ -1273,7 +1273,7 @@ checksum = "ff511d5dc435d703f4971bc399647c9bc38e20cb41452e3b9feb4765419ed3f3"
[[package]]
name = "error-support"
version = "0.1.0"
source = "git+https://github.com/mozilla/application-services?rev=77a7f5eb12a8d93f2bd71bd4d844405e06743365#77a7f5eb12a8d93f2bd71bd4d844405e06743365"
source = "git+https://github.com/mozilla/application-services?rev=57a07e89e9ac92756b60b67c4a6ee06975b86288#57a07e89e9ac92756b60b67c4a6ee06975b86288"
dependencies = [
"failure",
]
......@@ -1606,7 +1606,7 @@ dependencies = [
[[package]]
name = "fxa-client"
version = "0.1.0"
source = "git+https://github.com/mozilla/application-services?rev=77a7f5eb12a8d93f2bd71bd4d844405e06743365#77a7f5eb12a8d93f2bd71bd4d844405e06743365"
source = "git+https://github.com/mozilla/application-services?rev=57a07e89e9ac92756b60b67c4a6ee06975b86288#57a07e89e9ac92756b60b67c4a6ee06975b86288"
dependencies = [
"base64 0.12.0",
"byteorder",
......@@ -2295,7 +2295,7 @@ dependencies = [
[[package]]
name = "interrupt-support"
version = "0.1.0"
source = "git+https://github.com/mozilla/application-services?rev=77a7f5eb12a8d93f2bd71bd4d844405e06743365#77a7f5eb12a8d93f2bd71bd4d844405e06743365"
source = "git+https://github.com/mozilla/application-services?rev=57a07e89e9ac92756b60b67c4a6ee06975b86288#57a07e89e9ac92756b60b67c4a6ee06975b86288"
[[package]]
name = "intl-memoizer"
......@@ -3228,7 +3228,7 @@ dependencies = [
[[package]]
name = "nss"
version = "0.1.0"
source = "git+https://github.com/mozilla/application-services?rev=77a7f5eb12a8d93f2bd71bd4d844405e06743365#77a7f5eb12a8d93f2bd71bd4d844405e06743365"
source = "git+https://github.com/mozilla/application-services?rev=57a07e89e9ac92756b60b67c4a6ee06975b86288#57a07e89e9ac92756b60b67c4a6ee06975b86288"
dependencies = [
"base64 0.12.0",
"error-support",
......@@ -3242,12 +3242,12 @@ dependencies = [
[[package]]
name = "nss_build_common"
version = "0.1.0"
source = "git+https://github.com/mozilla/application-services?rev=77a7f5eb12a8d93f2bd71bd4d844405e06743365#77a7f5eb12a8d93f2bd71bd4d844405e06743365"
source = "git+https://github.com/mozilla/application-services?rev=57a07e89e9ac92756b60b67c4a6ee06975b86288#57a07e89e9ac92756b60b67c4a6ee06975b86288"
[[package]]
name = "nss_sys"
version = "0.1.0"
source = "git+https://github.com/mozilla/application-services?rev=77a7f5eb12a8d93f2bd71bd4d844405e06743365#77a7f5eb12a8d93f2bd71bd4d844405e06743365"
source = "git+https://github.com/mozilla/application-services?rev=57a07e89e9ac92756b60b67c4a6ee06975b86288#57a07e89e9ac92756b60b67c4a6ee06975b86288"
dependencies = [
"nss_build_common",
]
......@@ -3372,9 +3372,9 @@ dependencies = [
[[package]]
name = "once_cell"
version = "1.3.1"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1c601810575c99596d4afc46f78a678c80105117c379eb3650cf99b8a21ce5b"
checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d"
[[package]]
name = "opaque-debug"
......@@ -3894,7 +3894,7 @@ dependencies = [
[[package]]
name = "rc_crypto"
version = "0.1.0"
source = "git+https://github.com/mozilla/application-services?rev=77a7f5eb12a8d93f2bd71bd4d844405e06743365#77a7f5eb12a8d93f2bd71bd4d844405e06743365"
source = "git+https://github.com/mozilla/application-services?rev=57a07e89e9ac92756b60b67c4a6ee06975b86288#57a07e89e9ac92756b60b67c4a6ee06975b86288"
dependencies = [
"base64 0.12.0",
"ece",
......@@ -4454,7 +4454,7 @@ dependencies = [
[[package]]
name = "sql-support"
version = "0.1.0"
source = "git+https://github.com/mozilla/application-services?rev=77a7f5eb12a8d93f2bd71bd4d844405e06743365#77a7f5eb12a8d93f2bd71bd4d844405e06743365"
source = "git+https://github.com/mozilla/application-services?rev=57a07e89e9ac92756b60b67c4a6ee06975b86288#57a07e89e9ac92756b60b67c4a6ee06975b86288"
dependencies = [
"ffi-support",
"interrupt-support",
......@@ -4651,7 +4651,7 @@ dependencies = [
[[package]]
name = "sync-guid"
version = "0.1.0"
source = "git+https://github.com/mozilla/application-services?rev=77a7f5eb12a8d93f2bd71bd4d844405e06743365#77a7f5eb12a8d93f2bd71bd4d844405e06743365"
source = "git+https://github.com/mozilla/application-services?rev=57a07e89e9ac92756b60b67c4a6ee06975b86288#57a07e89e9ac92756b60b67c4a6ee06975b86288"
dependencies = [
"base64 0.12.0",
"rand",
......@@ -4662,7 +4662,7 @@ dependencies = [
[[package]]
name = "sync15"
version = "0.1.0"
source = "git+https://github.com/mozilla/application-services?rev=77a7f5eb12a8d93f2bd71bd4d844405e06743365#77a7f5eb12a8d93f2bd71bd4d844405e06743365"
source = "git+https://github.com/mozilla/application-services?rev=57a07e89e9ac92756b60b67c4a6ee06975b86288#57a07e89e9ac92756b60b67c4a6ee06975b86288"
dependencies = [
"base16",
"base64 0.12.0",
......@@ -4685,7 +4685,7 @@ dependencies = [
[[package]]
name = "sync15-traits"
version = "0.1.0"
source = "git+https://github.com/mozilla/application-services?rev=77a7f5eb12a8d93f2bd71bd4d844405e06743365#77a7f5eb12a8d93f2bd71bd4d844405e06743365"
source = "git+https://github.com/mozilla/application-services?rev=57a07e89e9ac92756b60b67c4a6ee06975b86288#57a07e89e9ac92756b60b67c4a6ee06975b86288"
dependencies = [
"failure",
"ffi-support",
......@@ -5301,7 +5301,7 @@ checksum = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce"
[[package]]
name = "viaduct"
version = "0.1.0"
source = "git+https://github.com/mozilla/application-services?rev=77a7f5eb12a8d93f2bd71bd4d844405e06743365#77a7f5eb12a8d93f2bd71bd4d844405e06743365"
source = "git+https://github.com/mozilla/application-services?rev=57a07e89e9ac92756b60b67c4a6ee06975b86288#57a07e89e9ac92756b60b67c4a6ee06975b86288"
dependencies = [
"failure",
"failure_derive",
......@@ -5417,7 +5417,7 @@ dependencies = [
[[package]]
name = "webext-storage"
version = "0.1.0"
source = "git+https://github.com/mozilla/application-services?rev=77a7f5eb12a8d93f2bd71bd4d844405e06743365#77a7f5eb12a8d93f2bd71bd4d844405e06743365"
source = "git+https://github.com/mozilla/application-services?rev=57a07e89e9ac92756b60b67c4a6ee06975b86288#57a07e89e9ac92756b60b67c4a6ee06975b86288"
dependencies = [
"error-support",
"failure",
......
......@@ -21,4 +21,4 @@ nsstring = { path = "../../../../xpcom/rust/nsstring" }
xpcom = { path = "../../../../xpcom/rust/xpcom" }
storage_variant = { path = "../../../../storage/variant" }
thin-vec = { version = "0.1", features = ["gecko-ffi"] }
fxa-client = { git = "https://github.com/mozilla/application-services", rev = "77a7f5eb12a8d93f2bd71bd4d844405e06743365", features = ["gecko"] }
fxa-client = { git = "https://github.com/mozilla/application-services", rev = "57a07e89e9ac92756b60b67c4a6ee06975b86288", features = ["gecko"] }
......@@ -8,14 +8,14 @@ edition = "2018"
[dependencies]
atomic_refcell = "0.1"
cstr = "0.1"
interrupt-support = { git = "https://github.com/mozilla/application-services", rev = "77a7f5eb12a8d93f2bd71bd4d844405e06743365" }
interrupt-support = { git = "https://github.com/mozilla/application-services", rev = "57a07e89e9ac92756b60b67c4a6ee06975b86288" }
log = "0.4"
moz_task = { path = "../../../xpcom/rust/moz_task" }
nserror = { path = "../../../xpcom/rust/nserror" }
nsstring = { path = "../../../xpcom/rust/nsstring" }
serde_json = "1"
storage_variant = { path = "../../../storage/variant" }
sync15-traits = { git = "https://github.com/mozilla/application-services", rev = "77a7f5eb12a8d93f2bd71bd4d844405e06743365" }
sync15-traits = { git = "https://github.com/mozilla/application-services", rev = "57a07e89e9ac92756b60b67c4a6ee06975b86288" }
xpcom = { path = "../../../xpcom/rust/xpcom" }
[dependencies.thin-vec]
......
{"files":{"Cargo.toml":"b94ceb62a211c20a148b1d65b1c8d33183e7ab09f91db79049eab9638075ee1e","examples/devices_api.rs":"87dfa7e92b33f4a3b0334aacf379a082149db85800947e927dbbf409dbb568ca","examples/migration.rs":"2577e4eb3a14ac8a4e81b6ab79b6658871225b08deb2fb573211fd02daebbdfa","examples/oauth_flow.rs":"99b0cb7b2a12051d2e0893ca9202124e0b229e888ef541518ac1c64ce89d6aff","src/commands/mod.rs":"0197979f5851da2300a481b6f7d0bd1ac7e00b08383339564b2372519965ca58","src/commands/send_tab.rs":"07e9ddc6b172bb3cf1af61f610fb4d39f73e9d63e304a05903f60ee76e3fa75e","src/config.rs":"cfc435dd49c3cd552091d2d46e30f2d67cfb3ba562caade3b5224550896c49a1","src/device.rs":"ffc8dfbf2d564393bbe80ef60907a06982db695d06208babe0608b821f56fb75","src/error.rs":"845280fdd99b13eb79d370f3585ccf4df21cfa4c97697bd9f173fa960b735886","src/ffi.rs":"ffd787adf013d57f776a7a5aac0b895b7bbbd83fbd0ebf5e6f139b404ea40a46","src/fxa_msg_types.proto":"e09fa503f531e83e28d8a813f20338df0cf16f96b7059975d55421a0657656a6","src/http_client.rs":"a0b8f955682ca02af601fbbc60d6476fa07e15916b0bc54b5cf1b0fab4b49dfe","src/lib.rs":"bc6303f7b87bd9f28fc9c4358d5914afe6b2b17f8f76543f413ab2b5c4f20dfa","src/migrator.rs":"8711aad7272f24c4d4d6e57142bafea883331022a35951f06151b7c9855e2c7a","src/mozilla.appservices.fxaclient.protobuf.rs":"e28aaa9ebf0874c9b9e9a482aaf0ee5205b5bff031d4f998d740db198831e9bb","src/oauth.rs":"ae70655b4b38df8313d633be4be52af232981ad3b98334545abc9b447b4a3cea","src/oauth/attached_clients.rs":"e0fd277d4294fd7982100e171cce790ea4acefb22ab1c7ab7b36f8593038cc43","src/profile.rs":"7197b630ebb992fb517a4fd9f5c4c03a24d5f66c4d888ccd5489eda074a5e556","src/push.rs":"dc1e846d4a5b8e7b0615583b4649cf3b0643d608651f6b7a0432f1aebdbb5197","src/scoped_keys.rs":"509bab207ac38e3662c0df9cd58b874f48c91b0728441bdefd684b56b536c514","src/scopes.rs":"2cb0799b0fb8b338124137456fa3cf8d6f56c0ea5709daef4e305c06dd0045c5","src/send_tab.rs":"8fc9ce5d56aa796cd72f7a920e695dfc23146b329f682812a12cb8c336b177ed","src/state_persistence.rs":"7a4a50726b6da30609dc6ca279419806e07c1843c9d7e5cdc1ce0db5ab9a5a2b","src/util.rs":"ecfd2d55dd0b329aac07979a3849485f932af6dd2990f02805ad4668f2c97d67"},"package":null}
\ No newline at end of file
{"files":{"Cargo.toml":"d9be79dd941f9a16b7e1b861820a718ce1eacc3085f62c1738157e1c8a47f0e0","examples/devices_api.rs":"87dfa7e92b33f4a3b0334aacf379a082149db85800947e927dbbf409dbb568ca","examples/migration.rs":"2577e4eb3a14ac8a4e81b6ab79b6658871225b08deb2fb573211fd02daebbdfa","examples/oauth_flow.rs":"99b0cb7b2a12051d2e0893ca9202124e0b229e888ef541518ac1c64ce89d6aff","src/commands/mod.rs":"0197979f5851da2300a481b6f7d0bd1ac7e00b08383339564b2372519965ca58","src/commands/send_tab.rs":"07e9ddc6b172bb3cf1af61f610fb4d39f73e9d63e304a05903f60ee76e3fa75e","src/config.rs":"b7771f5eb581b85a664202c8a63af158f36b672825c0dc164a2d986bfc2bf6fd","src/device.rs":"ffc8dfbf2d564393bbe80ef60907a06982db695d06208babe0608b821f56fb75","src/error.rs":"845280fdd99b13eb79d370f3585ccf4df21cfa4c97697bd9f173fa960b735886","src/ffi.rs":"ffd787adf013d57f776a7a5aac0b895b7bbbd83fbd0ebf5e6f139b404ea40a46","src/fxa_msg_types.proto":"e09fa503f531e83e28d8a813f20338df0cf16f96b7059975d55421a0657656a6","src/http_client.rs":"a0b8f955682ca02af601fbbc60d6476fa07e15916b0bc54b5cf1b0fab4b49dfe","src/lib.rs":"7b151b9a84bcd6a9bca7ecb1689e8909259ee058666ce20bcf8182b9b080c3b0","src/migrator.rs":"8711aad7272f24c4d4d6e57142bafea883331022a35951f06151b7c9855e2c7a","src/mozilla.appservices.fxaclient.protobuf.rs":"e28aaa9ebf0874c9b9e9a482aaf0ee5205b5bff031d4f998d740db198831e9bb","src/oauth.rs":"ae70655b4b38df8313d633be4be52af232981ad3b98334545abc9b447b4a3cea","src/oauth/attached_clients.rs":"e0fd277d4294fd7982100e171cce790ea4acefb22ab1c7ab7b36f8593038cc43","src/profile.rs":"7197b630ebb992fb517a4fd9f5c4c03a24d5f66c4d888ccd5489eda074a5e556","src/push.rs":"dc1e846d4a5b8e7b0615583b4649cf3b0643d608651f6b7a0432f1aebdbb5197","src/scoped_keys.rs":"509bab207ac38e3662c0df9cd58b874f48c91b0728441bdefd684b56b536c514","src/scopes.rs":"2cb0799b0fb8b338124137456fa3cf8d6f56c0ea5709daef4e305c06dd0045c5","src/send_tab.rs":"8fc9ce5d56aa796cd72f7a920e695dfc23146b329f682812a12cb8c336b177ed","src/state_persistence.rs":"7a4a50726b6da30609dc6ca279419806e07c1843c9d7e5cdc1ce0db5ab9a5a2b","src/util.rs":"ecfd2d55dd0b329aac07979a3849485f932af6dd2990f02805ad4668f2c97d67"},"package":null}
\ No newline at end of file
......@@ -7,14 +7,14 @@ license = "MPL-2.0"
exclude = ["/android", "/ios"]
[dependencies]
base64 = "0.12.0"
base64 = "0.12"
byteorder = "1.3"
failure = "0.1"
hex = "0.4"
lazy_static = "1.4.0"
lazy_static = "1.4"
log = "0.4"
prost = "0.6.1"
prost-derive = "0.6.1"
prost = "0.6"
prost-derive = "0.6"
serde = { version = "1", features = ["rc"] }
serde_derive = "1"
serde_json = "1"
......@@ -30,7 +30,7 @@ viaduct-reqwest = { path = "../support/viaduct-reqwest" }
cli-support = { path = "../support/cli" }
dialoguer = "0.6"
webbrowser = "0.5"
mockiato = "0.9.5"
mockiato = "0.9"
[features]
default = []
......
......@@ -55,6 +55,7 @@ pub struct RemoteConfig {
}
pub(crate) const CONTENT_URL_RELEASE: &str = "https://accounts.firefox.com";
pub(crate) const CONTENT_URL_CHINA: &str = "https://accounts.firefox.com.cn";
impl Config {
pub fn release(client_id: &str, redirect_uri: &str) -> Self {
......@@ -70,7 +71,7 @@ impl Config {
}
pub fn china(client_id: &str, redirect_uri: &str) -> Self {
Self::new("https://accounts.firefox.com.cn", client_id, redirect_uri)
Self::new(CONTENT_URL_CHINA, client_id, redirect_uri)
}
pub fn localdev(client_id: &str, redirect_uri: &str) -> Self {
......
......@@ -162,6 +162,10 @@ impl FirefoxAccount {
if self.state.config.content_url()? == Url::parse(config::CONTENT_URL_RELEASE)? {
return Ok(Url::parse("https://firefox.com/pair")?);
}
// Similarly special case for the China server.
if self.state.config.content_url()? == Url::parse(config::CONTENT_URL_CHINA)? {
return Ok(Url::parse("https://firefox.com.cn/pair")?);
}
Ok(self.state.config.pair_url()?)
}
......@@ -571,6 +575,13 @@ mod tests {
assert_eq!(
fxa.get_pairing_authority_url().unwrap().as_str(),
"https://firefox.com/pair"
);
let config = Config::china("12345678", "https://foo.bar");
let fxa = FirefoxAccount::with_config(config);
assert_eq!(
fxa.get_pairing_authority_url().unwrap().as_str(),
"https://firefox.com.cn/pair"
)
}
}
{"files":{"Cargo.toml":"fdff2d3a254e13c2199b10cdeebb6c6af1b0445dbb1a9166c50bbf91e44b5955","README.md":"14dd59e435d179c21c3b4b880bbe3cc6e5999b9f9ac9431f3f9aa3f43902e3fa","src/aes.rs":"820a74d1c1b9b5c818f5e4c4b39afb4346e56b8512a0f280c0bd92b763f50486","src/ec.rs":"3dfb1b2f630e855a37be7b2c03121d069d0b1f0f65e06bcd46493e2a0206be99","src/ecdh.rs":"6a970e6a30dfba4c5f4d113a5b5f3a814ee650a54eba903f8a50b47e180a1ceb","src/error.rs":"de521060e8ec9ad2c125815eec45ef690ad479ab9d41dab5a26294ee6acd9980","src/lib.rs":"7e9e1ebfaf13af124a5226a46e01e70743f3419eb7acc38ffaf202605bb33b89","src/pk11/context.rs":"ab3cdc8949fc1974523f0c6bf376ab933646df499d568a908076ad80b11c7c56","src/pk11/mod.rs":"d78368654f9a8bc12f1403c4a096b63cf9834820ea6ed48418b9afaa0fc2299e","src/pk11/slot.rs":"9f0aa039a55e7b26dc2dd5d2d3451497af71d147513f59e9c89b1166e89b2dda","src/pk11/sym_key.rs":"6dd1bae6e4c97665d0535fd0165736a2174edcb316f068ac3a8c73e5d4c20509","src/pk11/types.rs":"e42789b44e6c783a24d09c4ca955d70a305b20a35320c9c14c54c796e165b93e","src/secport.rs":"b4fbb007963a20cfd3170f37b35aa2816a0d7bf78bae9dbc64c83f5b8f15d2cb","src/util.rs":"236c46206bb6cd130c07f9da4fd603e23166c550a1ba675f4d752b056d13c27f"},"package":null}
\ No newline at end of file
{"files":{"Cargo.toml":"079319f9f7b8f3faf7f423f029f263c42f1c4836a9a9ef78af9733f5e47929bd","README.md":"14dd59e435d179c21c3b4b880bbe3cc6e5999b9f9ac9431f3f9aa3f43902e3fa","src/aes.rs":"820a74d1c1b9b5c818f5e4c4b39afb4346e56b8512a0f280c0bd92b763f50486","src/ec.rs":"3dfb1b2f630e855a37be7b2c03121d069d0b1f0f65e06bcd46493e2a0206be99","src/ecdh.rs":"6a970e6a30dfba4c5f4d113a5b5f3a814ee650a54eba903f8a50b47e180a1ceb","src/error.rs":"de521060e8ec9ad2c125815eec45ef690ad479ab9d41dab5a26294ee6acd9980","src/lib.rs":"7e9e1ebfaf13af124a5226a46e01e70743f3419eb7acc38ffaf202605bb33b89","src/pk11/context.rs":"ab3cdc8949fc1974523f0c6bf376ab933646df499d568a908076ad80b11c7c56","src/pk11/mod.rs":"d78368654f9a8bc12f1403c4a096b63cf9834820ea6ed48418b9afaa0fc2299e","src/pk11/slot.rs":"9f0aa039a55e7b26dc2dd5d2d3451497af71d147513f59e9c89b1166e89b2dda","src/pk11/sym_key.rs":"6dd1bae6e4c97665d0535fd0165736a2174edcb316f068ac3a8c73e5d4c20509","src/pk11/types.rs":"e42789b44e6c783a24d09c4ca955d70a305b20a35320c9c14c54c796e165b93e","src/secport.rs":"b4fbb007963a20cfd3170f37b35aa2816a0d7bf78bae9dbc64c83f5b8f15d2cb","src/util.rs":"236c46206bb6cd130c07f9da4fd603e23166c550a1ba675f4d752b056d13c27f"},"package":null}
\ No newline at end of file
......@@ -9,7 +9,7 @@ license = "MPL-2.0"
crate-type = ["lib"]
[dependencies]
base64 = "0.12.0"
base64 = "0.12"
error-support = { path = "../../error" }
failure = "0.1"
failure_derive = "0.1"
......
{"files":{"CHANGELOG.md":"30fa41d2cd20250b4d4defdef99cd18843b38f7991e8eed40801b94b8542ce13","Cargo.lock":"147a02b888dc8555251ba130e61c87afbd3c2af8ccac923b22773904ddb0a85e","Cargo.toml":"79f3565fce8df325c6096c50594228bfd7bfb9cef2dba1fc25ea48ba2fe9e5a0","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"d7203c0e18700de8e1408c3f4bb96075df271fea9ab678f6ad2e09855aefa7ed","examples/bench.rs":"1597a52529f75d6c5ad0b86759a775b1d723dfa810e2016317283b13594219da","examples/bench_acquire.rs":"3956f01158abaa1e15f1c633e6f96caf1257bca7bb4311c9568fdbc8347906f9","examples/bench_vs_lazy_static.rs":"d527294a2e73b53ac5faed8b316dfd1ae2a06adb31384134af21f10ce76333a5","examples/lazy_static.rs":"90541b093ed1d1cbb73f4097ff02cf80657e28264d281d6a31d96a708fdfea90","examples/reentrant_init_deadlocks.rs":"ff84929de27a848e5b155549caa96db5db5f030afca975f8ba3f3da640083001","examples/regex.rs":"4a2e0fb093c7f5bbe0fff8689fc0c670c5334344a1bfda376f5faa98a05d459f","examples/test_synchronization.rs":"1fe6828a2bfe5b5fbcaf287fcf02d746e757d89db81a2e32f24b849272dd1e90","src/imp_pl.rs":"2ec567e4a0f3b5adc7399822ced03243aa065b61ac50d81c485e952ddf676c7e","src/imp_std.rs":"bfd6e77afa84defffcc7a8b6bc0226353f95c12fd373866884cd8421c9326446","src/lib.rs":"20f7f610a6ad51dbe59b3dff328c6539520d00cec6d60bcfd3b3c0deb5efd06c","tests/test.rs":"d41dcc82bc03a52a1d1985b155d08de991919ae190a424012981a1e6f395eb20"},"package":"b1c601810575c99596d4afc46f78a678c80105117c379eb3650cf99b8a21ce5b"}
\ No newline at end of file
{"files":{"CHANGELOG.md":"0fe534ed96d710708290f0bb4506845529023ccc7cc5c25ea927df5516cd54e0","Cargo.lock":"cac2b1e8c08537f890d727b94fd334253d0a220a2d7fad866cf87641e6f2eb4e","Cargo.toml":"b9934c39f6c937a32fc6b596d1a67cf417e952487a7a0aaa8733c1acfa2527ce","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"d7203c0e18700de8e1408c3f4bb96075df271fea9ab678f6ad2e09855aefa7ed","examples/bench.rs":"1597a52529f75d6c5ad0b86759a775b1d723dfa810e2016317283b13594219da","examples/bench_acquire.rs":"9f4912ca262194cb55e893c33739c85c2f4868d07905b9dd3238552b6ce8a6e4","examples/bench_vs_lazy_static.rs":"d527294a2e73b53ac5faed8b316dfd1ae2a06adb31384134af21f10ce76333a5","examples/lazy_static.rs":"90541b093ed1d1cbb73f4097ff02cf80657e28264d281d6a31d96a708fdfea90","examples/reentrant_init_deadlocks.rs":"ff84929de27a848e5b155549caa96db5db5f030afca975f8ba3f3da640083001","examples/regex.rs":"4a2e0fb093c7f5bbe0fff8689fc0c670c5334344a1bfda376f5faa98a05d459f","examples/test_synchronization.rs":"88abd5c16275bb2f2d77eaecf369d97681404a77b8edd0021f24bfd377c46be3","src/imp_pl.rs":"8b994723144ff733a4872a3e1e68debd5ee2ce27b8e613e60d2744cae748052a","src/imp_std.rs":"b9d39dd1bbe8ebb779cd625dfd64b8f78a9dd6f0d531768ae61888f8416363b3","src/lib.rs":"3e128b775a7035322007590491914b6b23c4fb8f993354918d30a5f653557961","tests/test.rs":"800e951dc22e7d30cf05195904f49c162cc5e82db53afbb541b5be5ee19203a0"},"package":"0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d"}
\ No newline at end of file
# Changelog
## 1.4.0
- upgrade `parking_lot` to `0.10` (note that this bumps MSRV with `parking_lot` feature enabled to `1.36.0`).
- add `OnceCell::take`.
- upgrade crossbeam utils (private dependency) to `0.7`.
## 1.3.1
- remove unnecessary `F: fmt::Debug` bound from `impl fmt::Debug for Lazy<T, F>`.
......
......@@ -2,12 +2,17 @@
# It is not intended for manual editing.
[[package]]
name = "aho-corasick"
version = "0.7.6"
version = "0.7.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"memchr 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "autocfg"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bitflags"
version = "1.2.1"
......@@ -28,9 +33,10 @@ dependencies = [
[[package]]
name = "crossbeam-utils"
version = "0.6.6"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
......@@ -42,58 +48,51 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libc"
version = "0.2.66"
version = "0.2.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "lock_api"
version = "0.3.3"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"scopeguard 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "maybe-uninit"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "memchr"
version = "2.3.0"
version = "2.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "once_cell"
version = "1.3.1"
version = "1.4.0"
dependencies = [
"crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "parking_lot"
version = "0.9.0"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lock_api 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"lock_api 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot_core 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "parking_lot_core"
version = "0.6.2"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
......@@ -104,53 +103,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "regex"
version = "1.3.3"
version = "1.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"regex-syntax 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
"aho-corasick 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"regex-syntax 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)",
"thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex-syntax"
version = "0.6.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rustc_version"
version = "0.2.3"
version = "0.6.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "scopeguard"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "semver"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "semver-parser"
version = "0.7.0"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "smallvec"
version = "0.6.13"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "thread_local"
......@@ -180,26 +155,23 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d"
"checksum aho-corasick 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)" = "8716408b8bc624ed7f65d223ddb9ac2d044c0547b6fa4b0d554f3a9540496ada"
"checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
"checksum crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6"
"checksum crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8"
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
"checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558"
"checksum lock_api 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "79b2de95ecb4691949fea4716ca53cdbcfccb2c612e19644a8bad05edcf9f47b"
"checksum maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00"
"checksum memchr 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3197e20c7edb283f87c071ddfc7a2cca8f8e0b888c242959846a6fce03c72223"
"checksum parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252"
"checksum parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b876b1b9e7ac6e1a74a6da34d25c42e17e8862aa409cbbbdcfc8d86c6f3bc62b"
"checksum libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)" = "3baa92041a6fec78c687fa0cc2b3fae8884f743d672cf551bed1d6dac6988d0f"
"checksum lock_api 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75"
"checksum memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
"checksum parking_lot 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e"
"checksum parking_lot_core 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3"
"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
"checksum regex 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b5508c1941e4e7cb19965abef075d35a9a8b5cdf0846f30b4050e9b55dc55e87"
"checksum regex-syntax 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "e734e891f5b408a29efbf8309e656876276f49ab6a6ac208600b4419bd893d90"
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
"checksum scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b42e15e59b18a828bbf5c58ea01debb36b9b096346de35d941dcb89009f24a0d"
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
"checksum smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6"
"checksum regex 1.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a6020f034922e3194c711b82a627453881bc4682166cabb07134a10c26ba7692"
"checksum regex-syntax 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)" = "7fe5bd57d1d7414c6b5ed48563a2c855d995ff777729dcd91c369ec7fea395ae"
"checksum scopeguard 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
"checksum smallvec 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4"
"checksum thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
......
......@@ -13,7 +13,7 @@
[package]
edition = "2018"
name = "once_cell"
version = "1.3.1"
version = "1.4.0"
authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
exclude = ["*.png", "*.svg", "/Cargo.lock.min", "/.travis.yml", "/run-miri-tests.sh", "rustfmt.toml"]
description = "Single assignment cells and lazy values."
......@@ -52,11 +52,11 @@ required-features = ["std"]
name = "test_synchronization"
required-features = ["std"]
[dependencies.parking_lot]
version = "0.9.0"
version = "0.10.0"
optional = true
default_features = false
[dev-dependencies.crossbeam-utils]
version = "0.6.0"
version = "0.7.2"
[dev-dependencies.lazy_static]
version = "1.0.0"
......
/// Benchmark the overhead that the synchronization of `OnceCell::get` causes.
/// We do some other operations that write to memory to get an imprecise but somewhat realistic
/// measurement.
//! Benchmark the overhead that the synchronization of `OnceCell::get` causes.
//! We do some other operations that write to memory to get an imprecise but somewhat realistic
//! measurement.
use once_cell::sync::OnceCell;
use std::sync::atomic::{AtomicUsize, Ordering};
......@@ -29,7 +29,7 @@ fn thread_main(i: usize) {
let mut data = [i; 128];
let mut accum = 0usize;
for _ in 0..N_ROUNDS {
let _value = CELL.get_or_init(|| i+1);
let _value = CELL.get_or_init(|| i + 1);
let k = OTHER.fetch_add(data[accum & 0x7F] as usize, Ordering::Relaxed);
for j in data.iter_mut() {
*j = (*j).wrapping_add(accum);
......
/// Test if the OnceCell properly synchronizes.
/// Needs to be run in release mode.
///
/// We create a `Vec` with `N_ROUNDS` of `OnceCell`s. All threads will walk the `Vec`, and race to
/// be the first one to initialize a cell.
/// Every thread adds the results of the cells it sees to an accumulator, which is compared at the
/// end.
/// All threads should end up with the same result.
//! Test if the OnceCell properly synchronizes.
//! Needs to be run in release mode.
//!
//! We create a `Vec` with `N_ROUNDS` of `OnceCell`s. All threads will walk the `Vec`, and race to
//! be the first one to initialize a cell.
//! Every thread adds the results of the cells it sees to an accumulator, which is compared at the
//! end.
//! All threads should end up with the same result.
use once_cell::sync::OnceCell;
......
use std::{
cell::UnsafeCell,
mem::{self, MaybeUninit},
panic::{RefUnwindSafe, UnwindSafe},
ptr,
sync::atomic::{AtomicBool, Ordering},
};
......@@ -9,7 +11,7 @@ use parking_lot::{lock_api::RawMutex as _RawMutex, RawMutex};
pub(crate) struct OnceCell<T> {
mutex: Mutex,
is_initialized: AtomicBool,
pub(crate) value: UnsafeCell<Option<T>>,
value: UnsafeCell<MaybeUninit<T>>,
}
// Why do we need `T: Send`?
......@@ -28,7 +30,7 @@ impl<T> OnceCell<T> {
OnceCell {
mutex: Mutex::new(),
is_initialized: AtomicBool::new(false),
value: UnsafeCell::new(None),
value: UnsafeCell::new(MaybeUninit::uninit()),
}
}
......@@ -56,13 +58,76 @@ impl<T> OnceCell<T> {
// - finally, if it returns Ok, we store the value and store the flag with
// `Release`, which synchronizes with `Acquire`s.
let value = f()?;
let slot: &mut Option<T> = unsafe { &mut *self.value.get() };
debug_assert!(slot.is_none());
*slot = Some(value);
// Safe b/c we have a unique access and no panic may happen
// until the cell is marked as initialized.
unsafe { self.as_mut_ptr().write(value) };
self.is_initialized.store(true, Ordering::Release);
}
Ok(())
}
/// Get the reference to the underlying value, without checking if the cell
/// is initialized.
///
/// # Safety
///
/// Caller must ensure that the cell is in initialized state, and that
/// the contents are acquired by (synchronized to) this thread.
pub(crate) unsafe fn get_unchecked(&self) -> &T {
debug_assert!(self.is_initialized());
&*self.as_ptr()
}
/// Gets the mutable reference to the underlying value.
/// Returns `None` if the cell is empty.
pub(crate) fn get_mut(&mut self) -> Option<&mut T> {
if self.is_initialized() {
// Safe b/c we have a unique access and value is initialized.
Some(unsafe { &mut *self.as_mut_ptr() })
} else {
None
}
}
/// Consumes this `OnceCell`, returning the wrapped value.
/// Returns `None` if the cell was empty.
pub(crate) fn into_inner(self) -> Option<T> {
if !self.is_initialized() {
return None;
}
// Safe b/c we have a unique access and value is initialized.
let value: T = unsafe { ptr::read(self.as_ptr()) };
// It's OK to `mem::forget` without dropping, because both `self.mutex`
// and `self.is_initialized` are not heap-allocated.
mem::forget(self);
Some(value)
}
fn as_ptr(&self) -> *const T {
unsafe {
let slot: &MaybeUninit<T> = &*self.value.get();