25
25
/// SWIFTSCAN_VERSION_MINOR should increase when there are API additions.
26
26
/// SWIFTSCAN_VERSION_MAJOR is intended for "major" source/ABI breaking changes.
27
27
#define SWIFTSCAN_VERSION_MAJOR 0
28
- #define SWIFTSCAN_VERSION_MINOR 5
28
+ #define SWIFTSCAN_VERSION_MINOR 6
29
29
30
30
SWIFTSCAN_BEGIN_DECLS
31
31
@@ -441,6 +441,23 @@ typedef struct swiftscan_cas_options_s *swiftscan_cas_options_t;
441
441
/// ActionCache.
442
442
typedef struct swiftscan_cas_s * swiftscan_cas_t ;
443
443
444
+ /// Opaque container for a cached compilation.
445
+ typedef struct swiftscan_cached_compilation_s * swiftscan_cached_compilation_t ;
446
+
447
+ /// Opaque container for a cached compilation output.
448
+ typedef struct swiftscan_cached_output_s * swiftscan_cached_output_t ;
449
+
450
+ /// Opaque type for a cache replay instance.
451
+ typedef struct swiftscan_cache_replay_instance_s
452
+ * swiftscan_cache_replay_instance_t ;
453
+
454
+ /// Opaque container for a cached compilation replay result.
455
+ typedef struct swiftscan_cache_replay_result_s * swiftscan_cache_replay_result_t ;
456
+
457
+ /// Opaque type for a cancellation token for async cache operations.
458
+ typedef struct swiftscan_cache_cancellation_token_s
459
+ * swiftscan_cache_cancellation_token_t ;
460
+
444
461
/// Create a \c CASOptions for creating CAS inside scanner specified.
445
462
SWIFTSCAN_PUBLIC swiftscan_cas_options_t swiftscan_cas_options_create (void );
446
463
@@ -472,16 +489,16 @@ swiftscan_cas_options_set_option(swiftscan_cas_options_t options,
472
489
SWIFTSCAN_PUBLIC swiftscan_cas_t swiftscan_cas_create_from_options (
473
490
swiftscan_cas_options_t options , swiftscan_string_ref_t * error );
474
491
475
- /// Dispose the \c cas instance.
476
- SWIFTSCAN_PUBLIC void swiftscan_cas_dispose (swiftscan_cas_t cas );
477
-
478
492
/// Store content into CAS. Return \c CASID as string. Return NULL on error.
479
493
/// If error happens, the error message is returned via `error` parameter, and
480
494
/// caller needs to free the error message via `swiftscan_string_dispose`.
481
495
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
482
496
swiftscan_cas_store (swiftscan_cas_t cas , uint8_t * data , unsigned size ,
483
497
swiftscan_string_ref_t * error );
484
498
499
+ /// Dispose the \c cas instance.
500
+ SWIFTSCAN_PUBLIC void swiftscan_cas_dispose (swiftscan_cas_t cas );
501
+
485
502
/// Compute \c CacheKey for the outputs of a primary input file from a compiler
486
503
/// invocation with command-line \c argc and \c argv. When primary input file
487
504
/// is not available for compilation, e.g., using WMO, primary file is the first
@@ -492,6 +509,145 @@ SWIFTSCAN_PUBLIC swiftscan_string_ref_t
492
509
swiftscan_cache_compute_key (swiftscan_cas_t cas , int argc , const char * * argv ,
493
510
const char * input , swiftscan_string_ref_t * error );
494
511
512
+ /// Query the result of the compilation using the output cache key. \c globally
513
+ /// suggests if the lookup should check remote cache if such operation exists.
514
+ /// Returns the cached compilation of the result if found, or nullptr if output
515
+ /// is not found or an error occurs. When an error occurs, the error message is
516
+ /// returned via \c error parameter and its caller needs to free the message
517
+ /// using `swiftscan_string_dispose`. The returned cached compilation needs to
518
+ /// be freed via `swiftscan_cached_compilation_dispose`.
519
+ SWIFTSCAN_PUBLIC swiftscan_cached_compilation_t
520
+ swiftscan_cache_query (swiftscan_cas_t cas , const char * key , bool globally ,
521
+ swiftscan_string_ref_t * error );
522
+
523
+ /// Async version of `swiftscan_cache_query` where result is returned via
524
+ /// callback. Both cache_result enum and cached compilation will be provided to
525
+ /// callback. \c ctx is an opaque value that passed to the callback and \c
526
+ /// swiftscan_cache_cancellation_token_t will return an token that can be used
527
+ /// to cancel the async operation. The token needs to be freed by caller using
528
+ /// `swiftscan_cache_cancellation_token_dispose`. If no token is needed, nullptr
529
+ /// can be passed and no token will be returned.
530
+ SWIFTSCAN_PUBLIC void swiftscan_cache_query_async (
531
+ swiftscan_cas_t cas , const char * key , bool globally , void * ctx ,
532
+ void (* callback )(void * ctx , swiftscan_cached_compilation_t ,
533
+ swiftscan_string_ref_t error ),
534
+ swiftscan_cache_cancellation_token_t * );
535
+
536
+ /// Query the number of outputs from a cached compilation.
537
+ SWIFTSCAN_PUBLIC unsigned swiftscan_cached_compilation_get_num_outputs (
538
+ swiftscan_cached_compilation_t );
539
+
540
+ /// Get the output kind name for the given index in the cached compilation. The
541
+ /// returned name needs to be freed by `swiftscan_string_dispose`.
542
+ SWIFTSCAN_PUBLIC swiftscan_string_ref_t
543
+ swiftscan_cached_compilation_get_output_kind_name (
544
+ swiftscan_cached_compilation_t , unsigned idx );
545
+
546
+ /// Get the cached output for the given index in the cached compilation.
547
+ SWIFTSCAN_PUBLIC swiftscan_cached_output_t
548
+ swiftscan_cached_compilation_get_output (swiftscan_cached_compilation_t ,
549
+ unsigned idx );
550
+
551
+ /// Check if the requested cached compilation is uncacheable. That means the
552
+ /// compiler decides to skip caching its output even the compilation is
553
+ /// successful.
554
+ SWIFTSCAN_PUBLIC bool
555
+ swiftscan_cached_compilation_is_uncacheable (swiftscan_cached_compilation_t );
556
+
557
+ /// Make the cache compilation available globally. \c callback will be called
558
+ /// on completion.
559
+ /// \c swiftscan_cache_cancellation_token_t will return an token that can be
560
+ /// used to cancel the async operation. The token needs to be freed by caller
561
+ /// using `swiftscan_cache_cancellation_token_dispose`. If no token is needed,
562
+ /// nullptr can be passed and no token will be returned.
563
+ SWIFTSCAN_PUBLIC void swiftscan_cached_compilation_make_global_async (
564
+ swiftscan_cas_t cas , swiftscan_cached_compilation_t , void * ctx ,
565
+ void (* callback )(void * ctx , swiftscan_string_ref_t error ),
566
+ swiftscan_cache_cancellation_token_t * );
567
+
568
+ /// Dispose a cached compilation.
569
+ SWIFTSCAN_PUBLIC
570
+ void swiftscan_cached_compilation_dispose (swiftscan_cached_compilation_t );
571
+
572
+ /// Download and materialize the cached output if needed from a remote CAS.
573
+ /// Return true if load is successful, else false if not found or error. If
574
+ /// error, the error message is returned via \c error parameter and its caller
575
+ /// needs to free the message using `swiftscan_string_dispose`.
576
+ SWIFTSCAN_PUBLIC bool
577
+ swiftscan_cached_output_load (swiftscan_cached_output_t ,
578
+ swiftscan_string_ref_t * error );
579
+
580
+ /// Async version of `swiftscan_cached_output_load` where result is
581
+ /// returned via callback. \c ctx is an opaque value that passed to the callback
582
+ /// and \c swiftscan_cache_cancellation_token_t will return an token that can be
583
+ /// used to cancel the async operation. The token needs to be freed by caller
584
+ /// using `swiftscan_cache_cancellation_token_dispose`. If no token is needed,
585
+ /// nullptr can be passed and no token will be returned.
586
+ SWIFTSCAN_PUBLIC void swiftscan_cached_output_load_async (
587
+ swiftscan_cached_output_t , void * ctx ,
588
+ void (* callback )(void * ctx , bool success , swiftscan_string_ref_t error ),
589
+ swiftscan_cache_cancellation_token_t * );
590
+
591
+ /// Check if cached output is materialized locally and can be accessed
592
+ /// without downloading.
593
+ SWIFTSCAN_PUBLIC bool
594
+ swiftscan_cached_output_is_materialized (swiftscan_cached_output_t );
595
+
596
+ /// Return the casid for the cached output as \c swiftscan_string_ref_t and the
597
+ /// returned string needs to be freed using `swiftscan_string_dispose`. CASID
598
+ /// can be requested before load/materializaing.
599
+ SWIFTSCAN_PUBLIC swiftscan_string_ref_t
600
+ swiftscan_cached_output_get_casid (swiftscan_cached_output_t );
601
+
602
+ /// Dispose a cached output.
603
+ SWIFTSCAN_PUBLIC
604
+ void swiftscan_cached_output_dispose (swiftscan_cached_output_t );
605
+
606
+ /// Cancel the async cache action that is associated with token.
607
+ SWIFTSCAN_PUBLIC void
608
+ swiftscan_cache_action_cancel (swiftscan_cache_cancellation_token_t );
609
+
610
+ /// Dispose the cancellation token.
611
+ SWIFTSCAN_PUBLIC void swiftscan_cache_cancellation_token_dispose (
612
+ swiftscan_cache_cancellation_token_t );
613
+
614
+ /// Create a swift cached compilation replay instance with its command-line
615
+ /// invocation. Return nullptr when errors occurs and the error message is
616
+ /// returned via \c error parameter and its caller needs to free the message
617
+ /// using `swiftscan_string_dispose`.
618
+ SWIFTSCAN_PUBLIC swiftscan_cache_replay_instance_t
619
+ swiftscan_cache_replay_instance_create (int argc , const char * * argv ,
620
+ swiftscan_string_ref_t * error );
621
+
622
+ /// Dispose swift cached compilation replay instance.
623
+ SWIFTSCAN_PUBLIC void
624
+ swiftscan_cache_replay_instance_dispose (swiftscan_cache_replay_instance_t );
625
+
626
+ /// Replay the cached compilation using cached compliation replay instance.
627
+ /// Returns replay result or nullptr if output not found or error occurs. If
628
+ /// error, the error message is returned via \c error parameter and its caller
629
+ /// needs to free the message using `swiftscan_string_dispose`.
630
+ SWIFTSCAN_PUBLIC swiftscan_cache_replay_result_t
631
+ swiftscan_cache_replay_compilation (swiftscan_cache_replay_instance_t ,
632
+ swiftscan_cached_compilation_t ,
633
+ swiftscan_string_ref_t * error );
634
+
635
+ /// Get stdout from cached replay result. The returning swiftscan_string_ref_t
636
+ /// is owned by replay result and should not be disposed.
637
+ SWIFTSCAN_PUBLIC
638
+ swiftscan_string_ref_t
639
+ swiftscan_cache_replay_result_get_stdout (swiftscan_cache_replay_result_t );
640
+
641
+ /// Get stderr from cached replay result. The returning swiftscan_string_ref_t
642
+ /// is owned by replay result and should not be disposed.
643
+ SWIFTSCAN_PUBLIC
644
+ swiftscan_string_ref_t
645
+ swiftscan_cache_replay_result_get_stderr (swiftscan_cache_replay_result_t );
646
+
647
+ /// Dispose a cached replay result.
648
+ SWIFTSCAN_PUBLIC
649
+ void swiftscan_cache_replay_result_dispose (swiftscan_cache_replay_result_t );
650
+
495
651
//===----------------------------------------------------------------------===//
496
652
497
653
SWIFTSCAN_END_DECLS
0 commit comments