@lucent-lang/lucent 0.0.4 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/README.md +97 -0
  2. package/app.plugin.js +46 -10
  3. package/dist/{bench-CR3E7e2e.js → bench-B555m0wU.js} +10 -6
  4. package/dist/{build-CAIrRSYA.js → build-UZ5Zm5m6.js} +1 -1
  5. package/dist/{build-check-QozuNJm5.js → build-check-Dmf8_yiw.js} +28 -13
  6. package/dist/{check-1SCmYlqA.js → check-D-H9WLG4.js} +1 -1
  7. package/dist/cli.js +62 -13
  8. package/dist/{codes-CIuwXt1S.js → codes-D-6LxUqD.js} +163 -7
  9. package/dist/compiler.js +4 -4
  10. package/dist/{dashboard-B-NzjjaN.js → dashboard-C8iF5-6T.js} +2 -2
  11. package/dist/{dev-BYWMP7oC.js → dev-B3lSx5CF.js} +62 -23
  12. package/dist/{diagnostic-BM9sXmwl.js → diagnostic-BvwLZQS1.js} +3 -1
  13. package/dist/{doctor-C0PrfWT6.js → doctor-CTAX3euc.js} +1 -1
  14. package/dist/{doctor-DdR4JnVc.js → doctor-CrgOAV5L.js} +1 -1
  15. package/dist/{explain--vV1oaRl.js → explain-Byit07F-.js} +1 -1
  16. package/dist/{packages-HyskKIsY.js → packages-CSmKeaAh.js} +2 -33
  17. package/dist/pipeline-BBY0df_2.js +700 -0
  18. package/dist/project-BLhWwnns.js +342 -0
  19. package/dist/sdk-coverage-DFGiDOzR.js +113 -0
  20. package/dist/sdk-diff-DpPYWzrl.js +109 -0
  21. package/dist/sdk-lock-QOxEFD1o.js +38 -0
  22. package/dist/{sdk-prefetch-mo04JDZV.js → sdk-prefetch-DX6ztlPN.js} +2 -2
  23. package/dist/{sdk-search-Iv4K3-8a.js → sdk-search-BShBL1LL.js} +2 -2
  24. package/dist/{sdk-show-CkrdlqlP.js → sdk-show-B3bI-0M7.js} +5 -4
  25. package/dist/sdk-usage-ljX5bTuZ.js +95 -0
  26. package/dist/src-DlICbK91.js +39682 -0
  27. package/dist/trace-Bi4hkmPx.js +139 -0
  28. package/lib/core.cjs +368 -1
  29. package/lib/sdk/android.d.ts +54 -1
  30. package/lib/sdk/compose.d.ts +94 -0
  31. package/lib/sdk/compose.schemas.json.gz +0 -0
  32. package/lib/sdk/core.d.ts +201 -0
  33. package/lib/sdk/ios.d.ts +75 -2
  34. package/lib/sdk/ui.d.ts +129 -0
  35. package/metro/transformer.cjs +11 -2
  36. package/package.json +2 -1
  37. package/runtime/cpp/lucent/abort.cpp +59 -11
  38. package/runtime/cpp/lucent/abort.h +22 -6
  39. package/runtime/cpp/lucent/array.h +12 -2
  40. package/runtime/cpp/lucent/async.h +101 -21
  41. package/runtime/cpp/lucent/bigint.cpp +898 -0
  42. package/runtime/cpp/lucent/bigint.h +302 -0
  43. package/runtime/cpp/lucent/buffer.cpp +228 -0
  44. package/runtime/cpp/lucent/buffer.h +328 -0
  45. package/runtime/cpp/lucent/builtins.cpp +4 -1
  46. package/runtime/cpp/lucent/bytes.h +21 -2
  47. package/runtime/cpp/lucent/callback.cpp +29 -0
  48. package/runtime/cpp/lucent/callback.h +230 -0
  49. package/runtime/cpp/lucent/compute.cpp +370 -0
  50. package/runtime/cpp/lucent/compute.h +455 -0
  51. package/runtime/cpp/lucent/conversions.h +111 -0
  52. package/runtime/cpp/lucent/core.h +16 -5
  53. package/runtime/cpp/lucent/equality.h +107 -28
  54. package/runtime/cpp/lucent/execution.cpp +416 -0
  55. package/runtime/cpp/lucent/execution.h +270 -0
  56. package/runtime/cpp/lucent/extension.cpp +97 -0
  57. package/runtime/cpp/lucent/extension.h +210 -0
  58. package/runtime/cpp/lucent/helpers.h +12 -5
  59. package/runtime/cpp/lucent/items.h +52 -0
  60. package/runtime/cpp/lucent/jserror.cpp +9 -0
  61. package/runtime/cpp/lucent/jserror.h +11 -0
  62. package/runtime/cpp/lucent/jsi/convert.cpp +138 -0
  63. package/runtime/cpp/lucent/jsi/convert.h +128 -59
  64. package/runtime/cpp/lucent/jsi/host.cpp +213 -35
  65. package/runtime/cpp/lucent/jsi/host.h +116 -16
  66. package/runtime/cpp/lucent/json.h +19 -1
  67. package/runtime/cpp/lucent/lifecycle.cpp +260 -0
  68. package/runtime/cpp/lucent/lifecycle.h +124 -0
  69. package/runtime/cpp/lucent/lucent.h +7 -0
  70. package/runtime/cpp/lucent/map.h +41 -7
  71. package/runtime/cpp/lucent/native.cpp +35 -47
  72. package/runtime/cpp/lucent/native.h +116 -26
  73. package/runtime/cpp/lucent/number.cpp +38 -38
  74. package/runtime/cpp/lucent/number.h +33 -0
  75. package/runtime/cpp/lucent/operation.h +65 -0
  76. package/runtime/cpp/lucent/ops.h +14 -6
  77. package/runtime/cpp/lucent/platform/android.cpp +223 -10
  78. package/runtime/cpp/lucent/platform/android.h +227 -4
  79. package/runtime/cpp/lucent/platform/android_activity.cpp +258 -0
  80. package/runtime/cpp/lucent/platform/android_requests.h +140 -0
  81. package/runtime/cpp/lucent/platform/compose.h +256 -0
  82. package/runtime/cpp/lucent/platform/ios.h +325 -25
  83. package/runtime/cpp/lucent/platform/ios.mm +1 -14
  84. package/runtime/cpp/lucent/platform/ios_ui.h +192 -0
  85. package/runtime/cpp/lucent/platform/ios_ui.mm +454 -0
  86. package/runtime/cpp/lucent/platform/swiftui.h +190 -0
  87. package/runtime/cpp/lucent/presentation.cpp +11 -0
  88. package/runtime/cpp/lucent/presentation.h +109 -0
  89. package/runtime/cpp/lucent/reactive.cpp +406 -0
  90. package/runtime/cpp/lucent/reactive.h +566 -0
  91. package/runtime/cpp/lucent/report.cpp +40 -0
  92. package/runtime/cpp/lucent/report.h +16 -0
  93. package/runtime/cpp/lucent/resource.cpp +83 -0
  94. package/runtime/cpp/lucent/resource.h +75 -0
  95. package/runtime/cpp/lucent/scheduler.cpp +38 -124
  96. package/runtime/cpp/lucent/scheduler.h +102 -83
  97. package/runtime/cpp/lucent/scope.cpp +308 -0
  98. package/runtime/cpp/lucent/scope.h +452 -0
  99. package/runtime/cpp/lucent/sizing.h +263 -0
  100. package/runtime/cpp/lucent/slots.h +231 -0
  101. package/runtime/cpp/lucent/trace.cpp +539 -0
  102. package/runtime/cpp/lucent/trace.h +251 -0
  103. package/runtime/cpp/lucent/transport.cpp +9 -0
  104. package/runtime/cpp/lucent/transport.h +341 -0
  105. package/runtime/cpp/lucent/view.cpp +123 -0
  106. package/runtime/cpp/lucent/view.h +157 -0
  107. package/runtime/cpp/rn/LucentComponentView.h +121 -0
  108. package/runtime/cpp/rn/LucentComponentView.mm +479 -0
  109. package/runtime/cpp/rn/LucentModule.cpp +37 -7
  110. package/runtime/cpp/rn/LucentModule.h +3 -0
  111. package/runtime/cpp/rn/LucentViewChildren.h +80 -0
  112. package/runtime/cpp/rn/LucentViewChildren.mm +211 -0
  113. package/runtime/cpp/rn/LucentViewRegistry.h +62 -0
  114. package/runtime/cpp/rn/LucentViewRequests.cpp +91 -0
  115. package/runtime/cpp/rn/LucentViewRequests.h +104 -0
  116. package/runtime/cpp/rn/LucentViewSizing.h +345 -0
  117. package/runtime/cpp/rn/LucentViewSlots.h +242 -0
  118. package/runtime/cpp/rn/LucentViewValues.h +125 -0
  119. package/runtime/cpp/rn/LucentViews.h +440 -0
  120. package/runtime/cpp/rn/LucentViewsAndroid.cpp +439 -0
  121. package/runtime/cpp/rn/LucentViewsAndroid.h +138 -0
  122. package/runtime/cpp/third_party/dragonbox/LICENSE-Boost +23 -0
  123. package/runtime/cpp/third_party/dragonbox/README.md +16 -0
  124. package/runtime/cpp/third_party/dragonbox/dragonbox.h +4440 -0
  125. package/runtime/js/index.d.ts +11 -1
  126. package/runtime/js/index.js +84 -8
  127. package/runtime/js/views.d.ts +38 -0
  128. package/runtime/js/views.js +226 -0
  129. package/runtime/native/android/CMakeLists.txt +4 -1
  130. package/runtime/native/android/src/compose/java/dev/lucent/compose/CompositionRules.kt +44 -0
  131. package/runtime/native/android/src/compose/java/dev/lucent/compose/LucentComposition.kt +161 -0
  132. package/runtime/native/android/src/main/java/dev/lucent/LucentActivities.java +292 -0
  133. package/runtime/native/android/src/main/java/dev/lucent/LucentChildren.java +174 -0
  134. package/runtime/native/android/src/main/java/dev/lucent/LucentHostView.java +232 -0
  135. package/runtime/native/android/src/main/java/dev/lucent/LucentInitializer.java +46 -0
  136. package/runtime/native/android/src/main/java/dev/lucent/LucentPackage.java +4 -3
  137. package/runtime/native/android/src/main/java/dev/lucent/LucentRequestActivity.java +92 -0
  138. package/runtime/native/android/src/main/java/dev/lucent/LucentSlotView.java +102 -0
  139. package/runtime/native/android/src/main/java/dev/lucent/LucentViewManager.java +149 -0
  140. package/runtime/native/android/src/main/java/dev/lucent/LucentViewManagers.java +16 -0
  141. package/runtime/native/android/src/main/java/dev/lucent/LucentViews.java +44 -0
  142. package/runtime/test/jsi/harness.cpp +9 -0
  143. package/schemas/build.schema.json +96 -1
  144. package/schemas/check.schema.json +56 -1
  145. package/schemas/lucent.schema.json +495 -9
  146. package/schemas/sdk-diff.schema.json +70 -0
  147. package/schemas/sdk-lock.schema.json +67 -0
  148. package/ts-plugin/index.js +77 -4
  149. package/dist/pipeline-CH7-2cxu.js +0 -232
  150. package/dist/project-D8tEet0k.js +0 -150
  151. package/dist/sdk-coverage-BoW_3Efd.js +0 -64
  152. package/dist/src-BD7f1_aZ.js +0 -11493
