aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-10 12:51:58 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-10 12:51:58 +0000
commitaef93c918e2b6e0b8826e970b00c46f8a5c3aaa9 (patch)
tree0c264c806bb6fabbc31bb785f7ba2b8f16a3b7aa
parent9225033cdf16fd9f3f38b3d3482efb0c36698085 (diff)
parent495a7ea9f78209435579453b83726e50f339e50e (diff)
Merge #478
478: WIP: implement cancelation via unwinding r=matklad a=matklad This uses https://github.com/salsa-rs/salsa/pull/107 to implement cancellation. Now we can get rid of `Cancelable` wrapper from everywhere except the top-level analyzer library. Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r--Cargo.lock35
-rw-r--r--Cargo.toml1
-rw-r--r--crates/ra_db/src/cancellation.rs6
-rw-r--r--crates/ra_db/src/lib.rs22
-rw-r--r--crates/ra_db/src/loc2id.rs11
-rw-r--r--crates/ra_hir/src/mock.rs4
-rw-r--r--crates/ra_ide_api/src/db.rs5
-rw-r--r--crates/ra_ide_api/src/lib.rs51
8 files changed, 87 insertions, 48 deletions
diff --git a/Cargo.lock b/Cargo.lock
index b3172dc28..dba94aa6b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -66,11 +66,10 @@ dependencies = [
66 66
67[[package]] 67[[package]]
68name = "base64" 68name = "base64"
69version = "0.9.3" 69version = "0.10.0"
70source = "registry+https://github.com/rust-lang/crates.io-index" 70source = "registry+https://github.com/rust-lang/crates.io-index"
71dependencies = [ 71dependencies = [
72 "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", 72 "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
73 "safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
74] 73]
75 74
76[[package]] 75[[package]]
@@ -139,7 +138,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
139dependencies = [ 138dependencies = [
140 "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", 139 "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
141 "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 140 "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
142 "time 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", 141 "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
143] 142]
144 143
145[[package]] 144[[package]]
@@ -661,7 +660,7 @@ dependencies = [
661 "ra_syntax 0.1.0", 660 "ra_syntax 0.1.0",
662 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 661 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
663 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 662 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
664 "salsa 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", 663 "salsa 0.9.1 (git+https://github.com/matklad/salsa?branch=panic-hooks)",
665 "test_utils 0.1.0", 664 "test_utils 0.1.0",
666] 665]
667 666
@@ -680,7 +679,7 @@ dependencies = [
680 "ra_syntax 0.1.0", 679 "ra_syntax 0.1.0",
681 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 680 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
682 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 681 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
683 "salsa 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", 682 "salsa 0.9.1 (git+https://github.com/matklad/salsa?branch=panic-hooks)",
684 "test_utils 0.1.0", 683 "test_utils 0.1.0",
685] 684]
686 685
@@ -700,7 +699,7 @@ dependencies = [
700 "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", 699 "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
701 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 700 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
702 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 701 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
703 "salsa 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", 702 "salsa 0.9.1 (git+https://github.com/matklad/salsa?branch=panic-hooks)",
704 "test_utils 0.1.0", 703 "test_utils 0.1.0",
705 "unicase 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 704 "unicase 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
706] 705]
@@ -967,10 +966,10 @@ dependencies = [
967 966
968[[package]] 967[[package]]
969name = "ron" 968name = "ron"
970version = "0.4.0" 969version = "0.4.1"
971source = "registry+https://github.com/rust-lang/crates.io-index" 970source = "registry+https://github.com/rust-lang/crates.io-index"
972dependencies = [ 971dependencies = [
973 "base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", 972 "base64 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
974 "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", 973 "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
975 "serde 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)", 974 "serde 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)",
976] 975]
@@ -1023,14 +1022,9 @@ version = "0.2.7"
1023source = "registry+https://github.com/rust-lang/crates.io-index" 1022source = "registry+https://github.com/rust-lang/crates.io-index"
1024 1023
1025[[package]] 1024[[package]]
1026name = "safemem"
1027version = "0.3.0"
1028source = "registry+https://github.com/rust-lang/crates.io-index"
1029
1030[[package]]
1031name = "salsa" 1025name = "salsa"
1032version = "0.9.1" 1026version = "0.9.1"
1033source = "registry+https://github.com/rust-lang/crates.io-index" 1027source = "git+https://github.com/matklad/salsa?branch=panic-hooks#88313c80302c831ebc7601912ab3f11ad37e6bc2"
1034dependencies = [ 1028dependencies = [
1035 "derive-new 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", 1029 "derive-new 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
1036 "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 1030 "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1207,7 +1201,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1207dependencies = [ 1201dependencies = [
1208 "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 1202 "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
1209 "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 1203 "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
1210 "ron 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 1204 "ron 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
1211 "tera 0.11.20 (registry+https://github.com/rust-lang/crates.io-index)", 1205 "tera 0.11.20 (registry+https://github.com/rust-lang/crates.io-index)",
1212] 1206]
1213 1207
@@ -1274,7 +1268,7 @@ dependencies = [
1274 1268
1275[[package]] 1269[[package]]
1276name = "time" 1270name = "time"
1277version = "0.1.41" 1271version = "0.1.42"
1278source = "registry+https://github.com/rust-lang/crates.io-index" 1272source = "registry+https://github.com/rust-lang/crates.io-index"
1279dependencies = [ 1273dependencies = [
1280 "libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)", 1274 "libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1489,7 +1483,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1489"checksum autocfg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4e5f34df7a019573fb8bdc7e24a2bfebe51a2a1d6bfdbaeccedb3c41fc574727" 1483"checksum autocfg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4e5f34df7a019573fb8bdc7e24a2bfebe51a2a1d6bfdbaeccedb3c41fc574727"
1490"checksum backtrace 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)" = "b5b493b66e03090ebc4343eb02f94ff944e0cbc9ac6571491d170ba026741eb5" 1484"checksum backtrace 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)" = "b5b493b66e03090ebc4343eb02f94ff944e0cbc9ac6571491d170ba026741eb5"
1491"checksum backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "797c830ac25ccc92a7f8a7b9862bde440715531514594a6154e3d4a54dd769b6" 1485"checksum backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "797c830ac25ccc92a7f8a7b9862bde440715531514594a6154e3d4a54dd769b6"
1492"checksum base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643" 1486"checksum base64 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "621fc7ecb8008f86d7fb9b95356cd692ce9514b80a86d85b397f32a22da7b9e2"
1493"checksum bit-set 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6f1efcc46c18245a69c38fcc5cc650f16d3a59d034f3106e9ed63748f695730a" 1487"checksum bit-set 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6f1efcc46c18245a69c38fcc5cc650f16d3a59d034f3106e9ed63748f695730a"
1494"checksum bit-vec 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4440d5cb623bb7390ae27fec0bb6c61111969860f8e3ae198bfa0663645e67cf" 1488"checksum bit-vec 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4440d5cb623bb7390ae27fec0bb6c61111969860f8e3ae198bfa0663645e67cf"
1495"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" 1489"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
@@ -1579,15 +1573,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1579"checksum regex-syntax 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4e47a2ed29da7a9e1960e1639e7a982e6edc6d49be308a3b02daf511504a16d1" 1573"checksum regex-syntax 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4e47a2ed29da7a9e1960e1639e7a982e6edc6d49be308a3b02daf511504a16d1"
1580"checksum relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0e7790c7f1cc73d831d28dc5a7deb316a006e7848e6a7f467cdb10a0a9e0fb1c" 1574"checksum relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0e7790c7f1cc73d831d28dc5a7deb316a006e7848e6a7f467cdb10a0a9e0fb1c"
1581"checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" 1575"checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5"
1582"checksum ron 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c48677d8a9247a4e0d1f3f9cb4b0a8e29167fdc3c04f383a5e669cd7a960ae0f" 1576"checksum ron 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d9cb28ade964585205aaca1f3d41a6297f72e1ad097b49c4bbde033ef86b38d7"
1583"checksum rowan 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ae9ae7dba5e703f423ceb8646d636c73e6d858a2f8c834808b4565e42ccda9e2" 1577"checksum rowan 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ae9ae7dba5e703f423ceb8646d636c73e6d858a2f8c834808b4565e42ccda9e2"
1584"checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619" 1578"checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619"
1585"checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8" 1579"checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8"
1586"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" 1580"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
1587"checksum rusty-fork 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9591f190d2852720b679c21f66ad929f9f1d7bb09d1193c26167586029d8489c" 1581"checksum rusty-fork 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9591f190d2852720b679c21f66ad929f9f1d7bb09d1193c26167586029d8489c"
1588"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7" 1582"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7"
1589"checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9" 1583"checksum salsa 0.9.1 (git+https://github.com/matklad/salsa?branch=panic-hooks)" = "<none>"
1590"checksum salsa 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "442ef4acdb48c0e24ddaf4f3b62555af2d1da7047f2f26acd54ae73010aa0c02"
1591"checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267" 1584"checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267"
1592"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" 1585"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
1593"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" 1586"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
@@ -1612,7 +1605,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1612"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6" 1605"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6"
1613"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" 1606"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
1614"checksum threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e2f0c90a5f3459330ac8bc0d2f879c693bb7a2f59689c1083fc4ef83834da865" 1607"checksum threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e2f0c90a5f3459330ac8bc0d2f879c693bb7a2f59689c1083fc4ef83834da865"
1615"checksum time 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "847da467bf0db05882a9e2375934a8a55cffdc9db0d128af1518200260ba1f6c" 1608"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f"
1616"checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169" 1609"checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169"
1617"checksum ucd-trie 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "71a9c5b1fe77426cf144cc30e49e955270f5086e31a6441dfa8b32efc09b9d77" 1610"checksum ucd-trie 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "71a9c5b1fe77426cf144cc30e49e955270f5086e31a6441dfa8b32efc09b9d77"
1618"checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" 1611"checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86"
diff --git a/Cargo.toml b/Cargo.toml
index 1cf83dfa8..85aaa23b9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,3 +7,4 @@ debug = true
7 7
8[patch.'crates-io'] 8[patch.'crates-io']
9cargo_metadata = { git = "https://github.com/oli-obk/cargo_metadata.git", rev="f73e27b24e" } 9cargo_metadata = { git = "https://github.com/oli-obk/cargo_metadata.git", rev="f73e27b24e" }
10salsa = { git = "https://github.com/matklad/salsa", branch = "panic-hooks" }
diff --git a/crates/ra_db/src/cancellation.rs b/crates/ra_db/src/cancellation.rs
index 8d38eebfb..32a268553 100644
--- a/crates/ra_db/src/cancellation.rs
+++ b/crates/ra_db/src/cancellation.rs
@@ -27,6 +27,12 @@ impl Canceled {
27 pub(crate) fn new() -> Canceled { 27 pub(crate) fn new() -> Canceled {
28 Canceled { _private: () } 28 Canceled { _private: () }
29 } 29 }
30
31 pub fn throw() -> ! {
32 // We use resume and not panic here to avoid running the panic
33 // hook (that is, to avoid collecting and printing backtrace).
34 std::panic::resume_unwind(Box::new(Canceled::new()))
35 }
30} 36}
31 37
32impl std::fmt::Display for Canceled { 38impl std::fmt::Display for Canceled {
diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs
index fb8ea2496..20e712afe 100644
--- a/crates/ra_db/src/lib.rs
+++ b/crates/ra_db/src/lib.rs
@@ -5,6 +5,8 @@ mod input;
5mod loc2id; 5mod loc2id;
6pub mod mock; 6pub mod mock;
7 7
8use std::panic;
9
8use ra_syntax::{TextUnit, TextRange, SourceFile, TreePtr}; 10use ra_syntax::{TextUnit, TextRange, SourceFile, TreePtr};
9 11
10pub use crate::{ 12pub use crate::{
@@ -18,13 +20,21 @@ pub use crate::{
18 loc2id::LocationIntener, 20 loc2id::LocationIntener,
19}; 21};
20 22
21pub trait BaseDatabase: salsa::Database { 23pub trait BaseDatabase: salsa::Database + panic::RefUnwindSafe {
22 fn check_canceled(&self) -> Cancelable<()> { 24 fn check_canceled(&self) -> Cancelable<()> {
23 if self.salsa_runtime().is_current_revision_canceled() { 25 self.salsa_runtime()
24 Err(Canceled::new()) 26 .if_current_revision_is_canceled(Canceled::throw);
25 } else { 27 Ok(())
26 Ok(()) 28 }
27 } 29
30 fn catch_canceled<F: FnOnce(&Self) -> T + panic::UnwindSafe, T>(
31 &self,
32 f: F,
33 ) -> Result<T, Canceled> {
34 panic::catch_unwind(|| f(self)).map_err(|err| match err.downcast::<Canceled>() {
35 Ok(canceled) => *canceled,
36 Err(payload) => panic::resume_unwind(payload),
37 })
28 } 38 }
29} 39}
30 40
diff --git a/crates/ra_db/src/loc2id.rs b/crates/ra_db/src/loc2id.rs
index 254c52629..359cd893d 100644
--- a/crates/ra_db/src/loc2id.rs
+++ b/crates/ra_db/src/loc2id.rs
@@ -1,4 +1,4 @@
1use std::hash::Hash; 1use std::{panic, hash::Hash};
2 2
3use parking_lot::Mutex; 3use parking_lot::Mutex;
4use rustc_hash::FxHashMap; 4use rustc_hash::FxHashMap;
@@ -70,6 +70,15 @@ where
70 map: Mutex<Loc2IdMap<LOC, ID>>, 70 map: Mutex<Loc2IdMap<LOC, ID>>,
71} 71}
72 72
73impl<LOC, ID> panic::RefUnwindSafe for LocationIntener<LOC, ID>
74where
75 ID: ArenaId + Clone,
76 LOC: Clone + Eq + Hash,
77 ID: panic::RefUnwindSafe,
78 LOC: panic::RefUnwindSafe,
79{
80}
81
73impl<LOC, ID> Default for LocationIntener<LOC, ID> 82impl<LOC, ID> Default for LocationIntener<LOC, ID>
74where 83where
75 ID: ArenaId + Clone, 84 ID: ArenaId + Clone,
diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs
index 0fae7de82..7a0301648 100644
--- a/crates/ra_hir/src/mock.rs
+++ b/crates/ra_hir/src/mock.rs
@@ -1,4 +1,4 @@
1use std::sync::Arc; 1use std::{sync::Arc, panic};
2 2
3use parking_lot::Mutex; 3use parking_lot::Mutex;
4use salsa::{self, Database}; 4use salsa::{self, Database};
@@ -18,6 +18,8 @@ pub(crate) struct MockDatabase {
18 file_counter: u32, 18 file_counter: u32,
19} 19}
20 20
21impl panic::RefUnwindSafe for MockDatabase {}
22
21impl MockDatabase { 23impl MockDatabase {
22 pub(crate) fn with_files(fixture: &str) -> (MockDatabase, SourceRoot) { 24 pub(crate) fn with_files(fixture: &str) -> (MockDatabase, SourceRoot) {
23 let (db, source_root, position) = MockDatabase::from_fixture(fixture); 25 let (db, source_root, position) = MockDatabase::from_fixture(fixture);
diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs
index 9d46609ec..a2e06f5db 100644
--- a/crates/ra_ide_api/src/db.rs
+++ b/crates/ra_ide_api/src/db.rs
@@ -1,7 +1,7 @@
1use std::{fmt, sync::Arc}; 1use std::{fmt, sync::Arc};
2 2
3use salsa::{self, Database}; 3use salsa::{self, Database};
4use ra_db::{LocationIntener, BaseDatabase, FileId}; 4use ra_db::{LocationIntener, BaseDatabase, FileId, Canceled};
5 5
6use crate::{symbol_index, LineIndex}; 6use crate::{symbol_index, LineIndex};
7 7
@@ -29,6 +29,9 @@ impl salsa::Database for RootDatabase {
29 fn salsa_runtime(&self) -> &salsa::Runtime<RootDatabase> { 29 fn salsa_runtime(&self) -> &salsa::Runtime<RootDatabase> {
30 &self.runtime 30 &self.runtime
31 } 31 }
32 fn on_propagated_panic(&self) -> ! {
33 Canceled::throw()
34 }
32} 35}
33 36
34impl Default for RootDatabase { 37impl Default for RootDatabase {
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index fbe1421a4..f505959ce 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -35,7 +35,7 @@ use std::{fmt, sync::Arc};
35 35
36use ra_syntax::{SmolStr, SourceFile, TreePtr, SyntaxKind, TextRange, TextUnit}; 36use ra_syntax::{SmolStr, SourceFile, TreePtr, SyntaxKind, TextRange, TextUnit};
37use ra_text_edit::TextEdit; 37use ra_text_edit::TextEdit;
38use ra_db::{SyntaxDatabase, FilesDatabase, LocalSyntaxPtr}; 38use ra_db::{SyntaxDatabase, FilesDatabase, LocalSyntaxPtr, BaseDatabase};
39use rayon::prelude::*; 39use rayon::prelude::*;
40use relative_path::RelativePathBuf; 40use relative_path::RelativePathBuf;
41use rustc_hash::FxHashMap; 41use rustc_hash::FxHashMap;
@@ -420,43 +420,47 @@ impl Analysis {
420 420
421 /// Fuzzy searches for a symbol. 421 /// Fuzzy searches for a symbol.
422 pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<NavigationTarget>> { 422 pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<NavigationTarget>> {
423 let res = symbol_index::world_symbols(&*self.db, query)? 423 self.with_db(|db| {
424 .into_iter() 424 let res = symbol_index::world_symbols(db, query)?
425 .map(NavigationTarget::from_symbol) 425 .into_iter()
426 .collect(); 426 .map(NavigationTarget::from_symbol)
427 Ok(res) 427 .collect::<Vec<_>>();
428 Ok(res)
429 })?
428 } 430 }
429 431
430 pub fn goto_definition( 432 pub fn goto_definition(
431 &self, 433 &self,
432 position: FilePosition, 434 position: FilePosition,
433 ) -> Cancelable<Option<Vec<NavigationTarget>>> { 435 ) -> Cancelable<Option<Vec<NavigationTarget>>> {
434 goto_definition::goto_definition(&*self.db, position) 436 self.db
437 .catch_canceled(|db| goto_definition::goto_definition(db, position))?
435 } 438 }
436 439
437 /// Finds all usages of the reference at point. 440 /// Finds all usages of the reference at point.
438 pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> { 441 pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> {
439 self.db.find_all_refs(position) 442 self.with_db(|db| db.find_all_refs(position))?
440 } 443 }
441 444
442 /// Returns a short text descrbing element at position. 445 /// Returns a short text descrbing element at position.
443 pub fn hover(&self, position: FilePosition) -> Cancelable<Option<RangeInfo<String>>> { 446 pub fn hover(&self, position: FilePosition) -> Cancelable<Option<RangeInfo<String>>> {
444 hover::hover(&*self.db, position) 447 self.with_db(|db| hover::hover(db, position))?
445 } 448 }
446 449
447 /// Computes parameter information for the given call expression. 450 /// Computes parameter information for the given call expression.
448 pub fn call_info(&self, position: FilePosition) -> Cancelable<Option<CallInfo>> { 451 pub fn call_info(&self, position: FilePosition) -> Cancelable<Option<CallInfo>> {
449 call_info::call_info(&*self.db, position) 452 self.db
453 .catch_canceled(|db| call_info::call_info(db, position))?
450 } 454 }
451 455
452 /// Returns a `mod name;` declaration which created the current module. 456 /// Returns a `mod name;` declaration which created the current module.
453 pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<NavigationTarget>> { 457 pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<NavigationTarget>> {
454 self.db.parent_module(position) 458 self.with_db(|db| db.parent_module(position))?
455 } 459 }
456 460
457 /// Returns crates this file belongs too. 461 /// Returns crates this file belongs too.
458 pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { 462 pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> {
459 self.db.crate_for(file_id) 463 self.with_db(|db| db.crate_for(file_id))?
460 } 464 }
461 465
462 /// Returns the root file of the given crate. 466 /// Returns the root file of the given crate.
@@ -466,17 +470,21 @@ impl Analysis {
466 470
467 /// Returns the set of possible targets to run for the current file. 471 /// Returns the set of possible targets to run for the current file.
468 pub fn runnables(&self, file_id: FileId) -> Cancelable<Vec<Runnable>> { 472 pub fn runnables(&self, file_id: FileId) -> Cancelable<Vec<Runnable>> {
469 runnables::runnables(&*self.db, file_id) 473 self.db
474 .catch_canceled(|db| runnables::runnables(db, file_id))?
470 } 475 }
471 476
472 /// Computes syntax highlighting for the given file. 477 /// Computes syntax highlighting for the given file.
473 pub fn highlight(&self, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> { 478 pub fn highlight(&self, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> {
474 syntax_highlighting::highlight(&*self.db, file_id) 479 self.db
480 .catch_canceled(|db| syntax_highlighting::highlight(db, file_id))?
475 } 481 }
476 482
477 /// Computes completions at the given position. 483 /// Computes completions at the given position.
478 pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> { 484 pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> {
479 let completions = completion::completions(&self.db, position)?; 485 let completions = self
486 .db
487 .catch_canceled(|db| completion::completions(db, position))??;
480 Ok(completions.map(|it| it.into())) 488 Ok(completions.map(|it| it.into()))
481 } 489 }
482 490
@@ -488,12 +496,12 @@ impl Analysis {
488 496
489 /// Computes the set of diagnostics for the given file. 497 /// Computes the set of diagnostics for the given file.
490 pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> { 498 pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> {
491 self.db.diagnostics(file_id) 499 self.with_db(|db| db.diagnostics(file_id))?
492 } 500 }
493 501
494 /// Computes the type of the expression at the given position. 502 /// Computes the type of the expression at the given position.
495 pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> { 503 pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> {
496 hover::type_of(&*self.db, frange) 504 self.with_db(|db| hover::type_of(db, frange))?
497 } 505 }
498 506
499 /// Returns the edit required to rename reference at the position to the new 507 /// Returns the edit required to rename reference at the position to the new
@@ -503,7 +511,14 @@ impl Analysis {
503 position: FilePosition, 511 position: FilePosition,
504 new_name: &str, 512 new_name: &str,
505 ) -> Cancelable<Vec<SourceFileEdit>> { 513 ) -> Cancelable<Vec<SourceFileEdit>> {
506 self.db.rename(position, new_name) 514 self.with_db(|db| db.rename(position, new_name))?
515 }
516
517 fn with_db<F: FnOnce(&db::RootDatabase) -> T + std::panic::UnwindSafe, T>(
518 &self,
519 f: F,
520 ) -> Cancelable<T> {
521 self.db.catch_canceled(f)
507 } 522 }
508} 523}
509 524