Skip to content

Commit 197660f

Browse files
authored
Merge pull request #18 from fitzgen/sort-subsequences
Sort subsequences
2 parents c6ab950 + 34d1902 commit 197660f

File tree

10 files changed

+282
-186
lines changed

10 files changed

+282
-186
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ license = "Apache-2.0/MIT"
1818
name = "source-map-mappings"
1919
readme = "./README.md"
2020
repository = "https://github.com/fitzgen/source-map-mappings"
21-
version = "0.4.0"
21+
version = "0.5.0"
2222

2323
[badges.travis-ci]
2424
repository = "fitzgen/source-map-mappings"

source-map-mappings-wasm-api/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ license = "Apache-2.0/MIT"
55
name = "source-map-mappings-wasm-api"
66
readme = "../README.md"
77
repository = "https://github.com/fitzgen/source-map-mappings"
8-
version = "0.4.0"
8+
version = "0.5.0"
99

1010
[badges.travis-ci]
1111
repository = "fitzgen/source-map-mappings"
1212

1313
[dependencies]
14-
source-map-mappings = { version = "0.4.0", path = ".." }
14+
source-map-mappings = { version = "0.5.0", path = ".." }
1515

1616
[features]
1717
profiling = []

source-map-mappings-wasm-api/build.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,17 @@ def wasm_gc(args, wasm_path):
9494
return out_path
9595

9696
SHOULD_SNIP = [
97-
re.compile(r".*(std|core)(9|::)panicking"),
98-
re.compile(r".*(std|core)(3|::)fmt"),
99-
re.compile(r".*core(6|::)option(13|::)expect_failed"),
100-
re.compile(r".*core(3|::)str(16|::)slice_error_fail"),
101-
re.compile(r".*core(6|::)result(13|::)unwrap_failed"),
102-
re.compile(r".*std(6|::)thread(5|::)local(2|::)os(13|::)destroy_value"),
103-
re.compile(r".*std(2|::)io(5|::)Write"),
97+
re.compile(r".*(std|core)(9|::)panicking.*"),
98+
re.compile(r".*(std|core)(3|::)fmt.*"),
99+
re.compile(r".*core(6|::)option(13|::)expect_failed.*"),
100+
re.compile(r".*core(5|::)slice(\d+|::)slice_index_.*_fail.*"),
101+
re.compile(r".*core(3|::)str(\d+|::)slice_.*_fail.*"),
102+
re.compile(r".*core(6|::)result(13|::)unwrap_failed.*"),
103+
re.compile(r".*std(6|::)thread(5|::)local.*"),
104+
re.compile(r".*std(2|::)io(5|::).*"),
105+
re.compile(r"__.*2"),
106+
re.compile(r".*(std|core)(5|::)error.*"),
107+
re.compile(r".*(std|core)(3|::)any(3|::)Any.*"),
104108
]
105109

106110
def wasm_snip(args, wasm_path):
@@ -109,7 +113,7 @@ def wasm_snip(args, wasm_path):
109113

110114
out_path = add_path_ext_prefix(wasm_path, "snip")
111115

112-
private_functions = run(["wasm-nm", "-p", "-j", wasm_path]).splitlines()
116+
private_functions = run(["wasm-nm", "-j", wasm_path]).splitlines()
113117

114118
snip_functions = set()
115119
for snip in SHOULD_SNIP:

source-map-mappings-wasm-api/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ pub extern "C" fn by_original_location(mappings: *mut Mappings<Observer>) {
353353
let this_scope = ();
354354
let mappings = unsafe { mappings_mut(&this_scope, mappings) };
355355

356-
mappings.by_original_location().iter().for_each(|m| unsafe {
356+
mappings.by_original_location().for_each(|m| unsafe {
357357
invoke_mapping_callback(m);
358358
});
359359
}

source-map-mappings-wasm-api/who-calls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ def print_callers(reversed_call_graph, args, function=None, depth=0, seen=set())
146146

147147
print_callers(reversed_call_graph, args, function=caller, depth=depth+1, seen=seen)
148148

149+
seen.remove(function)
150+
149151
def main():
150152
args = parser.parse_args()
151153
disassembly = disassemble(args)

src/comparators.rs

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ macro_rules! compare {
4646
}
4747
}
4848

49-
/// Sort mappings by their generated locations, breaking ties by their original
50-
/// locations.
49+
/// Sort mappings by their generated location, but don't compare generated
50+
/// lines. This is useful for when we know that all mappings being sorted have
51+
/// the same generated line number.
5152
#[derive(Debug)]
52-
pub struct ByGeneratedLocation;
53+
pub struct ByGeneratedTail;
5354

54-
impl ComparatorFunction<Mapping> for ByGeneratedLocation {
55+
impl ComparatorFunction<Mapping> for ByGeneratedTail {
5556
#[inline]
5657
fn compare(a: &Mapping, b: &Mapping) -> Ordering {
57-
compare!(a.generated_line, b.generated_line);
5858
compare!(a.generated_column, b.generated_column);
5959
ByOriginalLocation::compare(&a.original, &b.original)
6060
}
@@ -89,3 +89,33 @@ impl ComparatorFunction<OriginalLocation> for ByOriginalLocation {
8989
a.name.cmp(&b.name)
9090
}
9191
}
92+
93+
/// Assuming mappings are in the same original source, sort mappings by their
94+
/// original locations, breaking ties by their generated locations.
95+
#[derive(Debug)]
96+
pub struct ByOriginalLocationSameSource;
97+
98+
impl ComparatorFunction<Mapping> for ByOriginalLocationSameSource {
99+
#[inline]
100+
fn compare(a: &Mapping, b: &Mapping) -> Ordering {
101+
let c = ByOriginalLocationSameSource::compare(&a.original, &b.original);
102+
match c {
103+
Ordering::Less | Ordering::Greater => c,
104+
Ordering::Equal => {
105+
compare!(a.generated_line, b.generated_line);
106+
compare!(a.generated_column, b.generated_column);
107+
Ordering::Equal
108+
}
109+
}
110+
}
111+
}
112+
113+
impl ComparatorFunction<OriginalLocation> for ByOriginalLocationSameSource {
114+
#[inline]
115+
fn compare(a: &OriginalLocation, b: &OriginalLocation) -> Ordering {
116+
debug_assert_eq!(a.source, b.source);
117+
compare!(a.original_line, b.original_line);
118+
compare!(a.original_column, b.original_column);
119+
a.name.cmp(&b.name)
120+
}
121+
}

0 commit comments

Comments
 (0)