@@ -0,0 +1,308 @@
1
+ #include "scope.h"
2
+
3
+ #include "report.h"
4
+
5
+ namespace lucent {
6
+
7
+ namespace {
8
+ // Constant-initialized: safe to use during static initialization.
9
+ std::atomic<ScopeId> nextScopeId{1};
10
+ std::atomic<OperationId> nextOperationId{1};
11
+ } // namespace
12
+
13
+ Error scopeDisposedError() {
14
+ return makeError(String::fromLatin1("AbortError"), String::fromLatin1("The operation's scope was disposed"));
15
+ }
16
+
17
+ std::exception_ptr detail::aggregateErrors(std::exception_ptr pending, std::exception_ptr next) {
18
+ if (!next) return pending;
19
+ if (!pending) return next;
20
+ return suppressedError(next, pending);
21
+ }
22
+
23
+ // --- OperationBase ------------------------------------------------------------
24
+
25
+ void detail::OperationBase::setCleanup(std::function<void()> cleanup) {
26
+ std::function<void()> removed;
27
+
28
+ {
29
+ std::lock_guard<std::mutex> g(m_);
30
+
31
+ if (!cleanup) {
32
+ // Destroyed after unlocking: what it captured may call back in.
33
+ removed = std::exchange(cleanup_, nullptr);
34
+ return;
35
+ }
36
+
37
+ if (cleanup_) throw std::logic_error("The operation already has a cleanup");
38
+
39
+ if (state_.load(std::memory_order_relaxed) == OperationState::Pending) {
40
+ cleanup_ = std::move(cleanup);
41
+ return;
42
+ }
43
+ }
44
+
45
+ // Settled already: the registration completed before it returned.
46
+ try {
47
+ cleanup();
48
+ } catch (...) {
49
+ report(std::current_exception());
50
+ }
51
+ }
52
+
53
+ bool detail::OperationBase::attach(const std::shared_ptr<Scope>& scope, bool pending) {
54
+ return scope->adopt(shared_from_this(), pending);
55
+ }
56
+
57
+ void detail::OperationBase::detach() {
58
+ if (auto scope = scope_.lock()) scope->forget(token_.operation);
59
+ }
60
+
61
+ std::exception_ptr detail::OperationBase::runCleanup() {
62
+ std::function<void()> cleanup;
63
+
64
+ {
65
+ std::lock_guard<std::mutex> g(m_);
66
+
67
+ if (state_.load(std::memory_order_relaxed) == OperationState::Pending) return nullptr;
68
+
69
+ cleanup = std::exchange(cleanup_, nullptr);
70
+ }
71
+
72
+ if (!cleanup) return nullptr;
73
+
74
+ try {
75
+ cleanup();
76
+ } catch (...) {
77
+ return std::current_exception();
78
+ }
79
+
80
+ return nullptr;
81
+ }
82
+
83
+ void detail::OperationBase::report(std::exception_ptr e) {
84
+ if (e) reportUncaught(e, "operation");
85
+ }
86
+
87
+ // --- Scope ---------------------------------------------------------------
88
+
89
+ Scope::Scope(RuntimeId runtime, const std::shared_ptr<Scope>& parent, std::weak_ptr<Owner> owner)
90
+ : runtime_(runtime),
91
+ id_(nextScopeId.fetch_add(1, std::memory_order_relaxed)),
92
+ parent_(parent),
93
+ owner_(std::move(owner)) {}
94
+
95
+ std::shared_ptr<Scope> Scope::create(RuntimeId runtime, const std::shared_ptr<Scope>& parent) {
96
+ if (parent && parent->runtime_ != 0 && parent->runtime_ != runtime) {
97
+ throw std::invalid_argument("A child scope belongs to its parent's runtime");
98
+ }
99
+
100
+ std::shared_ptr<Scope> scope(new Scope(runtime, parent, parent ? parent->owner_ : std::weak_ptr<Owner>()));
101
+
102
+ // Nothing is registered yet: disposed here, whatever the owner.
103
+ if (parent && !parent->adoptChild(scope)) scope->disposeHere();
104
+
105
+ return scope;
106
+ }
107
+
108
+ std::shared_ptr<Scope> Scope::createRoot(RuntimeId runtime, std::weak_ptr<Owner> owner) {
109
+ return std::shared_ptr<Scope>(new Scope(runtime, nullptr, std::move(owner)));
110
+ }
111
+
112
+ Scope::~Scope() {
113
+ if (auto e = dispose()) reportUncaught(e, "scope");
114
+ }
115
+
116
+ Scope::CleanupId Scope::onDispose(std::function<void()> cleanup) {
117
+ if (!cleanup) throw std::invalid_argument("A scope cleanup must be a function");
118
+
119
+ {
120
+ std::lock_guard<std::mutex> g(m_);
121
+
122
+ if (state_.load(std::memory_order_relaxed) == State::Active) {
123
+ CleanupId id = nextCleanup_++;
124
+ cleanups_.emplace(id, std::move(cleanup));
125
+ return id;
126
+ }
127
+ }
128
+
129
+ cleanup();
130
+ return 0;
131
+ }
132
+
133
+ bool Scope::remove(CleanupId id) {
134
+ std::function<void()> removed;
135
+
136
+ {
137
+ std::lock_guard<std::mutex> g(m_);
138
+
139
+ auto it = cleanups_.find(id);
140
+ if (it == cleanups_.end()) return false;
141
+
142
+ // Destroyed after unlocking: what it captured may call back in.
143
+ removed = std::move(it->second);
144
+ cleanups_.erase(it);
145
+ }
146
+
147
+ return true;
148
+ }
149
+
150
+ std::exception_ptr Scope::dispose() {
151
+ if (state_.load(std::memory_order_acquire) != State::Active) return nullptr;
152
+
153
+ auto owner = owner_.lock();
154
+ if (!owner || owner->isCurrent()) return disposeHere();
155
+
156
+ if (auto self = weak_from_this().lock()) {
157
+ auto job = [self] {
158
+ if (auto e = self->dispose()) reportUncaught(e, "scope");
159
+ };
160
+
161
+ if (owner->post(std::move(job))) return nullptr;
162
+
163
+ return disposeHere();
164
+ }
165
+
166
+ // The destructor: nothing refers to this scope any more, so its teardown
167
+ // goes to the owner alone.
168
+ auto teardown = begin();
169
+ if (!teardown) return nullptr;
170
+
171
+ auto moved = std::make_shared<Teardown>(std::move(*teardown));
172
+ auto job = [moved] {
173
+ if (auto e = finish(*moved)) reportUncaught(e, "scope");
174
+ };
175
+
176
+ if (owner->post(std::move(job))) return nullptr;
177
+
178
+ return finish(*moved);
179
+ }
180
+
181
+ std::exception_ptr Scope::disposeHere() {
182
+ // A child's last reference may be its parent's, dropped below. Null in
183
+ // the destructor, where nothing else refers to this scope.
184
+ auto self = weak_from_this().lock();
185
+
186
+ auto teardown = begin();
187
+ if (!teardown) return nullptr;
188
+
189
+ std::exception_ptr errors = finish(*teardown);
190
+
191
+ state_.store(State::Disposed, std::memory_order_release);
192
+
193
+ if (auto parent = parent_.lock()) parent->forgetChild(id_);
194
+
195
+ return errors;
196
+ }
197
+
198
+ std::optional<Scope::Teardown> Scope::begin() {
199
+ std::lock_guard<std::mutex> g(m_);
200
+
201
+ if (state_.load(std::memory_order_relaxed) != State::Active) return std::nullopt;
202
+
203
+ generation_.fetch_add(1, std::memory_order_acq_rel);
204
+ state_.store(State::Disposing, std::memory_order_release);
205
+
206
+ Teardown teardown;
207
+ teardown.children.swap(children_);
208
+ teardown.operations.swap(operations_);
209
+ teardown.cleanups.swap(cleanups_);
210
+ return teardown;
211
+ }
212
+
213
+ std::exception_ptr Scope::finish(Teardown& teardown) {
214
+ std::exception_ptr errors;
215
+
216
+ for (auto it = teardown.children.rbegin(); it != teardown.children.rend(); ++it) {
217
+ errors = detail::aggregateErrors(errors, it->second->dispose());
218
+ }
219
+
220
+ if (!teardown.operations.empty()) {
221
+ Error reason = scopeDisposedError();
222
+
223
+ for (auto it = teardown.operations.rbegin(); it != teardown.operations.rend(); ++it) {
224
+ errors = detail::aggregateErrors(errors, it->second->cancelOwned(reason));
225
+ }
226
+
227
+ for (auto it = teardown.operations.rbegin(); it != teardown.operations.rend(); ++it) {
228
+ errors = detail::aggregateErrors(errors, it->second->runCleanup());
229
+ }
230
+ }
231
+
232
+ for (auto it = teardown.cleanups.rbegin(); it != teardown.cleanups.rend(); ++it) {
233
+ try {
234
+ it->second();
235
+ } catch (...) {
236
+ errors = detail::aggregateErrors(errors, std::current_exception());
237
+ }
238
+ }
239
+
240
+ return errors;
241
+ }
242
+
243
+ bool Scope::validates(const OperationToken& token) const {
244
+ std::lock_guard<std::mutex> g(m_);
245
+
246
+ if (state_.load(std::memory_order_relaxed) != State::Active) return false;
247
+ if (token.runtime != runtime_ || token.scope != id_) return false;
248
+ if (token.generation != generation_.load(std::memory_order_relaxed)) return false;
249
+
250
+ auto it = operations_.find(token.operation);
251
+ return it != operations_.end() && it->second->state() == OperationState::Pending;
252
+ }
253
+
254
+ size_t Scope::registrations() const {
255
+ std::lock_guard<std::mutex> g(m_);
256
+
257
+ return children_.size() + operations_.size() + cleanups_.size();
258
+ }
259
+
260
+ bool Scope::adopt(const std::shared_ptr<detail::OperationBase>& op, bool pending) {
261
+ std::lock_guard<std::mutex> g(m_);
262
+
263
+ // Under the lock, so the generation and the state agree, and ids follow
264
+ // the order operations join the scope.
265
+ op->token_ = {runtime_, id_, generation_.load(std::memory_order_relaxed),
266
+ nextOperationId.fetch_add(1, std::memory_order_relaxed)};
267
+ op->scope_ = weak_from_this();
268
+
269
+ if (!pending || state_.load(std::memory_order_relaxed) != State::Active) return false;
270
+
271
+ operations_.emplace(op->token_.operation, op);
272
+ return true;
273
+ }
274
+
275
+ void Scope::forget(OperationId id) {
276
+ // Released after unlocking.
277
+ std::shared_ptr<detail::OperationBase> op;
278
+ std::lock_guard<std::mutex> g(m_);
279
+
280
+ auto it = operations_.find(id);
281
+ if (it == operations_.end()) return;
282
+
283
+ op = std::move(it->second);
284
+ operations_.erase(it);
285
+ }
286
+
287
+ bool Scope::adoptChild(const std::shared_ptr<Scope>& child) {
288
+ std::lock_guard<std::mutex> g(m_);
289
+
290
+ if (state_.load(std::memory_order_relaxed) != State::Active) return false;
291
+
292
+ children_.emplace(child->id_, child);
293
+ return true;
294
+ }
295
+
296
+ void Scope::forgetChild(ScopeId id) {
297
+ // Released after unlocking.
298
+ std::shared_ptr<Scope> child;
299
+ std::lock_guard<std::mutex> g(m_);
300
+
301
+ auto it = children_.find(id);
302
+ if (it == children_.end()) return;
303
+
304
+ child = std::move(it->second);
305
+ children_.erase(it);
306
+ }
307
+
308
+ } // namespace lucent