@@ -69,8 +69,23 @@ raw_ostream &operator<<(raw_ostream &OS, const SymbolDependenceMap &Deps);
69
69
// / A list of VSO pointers.
70
70
using VSOList = std::vector<VSO *>;
71
71
72
+ // / Render a VSOList.
72
73
raw_ostream &operator <<(raw_ostream &OS, const VSOList &VSOs);
73
74
75
+ // / Callback to notify client that symbols have been resolved.
76
+ using SymbolsResolvedCallback = std::function<void (Expected<SymbolMap>)>;
77
+
78
+ // / Callback to notify client that symbols are ready for execution.
79
+ using SymbolsReadyCallback = std::function<void (Error)>;
80
+
81
+ // / Callback to register the dependencies for a given query.
82
+ using RegisterDependenciesFunction =
83
+ std::function<void (const SymbolDependenceMap &)>;
84
+
85
+ // / This can be used as the value for a RegisterDependenciesFunction if there
86
+ // / are no dependants to register with.
87
+ extern RegisterDependenciesFunction NoDependenciesToRegister;
88
+
74
89
// / Used to notify a VSO that the given set of symbols failed to materialize.
75
90
class FailedToMaterialize : public ErrorInfo <FailedToMaterialize> {
76
91
public:
@@ -122,6 +137,9 @@ class MaterializationResponsibility {
122
137
// / into.
123
138
VSO &getTargetVSO () const { return V; }
124
139
140
+ // / Returns the symbol flags map for this responsibility instance.
141
+ SymbolFlagsMap getSymbols () { return SymbolFlags; }
142
+
125
143
// / Returns the names of any symbols covered by this
126
144
// / MaterializationResponsibility object that have queries pending. This
127
145
// / information can be used to return responsibility for unrequested symbols
@@ -223,6 +241,9 @@ class MaterializationUnit {
223
241
virtual void discard (const VSO &V, SymbolStringPtr Name) = 0;
224
242
};
225
243
244
+ using MaterializationUnitList =
245
+ std::vector<std::unique_ptr<MaterializationUnit>>;
246
+
226
247
// / A MaterializationUnit implementation for pre-existing absolute symbols.
227
248
// /
228
249
// / All symbols will be resolved and marked ready as soon as the unit is
@@ -322,6 +343,9 @@ buildSimpleReexportsAliasMap(VSO &SourceV, const SymbolNameSet &Symbols);
322
343
323
344
// / Base utilities for ExecutionSession.
324
345
class ExecutionSessionBase {
346
+ // FIXME: Remove this when we remove the old ORC layers.
347
+ friend class VSO ;
348
+
325
349
public:
326
350
// / For reporting errors.
327
351
using ErrorReporter = std::function<void (Error)>;
@@ -372,11 +396,50 @@ class ExecutionSessionBase {
372
396
void releaseVModule (VModuleKey Key) { /* FIXME: Recycle keys */
373
397
}
374
398
375
- // / Cause the given query to fail with the given Error.
399
+ void legacyFailQuery (AsynchronousSymbolQuery &Q, Error Err);
400
+
401
+ using LegacyAsyncLookupFunction = std::function<SymbolNameSet(
402
+ std::shared_ptr<AsynchronousSymbolQuery> Q, SymbolNameSet Names)>;
403
+
404
+ // / A legacy lookup function for JITSymbolResolverAdapter.
405
+ // / Do not use -- this will be removed soon.
406
+ Expected<SymbolMap>
407
+ legacyLookup (ExecutionSessionBase &ES, LegacyAsyncLookupFunction AsyncLookup,
408
+ SymbolNameSet Names, bool WaiUntilReady,
409
+ RegisterDependenciesFunction RegisterDependencies);
410
+
411
+ // / Search the given VSO list for the given symbols.
376
412
// /
377
- // / This should only be used by legacy APIs and will be deprecated in the
378
- // / future.
379
- void failQuery (AsynchronousSymbolQuery &Q, Error Err);
413
+ // /
414
+ // / The OnResolve callback will be called once all requested symbols are
415
+ // / resolved, or if an error occurs prior to resolution.
416
+ // /
417
+ // / The OnReady callback will be called once all requested symbols are ready,
418
+ // / or if an error occurs after resolution but before all symbols are ready.
419
+ // /
420
+ // / If all symbols are found, the RegisterDependencies function will be called
421
+ // / while the session lock is held. This gives clients a chance to register
422
+ // / dependencies for on the queried symbols for any symbols they are
423
+ // / materializing (if a MaterializationResponsibility instance is present,
424
+ // / this can be implemented by calling
425
+ // / MaterializationResponsibility::addDependencies). If there are no
426
+ // / dependenant symbols for this query (e.g. it is being made by a top level
427
+ // / client to get an address to call) then the value NoDependenciesToRegister
428
+ // / can be used.
429
+ void lookup (const VSOList &VSOs, const SymbolNameSet &Symbols,
430
+ SymbolsResolvedCallback OnResolve, SymbolsReadyCallback OnReady,
431
+ RegisterDependenciesFunction RegisterDependencies);
432
+
433
+ // / Blocking version of lookup above. Returns the resolved symbol map.
434
+ // / If WaitUntilReady is true (the default), will not return until all
435
+ // / requested symbols are ready (or an error occurs). If WaitUntilReady is
436
+ // / false, will return as soon as all requested symbols are resolved,
437
+ // / or an error occurs. If WaitUntilReady is false and an error occurs
438
+ // / after resolution, the function will return a success value, but the
439
+ // / error will be reported via reportErrors.
440
+ Expected<SymbolMap> lookup (const VSOList &VSOs, const SymbolNameSet &Symbols,
441
+ RegisterDependenciesFunction RegisterDependencies,
442
+ bool WaitUntilReady = true );
380
443
381
444
// / Materialize the given unit.
382
445
void dispatchMaterialization (VSO &V,
@@ -394,12 +457,20 @@ class ExecutionSessionBase {
394
457
MU->doMaterialize (V);
395
458
}
396
459
460
+ void runOutstandingMUs ();
461
+
397
462
mutable std::recursive_mutex SessionMutex;
398
463
std::shared_ptr<SymbolStringPool> SSP;
399
464
VModuleKey LastKey = 0 ;
400
465
ErrorReporter ReportError = logErrorsToStdErr;
401
466
DispatchMaterializationFunction DispatchMaterialization =
402
467
materializeOnCurrentThread;
468
+
469
+ // FIXME: Remove this (and runOutstandingMUs) once the linking layer works
470
+ // with callbacks from asynchronous queries.
471
+ mutable std::recursive_mutex OutstandingMUsMutex;
472
+ std::vector<std::pair<VSO *, std::unique_ptr<MaterializationUnit>>>
473
+ OutstandingMUs;
403
474
};
404
475
405
476
// / A symbol query that returns results via a callback when results are
@@ -411,21 +482,6 @@ class AsynchronousSymbolQuery {
411
482
friend class VSO ;
412
483
413
484
public:
414
- class ResolutionResult {
415
- public:
416
- ResolutionResult (SymbolMap Symbols, const SymbolDependenceMap &Dependencies)
417
- : Symbols(std::move(Symbols)), Dependencies(Dependencies) {}
418
-
419
- SymbolMap Symbols;
420
- const SymbolDependenceMap &Dependencies;
421
- };
422
-
423
- // / Callback to notify client that symbols have been resolved.
424
- using SymbolsResolvedCallback =
425
- std::function<void (Expected<ResolutionResult>)>;
426
-
427
- // / Callback to notify client that symbols are ready for execution.
428
- using SymbolsReadyCallback = std::function<void (Error)>;
429
485
430
486
// / Create a query for the given symbols, notify-resolved and
431
487
// / notify-ready callbacks.
@@ -485,6 +541,7 @@ class AsynchronousSymbolQuery {
485
541
class VSO {
486
542
friend class AsynchronousSymbolQuery ;
487
543
friend class ExecutionSession ;
544
+ friend class ExecutionSessionBase ;
488
545
friend class MaterializationResponsibility ;
489
546
public:
490
547
using FallbackDefinitionGeneratorFunction =
@@ -493,9 +550,6 @@ class VSO {
493
550
using AsynchronousSymbolQuerySet =
494
551
std::set<std::shared_ptr<AsynchronousSymbolQuery>>;
495
552
496
- using MaterializationUnitList =
497
- std::vector<std::unique_ptr<MaterializationUnit>>;
498
-
499
553
VSO (const VSO &) = delete ;
500
554
VSO &operator =(const VSO &) = delete ;
501
555
VSO (VSO &&) = delete ;
@@ -547,8 +601,10 @@ class VSO {
547
601
void removeFromSearchOrder (VSO &V);
548
602
549
603
// / Do something with the search order (run under the session lock).
550
- template <typename Func> void withSearchOrderDo (Func F) {
551
- ES.runSessionLocked ([&]() { F (SearchOrder); });
604
+ template <typename Func>
605
+ auto withSearchOrderDo (Func &&F)
606
+ -> decltype(F(std::declval<const VSOList &>())) {
607
+ return ES.runSessionLocked ([&]() { return F (SearchOrder); });
552
608
}
553
609
554
610
// / Define all symbols provided by the materialization unit to be part
@@ -579,18 +635,19 @@ class VSO {
579
635
// / the flags for each symbol in Flags. Returns any unresolved symbols.
580
636
SymbolFlagsMap lookupFlags (const SymbolNameSet &Names);
581
637
638
+ // / Dump current VSO state to OS.
639
+ void dump (raw_ostream &OS);
640
+
641
+ // / FIXME: Remove this when we remove the old ORC layers.
582
642
// / Search the given VSOs in order for the symbols in Symbols. Results
583
643
// / (once they become available) will be returned via the given Query.
584
644
// /
585
645
// / If any symbol is not found then the unresolved symbols will be returned,
586
646
// / and the query will not be applied. The Query is not failed and can be
587
647
// / re-used in a subsequent lookup once the symbols have been added, or
588
648
// / manually failed.
589
- SymbolNameSet lookup (std::shared_ptr<AsynchronousSymbolQuery> Q,
590
- SymbolNameSet Names);
591
-
592
- // / Dump current VSO state to OS.
593
- void dump (raw_ostream &OS);
649
+ SymbolNameSet legacyLookup (std::shared_ptr<AsynchronousSymbolQuery> Q,
650
+ SymbolNameSet Names);
594
651
595
652
private:
596
653
using AsynchronousSymbolQueryList =
@@ -629,6 +686,12 @@ class VSO {
629
686
SymbolNameSet lookupFlagsImpl (SymbolFlagsMap &Flags,
630
687
const SymbolNameSet &Names);
631
688
689
+ void lodgeQuery (std::shared_ptr<AsynchronousSymbolQuery> &Q,
690
+ SymbolNameSet &Unresolved, MaterializationUnitList &MUs);
691
+
692
+ void lodgeQueryImpl (std::shared_ptr<AsynchronousSymbolQuery> &Q,
693
+ SymbolNameSet &Unresolved, MaterializationUnitList &MUs);
694
+
632
695
LookupImplActionFlags
633
696
lookupImpl (std::shared_ptr<AsynchronousSymbolQuery> &Q,
634
697
std::vector<std::unique_ptr<MaterializationUnit>> &MUs,
@@ -647,29 +710,22 @@ class VSO {
647
710
648
711
SymbolNameSet getRequestedSymbols (const SymbolFlagsMap &SymbolFlags);
649
712
650
- void addDependencies (const SymbolFlagsMap &Dependents ,
651
- const SymbolDependenceMap &Dependencies );
713
+ void addDependencies (const SymbolStringPtr &Name ,
714
+ const SymbolDependenceMap &Dependants );
652
715
653
716
void resolve (const SymbolMap &Resolved);
654
717
655
718
void finalize (const SymbolFlagsMap &Finalized);
656
719
657
720
void notifyFailed (const SymbolNameSet &FailedSymbols);
658
721
659
- void runOutstandingMUs ();
660
-
661
722
ExecutionSessionBase &ES;
662
723
std::string VSOName;
663
724
SymbolMap Symbols;
664
725
UnmaterializedInfosMap UnmaterializedInfos;
665
726
MaterializingInfosMap MaterializingInfos;
666
727
FallbackDefinitionGeneratorFunction FallbackDefinitionGenerator;
667
728
VSOList SearchOrder;
668
-
669
- // FIXME: Remove this (and runOutstandingMUs) once the linking layer works
670
- // with callbacks from asynchronous queries.
671
- mutable std::recursive_mutex OutstandingMUsMutex;
672
- std::vector<std::unique_ptr<MaterializationUnit>> OutstandingMUs;
673
729
};
674
730
675
731
// / An ExecutionSession represents a running JIT program.
@@ -693,15 +749,6 @@ class ExecutionSession : public ExecutionSessionBase {
693
749
std::vector<std::unique_ptr<VSO>> VSOs;
694
750
};
695
751
696
- using AsynchronousLookupFunction = std::function<SymbolNameSet(
697
- std::shared_ptr<AsynchronousSymbolQuery> Q, SymbolNameSet Names)>;
698
-
699
- // / Perform a blocking lookup on the given symbols.
700
- Expected<SymbolMap> blockingLookup (ExecutionSessionBase &ES,
701
- AsynchronousLookupFunction AsyncLookup,
702
- SymbolNameSet Names, bool WaiUntilReady,
703
- MaterializationResponsibility *MR = nullptr );
704
-
705
752
// / Look up the given names in the given VSOs.
706
753
// / VSOs will be searched in order and no VSO pointer may be null.
707
754
// / All symbols must be found within the given VSOs or an error
0 commit comments