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,52 @@ 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
+
461
+ /// Enum types for output types for cache key computation.
462
+ /// List should contain all the output file types, including supplemententary
463
+ /// outputs, except diagnostics outputs, which are covered by cached diagnostic
464
+ /// entry.
465
+ typedef enum {
466
+ SWIFTSCAN_OUTPUT_TYPE_OBJECT = 0 ,
467
+ SWIFTSCAN_OUTPUT_TYPE_SWIFTMODULE = 1 ,
468
+ SWIFTSCAN_OUTPUT_TYPE_SWIFTINTERFACE = 2 ,
469
+ SWIFTSCAN_OUTPUT_TYPE_SWIFTPRIVATEINTERFACE = 3 ,
470
+ SWIFTSCAN_OUTPUT_TYPE_CLANG_MODULE = 4 ,
471
+ SWIFTSCAN_OUTPUT_TYPE_CLANG_PCH = 5 ,
472
+ SWIFTSCAN_OUTPUT_TYPE_CLANG_HEADER = 6 ,
473
+ SWIFTSCAN_OUTPUT_TYPE_SWIFT_SOURCE_INFO = 7 ,
474
+ SWIFTSCAN_OUTPUT_TYPE_SWIFT_MODULE_DOC = 8 ,
475
+ SWIFTSCAN_OUTPUT_TYPE_DEPENDENCIES = 9 ,
476
+ SWIFTSCAN_OUTPUT_TYPE_SWIFT_DEPS = 10 ,
477
+ SWIFTSCAN_OUTPUT_TYPE_MODULE_TRACE = 11 ,
478
+ SWIFTSCAN_OUTPUT_TYPE_TBD = 12 ,
479
+ SWIFTSCAN_OUTPUT_TYPE_SWIFT_MODULE_SUMMARY = 13 ,
480
+ SWIFTSCAN_OUTPUT_TYPE_SWIFT_ABI_DESCRIPTOR = 14 ,
481
+ SWIFTSCAN_OUTPUT_TYPE_SWIFT_API_DESCRIPTOR = 15 ,
482
+ SWIFTSCAN_OUTPUT_TYPE_CONST_VALUE = 16 ,
483
+ SWIFTSCAN_OUTPUT_TYPE_MODULE_SEMANTIC_INFO = 17 ,
484
+ SWIFTSCAN_OUTPUT_TYPE_YAML_OPT_RECORD = 18 ,
485
+ SWIFTSCAN_OUTPUT_TYPE_BITSTREAM_OPT_RECORD = 19 ,
486
+ SWIFTSCAN_OUTPUT_TYPE_CACHED_DIAGNOSTICS = 20 ,
487
+ SWIFTSCAN_OUTPUT_TYPE_LAST = SWIFTSCAN_OUTPUT_TYPE_CACHED_DIAGNOSTICS
488
+ } swiftscan_output_kind_t ;
489
+
444
490
/// Create a \c CASOptions for creating CAS inside scanner specified.
445
491
SWIFTSCAN_PUBLIC swiftscan_cas_options_t swiftscan_cas_options_create (void );
446
492
@@ -472,16 +518,16 @@ swiftscan_cas_options_set_option(swiftscan_cas_options_t options,
472
518
SWIFTSCAN_PUBLIC swiftscan_cas_t swiftscan_cas_create_from_options (
473
519
swiftscan_cas_options_t options , swiftscan_string_ref_t * error );
474
520
475
- /// Dispose the \c cas instance.
476
- SWIFTSCAN_PUBLIC void swiftscan_cas_dispose (swiftscan_cas_t cas );
477
-
478
521
/// Store content into CAS. Return \c CASID as string. Return NULL on error.
479
522
/// If error happens, the error message is returned via `error` parameter, and
480
523
/// caller needs to free the error message via `swiftscan_string_dispose`.
481
524
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
482
525
swiftscan_cas_store (swiftscan_cas_t cas , uint8_t * data , unsigned size ,
483
526
swiftscan_string_ref_t * error );
484
527
528
+ /// Dispose the \c cas instance.
529
+ SWIFTSCAN_PUBLIC void swiftscan_cas_dispose (swiftscan_cas_t cas );
530
+
485
531
/// Compute \c CacheKey for the outputs of a primary input file from a compiler
486
532
/// invocation with command-line \c argc and \c argv. When primary input file
487
533
/// is not available for compilation, e.g., using WMO, primary file is the first
@@ -492,6 +538,151 @@ SWIFTSCAN_PUBLIC swiftscan_string_ref_t
492
538
swiftscan_cache_compute_key (swiftscan_cas_t cas , int argc , const char * * argv ,
493
539
const char * input , swiftscan_string_ref_t * error );
494
540
541
+ /// Query the result of the compilation using the output cache key. \c globally
542
+ /// suggests if the lookup should check remote cache if such operation exists.
543
+ /// Returns the cached compilation of the result if found, or nullptr if output
544
+ /// is not found or an error occurs. When an error occurs, the error message is
545
+ /// returned via \c error parameter and its caller needs to free the message
546
+ /// using `swiftscan_string_dispose`. The returned cached compilation needs to
547
+ /// be freed via `swiftscan_cached_compilation_dispose`.
548
+ SWIFTSCAN_PUBLIC swiftscan_cached_compilation_t
549
+ swiftscan_cache_query (swiftscan_cas_t cas , const char * key , bool globally ,
550
+ swiftscan_string_ref_t * error );
551
+
552
+ /// Async version of `swiftscan_cache_query` where result is returned via
553
+ /// callback. Both cache_result enum and cached compilation will be provided to
554
+ /// callback. \c ctx is an opaque value that passed to the callback and \c
555
+ /// swiftscan_cache_cancellation_token_t will return an token that can be used
556
+ /// to cancel the async operation. The token needs to be freed by caller using
557
+ /// `swiftscan_cache_cancellation_token_dispose`.
558
+ SWIFTSCAN_PUBLIC void swiftscan_cache_query_async (
559
+ swiftscan_cas_t cas , const char * key , bool globally , void * ctx ,
560
+ void (* callback )(void * ctx , swiftscan_cached_compilation_t ,
561
+ swiftscan_string_ref_t error ),
562
+ swiftscan_cache_cancellation_token_t * );
563
+
564
+ /// Query the number of outputs from a cached compilation.
565
+ SWIFTSCAN_PUBLIC unsigned swiftscan_cached_compilation_get_num_outputs (
566
+ swiftscan_cached_compilation_t );
567
+
568
+ /// Get the output kind for the given index in the cached compilation.
569
+ SWIFTSCAN_PUBLIC swiftscan_output_kind_t
570
+ swiftscan_cached_compilation_get_output_kind (swiftscan_cached_compilation_t ,
571
+ unsigned idx );
572
+
573
+ /// Get the cached output for the given index in the cached compilation.
574
+ SWIFTSCAN_PUBLIC swiftscan_cached_output_t
575
+ swiftscan_cached_compilation_get_output (swiftscan_cached_compilation_t ,
576
+ unsigned idx );
577
+
578
+ /// Make the cache compilation available globally. \c callback will be called
579
+ /// on completion.
580
+ /// \c swiftscan_cache_cancellation_token_t will return an token that can be
581
+ /// used to cancel the async operation. The token needs to be freed by caller
582
+ /// using `swiftscan_cache_cancellation_token_dispose`.
583
+ SWIFTSCAN_PUBLIC void swiftscan_cached_compilation_make_global_async (
584
+ swiftscan_cas_t cas , swiftscan_cached_compilation_t , void * ctx ,
585
+ void (* callback )(void * ctx , swiftscan_string_ref_t error ),
586
+ swiftscan_cache_cancellation_token_t * );
587
+
588
+ /// Dispose a cached compilation.
589
+ SWIFTSCAN_PUBLIC
590
+ void swiftscan_cached_compilation_dispose (swiftscan_cached_compilation_t );
591
+
592
+ /// Download and materialize the cached output if needed from a remote CAS.
593
+ /// Return true if load is successful, else false if not found or error. If
594
+ /// error, the error message is returned via \c error parameter and its caller
595
+ /// needs to free the message using `swiftscan_string_dispose`.
596
+ SWIFTSCAN_PUBLIC bool
597
+ swiftscan_cached_output_load (swiftscan_cas_t cas , swiftscan_cached_output_t ,
598
+ swiftscan_string_ref_t * error );
599
+
600
+ /// Async version of `swiftscan_cached_output_load` where result is
601
+ /// returned via callback. \c ctx is an opaque value that passed to the callback
602
+ /// and \c swiftscan_cache_cancellation_token_t will return an token that can be
603
+ /// used to cancel the async operation. The token needs to be freed by caller
604
+ /// using `swiftscan_cache_cancellation_token_dispose`.
605
+ SWIFTSCAN_PUBLIC void swiftscan_cached_output_load_async (
606
+ swiftscan_cas_t cas , swiftscan_cached_output_t , void * ctx ,
607
+ void (* callback )(void * ctx , bool success , swiftscan_string_ref_t error ),
608
+ swiftscan_cache_cancellation_token_t * );
609
+
610
+ /// Check if cached output is materialized locally and can be accessed
611
+ /// without downloading.
612
+ SWIFTSCAN_PUBLIC bool
613
+ swiftscan_cached_output_is_materialized (swiftscan_cas_t ,
614
+ swiftscan_cached_output_t );
615
+
616
+ /// Dispose a cached output.
617
+ SWIFTSCAN_PUBLIC
618
+ void swiftscan_cached_output_dispose (swiftscan_cached_output_t );
619
+
620
+ /// Cancel the async cache action that is associated with token.
621
+ SWIFTSCAN_PUBLIC void
622
+ swiftscan_cache_action_cancel (swiftscan_cache_cancellation_token_t );
623
+
624
+ /// Dispose the cancellation token.
625
+ SWIFTSCAN_PUBLIC void swiftscan_cache_cancellation_token_dispose (
626
+ swiftscan_cache_cancellation_token_t );
627
+
628
+ /// Create a swift cached compilation replay instance with its command-line
629
+ /// invocation. Return nullptr when errors occurs and the error message is
630
+ /// returned via \c error parameter and its caller needs to free the message
631
+ /// using `swiftscan_string_dispose`.
632
+ SWIFTSCAN_PUBLIC swiftscan_cache_replay_instance_t
633
+ swiftscan_cache_replay_instance_create (int argc , const char * * argv ,
634
+ swiftscan_string_ref_t * error );
635
+
636
+ /// Dispose swift cached compilation replay instance.
637
+ SWIFTSCAN_PUBLIC void
638
+ swiftscan_cache_replay_instance_dispose (swiftscan_cache_replay_instance_t );
639
+
640
+ /// Replay the cached compilation using cached compliation replay instance.
641
+ /// Returns replay result or nullptr if output not found or error occurs. If
642
+ /// error, the error message is returned via \c error parameter and its caller
643
+ /// needs to free the message using `swiftscan_string_dispose`.
644
+ SWIFTSCAN_PUBLIC swiftscan_cache_replay_result_t
645
+ swiftscan_cache_replay_compilation (swiftscan_cas_t cas ,
646
+ swiftscan_cache_replay_instance_t ,
647
+ swiftscan_cached_compilation_t ,
648
+ swiftscan_string_ref_t * error );
649
+
650
+ /// Async replay the cached compilation. Callback function will be provided
651
+ /// by the cache replay result, and its stdout, stderr, and any error message.
652
+ /// \c ctx is an opaque value that passed to the callback and
653
+ /// \c swiftscan_cache_cancellation_token_t will return an token that can be
654
+ /// used to cancel the async operation. The token needs to be freed by caller
655
+ /// using `swiftscan_cache_cancellation_token_dispose`.
656
+ SWIFTSCAN_PUBLIC void swiftscan_cache_replay_compilation_async (
657
+ swiftscan_cas_t cas , swiftscan_cache_replay_instance_t ,
658
+ swiftscan_cached_compilation_t , void * ctx ,
659
+ void (* callback )(void * ctx , swiftscan_cache_replay_result_t ,
660
+ swiftscan_string_ref_t error ),
661
+ swiftscan_cache_cancellation_token_t * );
662
+
663
+ /// Get return code from replay. Return code is 0 for success, and a non-zero
664
+ /// value for failure.
665
+ /// FIXME: This should match the return code from `swift-frontend` invocation.
666
+ SWIFTSCAN_PUBLIC
667
+ int swiftscan_cache_replay_result_get_return_code (
668
+ swiftscan_cache_replay_result_t );
669
+
670
+ /// Get stdout from cached replay result. The returning swiftscan_string_ref_t
671
+ /// is owned by replay result and should not be disposed.
672
+ SWIFTSCAN_PUBLIC
673
+ swiftscan_string_ref_t
674
+ swiftscan_cache_replay_result_get_stdout (swiftscan_cache_replay_result_t );
675
+
676
+ /// Get stderr from cached replay result. The returning swiftscan_string_ref_t
677
+ /// is owned by replay result and should not be disposed.
678
+ SWIFTSCAN_PUBLIC
679
+ swiftscan_string_ref_t
680
+ swiftscan_cache_replay_result_get_stderr (swiftscan_cache_replay_result_t );
681
+
682
+ /// Dispose a cached replay result.
683
+ SWIFTSCAN_PUBLIC
684
+ void swiftscan_cache_replay_result_dispose (swiftscan_cache_replay_result_t );
685
+
495
686
//===----------------------------------------------------------------------===//
496
687
497
688
SWIFTSCAN_END_DECLS
0 commit comments