@@ -4,18 +4,20 @@ pub mod module;
4
4
pub mod resolve;
5
5
6
6
use std:: {
7
+ borrow:: Cow ,
7
8
cmp:: { min, Ordering } ,
8
9
fmt:: { Display , Formatter } ,
9
10
} ;
10
11
11
12
use anyhow:: { anyhow, Result } ;
12
13
use async_trait:: async_trait;
13
14
use auto_hash_map:: AutoSet ;
14
- use serde:: Serialize ;
15
+ use serde:: { Deserialize , Serialize } ;
15
16
use turbo_rcstr:: RcStr ;
16
17
use turbo_tasks:: {
17
- emit, CollectiblesSource , OperationVc , RawVc , ReadRef , ResolvedVc , TransientInstance ,
18
- TransientValue , TryJoinIterExt , Upcast , ValueToString , Vc ,
18
+ emit, trace:: TraceRawVcs , CollectiblesSource , NonLocalValue , OperationVc , RawVc , ReadRef ,
19
+ ResolvedVc , TaskInput , TransientInstance , TransientValue , TryJoinIterExt , Upcast ,
20
+ ValueToString , Vc ,
19
21
} ;
20
22
use turbo_tasks_fs:: { FileContent , FileLine , FileLinesContent , FileSystemPath } ;
21
23
use turbo_tasks_hash:: { DeterministicHash , Xxh3Hash64Hasher } ;
@@ -172,7 +174,7 @@ pub trait Issue {
172
174
detail,
173
175
documentation_link : self . documentation_link ( ) . await ?. clone_value ( ) ,
174
176
source : {
175
- if let Some ( s) = * self . source ( ) . await ? {
177
+ if let Some ( s) = & * self . source ( ) . await ? {
176
178
Some ( s. into_plain ( ) . await ?)
177
179
} else {
178
180
None
@@ -435,79 +437,71 @@ impl CapturedIssues {
435
437
}
436
438
}
437
439
438
- #[ turbo_tasks:: value]
439
- #[ derive( Clone , Debug ) ]
440
+ #[ derive(
441
+ Clone , Debug , PartialEq , Eq , Serialize , Deserialize , Hash , TaskInput , TraceRawVcs , NonLocalValue ,
442
+ ) ]
440
443
pub struct IssueSource {
441
444
source : ResolvedVc < Box < dyn Source > > ,
442
- range : Option < ResolvedVc < SourceRange > > ,
445
+ range : Option < SourceRange > ,
443
446
}
444
447
445
448
/// The end position is the first character after the range
446
- #[ turbo_tasks:: value]
447
- #[ derive( Clone , Debug ) ]
449
+ #[ derive(
450
+ Clone , Debug , PartialEq , Eq , Serialize , Deserialize , Hash , TaskInput , TraceRawVcs , NonLocalValue ,
451
+ ) ]
448
452
enum SourceRange {
449
453
LineColumn ( SourcePos , SourcePos ) ,
450
454
ByteOffset ( usize , usize ) ,
451
455
}
452
456
453
- #[ turbo_tasks:: value_impl]
454
457
impl IssueSource {
455
458
// Sometimes we only have the source file that causes an issue, not the
456
459
// exact location, such as as in some generated code.
457
- #[ turbo_tasks:: function]
458
- pub fn from_source_only ( source : ResolvedVc < Box < dyn Source > > ) -> Vc < Self > {
459
- Self :: cell ( IssueSource {
460
+ pub fn from_source_only ( source : ResolvedVc < Box < dyn Source > > ) -> Self {
461
+ IssueSource {
460
462
source,
461
463
range : None ,
462
- } )
464
+ }
463
465
}
464
466
465
- #[ turbo_tasks:: function]
466
467
pub fn from_line_col (
467
468
source : ResolvedVc < Box < dyn Source > > ,
468
469
start : SourcePos ,
469
470
end : SourcePos ,
470
- ) -> Vc < Self > {
471
- Self :: cell ( IssueSource {
471
+ ) -> Self {
472
+ IssueSource {
472
473
source,
473
- range : Some ( SourceRange :: LineColumn ( start, end) . resolved_cell ( ) ) ,
474
- } )
474
+ range : Some ( SourceRange :: LineColumn ( start, end) ) ,
475
+ }
475
476
}
476
477
477
- #[ turbo_tasks:: function]
478
- pub async fn resolve_source_map (
479
- self : Vc < Self > ,
480
- origin : Vc < FileSystemPath > ,
481
- ) -> Result < Vc < Self > > {
482
- let this = self . await ?;
483
-
484
- if let Some ( range) = this. range {
485
- let ( start, end) = match & * range. await ? {
478
+ pub async fn resolve_source_map ( & self , origin : Vc < FileSystemPath > ) -> Result < Cow < ' _ , Self > > {
479
+ if let Some ( range) = & self . range {
480
+ let ( start, end) = match range {
486
481
SourceRange :: LineColumn ( start, end) => ( * start, * end) ,
487
-
488
482
SourceRange :: ByteOffset ( start, end) => {
489
- if let FileLinesContent :: Lines ( lines) = & * this . source . content ( ) . lines ( ) . await ? {
483
+ if let FileLinesContent :: Lines ( lines) = & * self . source . content ( ) . lines ( ) . await ? {
490
484
let start = find_line_and_column ( lines. as_ref ( ) , * start) ;
491
485
let end = find_line_and_column ( lines. as_ref ( ) , * end) ;
492
486
( start, end)
493
487
} else {
494
- return Ok ( self ) ;
488
+ return Ok ( Cow :: Borrowed ( self ) ) ;
495
489
}
496
490
}
497
491
} ;
498
492
499
493
// If we have a source map, map the line/column to the original source.
500
- let mapped = source_pos ( this . source , origin, start, end) . await ?;
494
+ let mapped = source_pos ( self . source , origin, start, end) . await ?;
501
495
502
496
if let Some ( ( source, start, end) ) = mapped {
503
- return Ok ( Self :: cell ( IssueSource {
497
+ return Ok ( Cow :: Owned ( IssueSource {
504
498
source,
505
- range : Some ( SourceRange :: LineColumn ( start, end) . resolved_cell ( ) ) ,
499
+ range : Some ( SourceRange :: LineColumn ( start, end) ) ,
506
500
} ) ) ;
507
501
}
508
502
}
509
503
510
- Ok ( self )
504
+ Ok ( Cow :: Borrowed ( self ) )
511
505
}
512
506
513
507
/// Create a [`IssueSource`] from byte offsets given by an swc ast node
@@ -518,26 +512,18 @@ impl IssueSource {
518
512
/// * `source`: The source code in which to look up the byte offsets.
519
513
/// * `start`: The start index of the span. Must use **1-based** indexing.
520
514
/// * `end`: The end index of the span. Must use **1-based** indexing.
521
- #[ turbo_tasks:: function]
522
- pub fn from_swc_offsets (
523
- source : ResolvedVc < Box < dyn Source > > ,
524
- start : usize ,
525
- end : usize ,
526
- ) -> Vc < Self > {
527
- Self :: cell ( IssueSource {
515
+ pub fn from_swc_offsets ( source : ResolvedVc < Box < dyn Source > > , start : usize , end : usize ) -> Self {
516
+ IssueSource {
528
517
source,
529
518
range : match ( start == 0 , end == 0 ) {
530
519
( true , true ) => None ,
531
- ( false , false ) => Some ( SourceRange :: ByteOffset ( start - 1 , end - 1 ) . resolved_cell ( ) ) ,
532
- ( false , true ) => {
533
- Some ( SourceRange :: ByteOffset ( start - 1 , start - 1 ) . resolved_cell ( ) )
534
- }
535
- ( true , false ) => Some ( SourceRange :: ByteOffset ( end - 1 , end - 1 ) . resolved_cell ( ) ) ,
520
+ ( false , false ) => Some ( SourceRange :: ByteOffset ( start - 1 , end - 1 ) ) ,
521
+ ( false , true ) => Some ( SourceRange :: ByteOffset ( start - 1 , start - 1 ) ) ,
522
+ ( true , false ) => Some ( SourceRange :: ByteOffset ( end - 1 , end - 1 ) ) ,
536
523
} ,
537
- } )
524
+ }
538
525
}
539
526
540
- #[ turbo_tasks:: function]
541
527
/// Returns an `IssueSource` representing a span of code in the `source`.
542
528
/// Positions are derived from byte offsets and stored as lines and columns.
543
529
/// Requires a binary search of the source text to perform this.
@@ -551,21 +537,20 @@ impl IssueSource {
551
537
source : ResolvedVc < Box < dyn Source > > ,
552
538
start : usize ,
553
539
end : usize ,
554
- ) -> Result < Vc < Self > > {
555
- Ok ( Self :: cell ( IssueSource {
540
+ ) -> Result < Self > {
541
+ Ok ( IssueSource {
556
542
source,
557
543
range : if let FileLinesContent :: Lines ( lines) = & * source. content ( ) . lines ( ) . await ? {
558
544
let start = find_line_and_column ( lines. as_ref ( ) , start) ;
559
545
let end = find_line_and_column ( lines. as_ref ( ) , end) ;
560
- Some ( SourceRange :: LineColumn ( start, end) . resolved_cell ( ) )
546
+ Some ( SourceRange :: LineColumn ( start, end) )
561
547
} else {
562
548
None
563
549
} ,
564
- } ) )
550
+ } )
565
551
}
566
552
567
553
/// Returns the file path for the source file.
568
- #[ turbo_tasks:: function]
569
554
pub fn file_path ( & self ) -> Vc < FileSystemPath > {
570
555
self . source . ident ( ) . path ( )
571
556
}
@@ -574,8 +559,8 @@ impl IssueSource {
574
559
impl IssueSource {
575
560
/// Returns bytes offsets corresponding the source range in the format used by swc's Spans.
576
561
pub async fn to_swc_offsets ( & self ) -> Result < Option < ( usize , usize ) > > {
577
- Ok ( match self . range {
578
- Some ( range) => match & * range. await ? {
562
+ Ok ( match & self . range {
563
+ Some ( range) => match range {
579
564
SourceRange :: ByteOffset ( start, end) => Some ( ( * start + 1 , * end + 1 ) ) ,
580
565
SourceRange :: LineColumn ( start, end) => {
581
566
if let FileLinesContent :: Lines ( lines) = & * self . source . content ( ) . lines ( ) . await ? {
@@ -647,7 +632,7 @@ async fn source_pos(
647
632
}
648
633
649
634
#[ turbo_tasks:: value( transparent) ]
650
- pub struct OptionIssueSource ( Option < ResolvedVc < IssueSource > > ) ;
635
+ pub struct OptionIssueSource ( Option < IssueSource > ) ;
651
636
652
637
#[ turbo_tasks:: value( transparent) ]
653
638
pub struct OptionStyledString ( Option < ResolvedVc < StyledString > > ) ;
@@ -707,7 +692,7 @@ pub struct PlainIssue {
707
692
pub detail : Option < StyledString > ,
708
693
pub documentation_link : RcStr ,
709
694
710
- pub source : Option < ReadRef < PlainIssueSource > > ,
695
+ pub source : Option < PlainIssueSource > ,
711
696
pub sub_issues : Vec < ReadRef < PlainIssue > > ,
712
697
pub processing_path : ReadRef < PlainIssueProcessingPath > ,
713
698
}
@@ -779,14 +764,12 @@ pub struct PlainIssueSource {
779
764
pub range : Option < ( SourcePos , SourcePos ) > ,
780
765
}
781
766
782
- #[ turbo_tasks:: value_impl]
783
767
impl IssueSource {
784
- #[ turbo_tasks:: function]
785
- pub async fn into_plain ( & self ) -> Result < Vc < PlainIssueSource > > {
768
+ pub async fn into_plain ( & self ) -> Result < PlainIssueSource > {
786
769
Ok ( PlainIssueSource {
787
770
asset : PlainSource :: from_source ( * self . source ) . await ?,
788
- range : match self . range {
789
- Some ( range) => match & * range. await ? {
771
+ range : match & self . range {
772
+ Some ( range) => match range {
790
773
SourceRange :: LineColumn ( start, end) => Some ( ( * start, * end) ) ,
791
774
SourceRange :: ByteOffset ( start, end) => {
792
775
if let FileLinesContent :: Lines ( lines) =
@@ -802,8 +785,7 @@ impl IssueSource {
802
785
} ,
803
786
_ => None ,
804
787
} ,
805
- }
806
- . cell ( ) )
788
+ } )
807
789
}
808
790
}
809
791
0 commit comments