Skip to content

Commit 7adef5c

Browse files
simplify trace operations (#56)
1 parent c5f2bbf commit 7adef5c

File tree

683 files changed

+1444
-1325
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

683 files changed

+1444
-1325
lines changed

.clang-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ AccessModifierOffset: -4
44
AllowShortFunctionsOnASingleLine: false
55
AllowShortLambdasOnASingleLine: Inline
66
AlwaysBreakTemplateDeclarations: Yes
7-
ColumnLimit: 240
7+
ColumnLimit: 120
88
CompactNamespaces: true
99
IncludeBlocks: Merge
1010
IncludeCategories:

nautilus/include/nautilus/Engine.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ std::function<void()> createFunctionWrapper(std::index_sequence<Indices...>, std
3232
auto traceFunc = [=]() {
3333
if constexpr (std::is_void_v<R>) {
3434
func(details::createTraceableArgument<FunctionArguments, Indices>()...);
35-
tracing::traceReturnOperation(Type::v, tracing::value_ref());
35+
tracing::traceReturnOperation(Type::v, tracing::TypedValueRef());
3636
} else {
3737
auto returnValue = func(details::createTraceableArgument<FunctionArguments, Indices>()...);
3838
auto type = tracing::to_type<typename decltype(returnValue)::raw_type>();

nautilus/include/nautilus/function.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ namespace nautilus {
1010

1111
template <typename... ValueArguments>
1212
auto getArgumentReferences(const ValueArguments&... arguments) {
13-
std::vector<tracing::value_ref> functionArgumentReferences;
13+
std::vector<tracing::TypedValueRef> functionArgumentReferences;
1414
if constexpr (sizeof...(ValueArguments) > 0) {
1515
functionArgumentReferences.reserve(sizeof...(ValueArguments));
16-
for (const tracing::value_ref& p : {details::getState(arguments)...}) {
16+
for (const tracing::TypedValueRef& p : {details::getState(arguments)...}) {
1717
functionArgumentReferences.emplace_back(p);
1818
}
1919
}

nautilus/include/nautilus/std/string.h

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ class val<std::basic_string<CharT, Traits>> {
115115
}
116116

117117
/**
118-
* Informs a std::basic_string object of a planned change in size, so that it can manage the storage allocation appropriately.
118+
* Informs a std::basic_string object of a planned change in size, so that it can manage the storage allocation
119+
* appropriately.
119120
* @param new_cap
120121
*/
121122
void reserve(val<size_type> new_cap) const {
@@ -147,7 +148,8 @@ class val<std::basic_string<CharT, Traits>> {
147148
*/
148149
auto& insert(val<size_type> index, val<size_type> count, val<CharT> ch) const {
149150
invoke(
150-
+[](base_type* ptr, size_type index, size_type count, CharT ch) -> void { ptr->insert(index, count, ch); }, data_ptr, index, count, ch);
151+
+[](base_type* ptr, size_type index, size_type count, CharT ch) -> void { ptr->insert(index, count, ch); },
152+
data_ptr, index, count, ch);
151153
return *this;
152154
}
153155

@@ -156,7 +158,8 @@ class val<std::basic_string<CharT, Traits>> {
156158
*/
157159
auto& insert(val<size_type> index, val<const CharT*> s) const {
158160
invoke(
159-
+[](base_type* ptr, size_type index, const CharT* s) -> void { ptr->insert(index, s); }, data_ptr, index, s);
161+
+[](base_type* ptr, size_type index, const CharT* s) -> void { ptr->insert(index, s); }, data_ptr, index,
162+
s);
160163
return *this;
161164
}
162165

@@ -181,9 +184,13 @@ class val<std::basic_string<CharT, Traits>> {
181184
/**
182185
* Appends additional characters to the string.
183186
*/
184-
auto& append(const val<std::basic_string<CharT, Traits>>& str, const val<size_type>& pos, const val<size_type>& count) {
187+
auto& append(const val<std::basic_string<CharT, Traits>>& str, const val<size_type>& pos,
188+
const val<size_type>& count) {
185189
invoke(
186-
+[](base_type* ptr, base_type* other, size_type pos, size_type count) -> void { ptr->append(*other, pos, count); }, data_ptr, str.data_ptr, pos, count);
190+
+[](base_type* ptr, base_type* other, size_type pos, size_type count) -> void {
191+
ptr->append(*other, pos, count);
192+
},
193+
data_ptr, str.data_ptr, pos, count);
187194
return *this;
188195
}
189196

@@ -192,7 +199,8 @@ class val<std::basic_string<CharT, Traits>> {
192199
*/
193200
auto& append(const val<std::basic_string<CharT, Traits>>& str, const val<size_type>& count) {
194201
invoke(
195-
+[](base_type* ptr, base_type* other, size_type count) -> void { ptr->append(*other, count); }, data_ptr, str.data_ptr, count);
202+
+[](base_type* ptr, base_type* other, size_type count) -> void { ptr->append(*other, count); }, data_ptr,
203+
str.data_ptr, count);
196204
return *this;
197205
}
198206

@@ -243,11 +251,15 @@ class val<std::basic_string<CharT, Traits>> {
243251
}
244252

245253
/**
246-
* Copies a substring [pos, pos + count) to character string pointed to by dest. If the requested substring lasts past the end of the string, or if count == npos, the copied substring is [pos, size()).
254+
* Copies a substring [pos, pos + count) to character string pointed to by dest. If the requested substring lasts
255+
* past the end of the string, or if count == npos, the copied substring is [pos, size()).
247256
*/
248257
val<size_type> copy(const val<CharT*>& dest, const val<size_type>& count, const val<size_type>& pos = 0) {
249258
return invoke(
250-
+[](base_type* ptr, CharT* dest, size_type count, size_type pos) -> size_type { return ptr->copy(dest, count, pos); }, data_ptr, dest, count, pos);
259+
+[](base_type* ptr, CharT* dest, size_type count, size_type pos) -> size_type {
260+
return ptr->copy(dest, count, pos);
261+
},
262+
data_ptr, dest, count, pos);
251263
}
252264

253265
~val() {

nautilus/include/nautilus/std/string_view.h

Lines changed: 64 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,16 @@ class val<std::basic_string_view<CharT, Traits>> {
6262

6363
val<value_type> operator[](val<size_type> pos) const {
6464
return invoke(
65-
+[](std::basic_string_view<CharT, Traits>* ptr, size_type pos) -> value_type { return ptr->operator[](pos); }, data_ptr, pos);
65+
+[](std::basic_string_view<CharT, Traits>* ptr, size_type pos) -> value_type {
66+
return ptr->operator[](pos);
67+
},
68+
data_ptr, pos);
6669
}
6770

6871
const val<value_type> at(val<size_type> index) const {
6972
return invoke(
70-
+[](std::basic_string_view<CharT, Traits>* ptr, size_type index) -> value_type { return ptr->at(index); }, data_ptr, index);
73+
+[](std::basic_string_view<CharT, Traits>* ptr, size_type index) -> value_type { return ptr->at(index); },
74+
data_ptr, index);
7175
}
7276

7377
val<size_type> size() const noexcept {
@@ -107,22 +111,30 @@ class val<std::basic_string_view<CharT, Traits>> {
107111

108112
void remove_prefix(val<size_type> n) {
109113
invoke(
110-
+[](std::basic_string_view<CharT, Traits>* ptr, size_type n) -> void { ptr->remove_prefix(n); }, data_ptr, n);
114+
+[](std::basic_string_view<CharT, Traits>* ptr, size_type n) -> void { ptr->remove_prefix(n); }, data_ptr,
115+
n);
111116
}
112117

113118
void remove_suffix(val<size_type> n) {
114119
invoke(
115-
+[](std::basic_string_view<CharT, Traits>* ptr, size_type n) -> void { ptr->remove_suffix(n); }, data_ptr, n);
120+
+[](std::basic_string_view<CharT, Traits>* ptr, size_type n) -> void { ptr->remove_suffix(n); }, data_ptr,
121+
n);
116122
}
117123

118124
void swap(val<std::basic_string_view<CharT, Traits>>& v) {
119125
invoke(
120-
+[](std::basic_string_view<CharT, Traits>* ptr, std::basic_string_view<CharT, Traits>* other) -> void { ptr->swap(*other); }, data_ptr, v.data_ptr);
126+
+[](std::basic_string_view<CharT, Traits>* ptr, std::basic_string_view<CharT, Traits>* other) -> void {
127+
ptr->swap(*other);
128+
},
129+
data_ptr, v.data_ptr);
121130
}
122131

123132
val<size_type> copy(val<CharT*> dest, val<size_type> count, val<size_type> pos = 0) {
124133
return invoke(
125-
+[](std::basic_string_view<CharT, Traits>* ptr, CharT* dest, size_type count, size_type pos) -> size_type { return ptr->copy(dest, count, pos); }, data_ptr, dest, count, pos);
134+
+[](std::basic_string_view<CharT, Traits>* ptr, CharT* dest, size_type count, size_type pos) -> size_type {
135+
return ptr->copy(dest, count, pos);
136+
},
137+
data_ptr, dest, count, pos);
126138
}
127139

128140
/*
@@ -142,76 +154,104 @@ class val<std::basic_string_view<CharT, Traits>> {
142154

143155
val<int> compare(val<std::basic_string_view<CharT, Traits>>& v) {
144156
return invoke(
145-
+[](std::basic_string_view<CharT, Traits>* ptr, std::basic_string_view<CharT, Traits>* other) -> int { return ptr->compare(*other); }, data_ptr, v.data_ptr);
157+
+[](std::basic_string_view<CharT, Traits>* ptr, std::basic_string_view<CharT, Traits>* other) -> int {
158+
return ptr->compare(*other);
159+
},
160+
data_ptr, v.data_ptr);
146161
}
147162

148163
val<int> compare(val<size_type> pos1, val<size_type> count1, val<std::basic_string_view<CharT, Traits>>& v) {
149164
return invoke(
150-
+[](std::basic_string_view<CharT, Traits>* ptr, size_type pos1, size_t count1, std::basic_string_view<CharT, Traits>* v) -> int { return ptr->compare(pos1, count1, *v); }, data_ptr, pos1, count1, v.data_ptr);
165+
+[](std::basic_string_view<CharT, Traits>* ptr, size_type pos1, size_t count1,
166+
std::basic_string_view<CharT, Traits>* v) -> int { return ptr->compare(pos1, count1, *v); },
167+
data_ptr, pos1, count1, v.data_ptr);
151168
}
152169

153-
val<int> compare(val<size_type> pos1, val<size_type> count1, val<std::basic_string_view<CharT, Traits>>& v, val<size_type> pos2, val<size_type> count2) {
170+
val<int> compare(val<size_type> pos1, val<size_type> count1, val<std::basic_string_view<CharT, Traits>>& v,
171+
val<size_type> pos2, val<size_type> count2) {
154172
return invoke(
155-
+[](std::basic_string_view<CharT, Traits>* ptr, size_type pos1, size_t count1, std::basic_string_view<CharT, Traits>* v, size_type pos2, size_t count2) -> int { return ptr->compare(pos1, count1, *v, pos2, count2); }, data_ptr,
156-
pos1, count1, v.data_ptr, pos2, count2);
173+
+[](std::basic_string_view<CharT, Traits>* ptr, size_type pos1, size_t count1,
174+
std::basic_string_view<CharT, Traits>* v, size_type pos2,
175+
size_t count2) -> int { return ptr->compare(pos1, count1, *v, pos2, count2); },
176+
data_ptr, pos1, count1, v.data_ptr, pos2, count2);
157177
}
158178

159179
val<int> compare(val<const CharT*> s) {
160180
return invoke(
161-
+[](std::basic_string_view<CharT, Traits>* ptr, const CharT* s) -> int { return ptr->compare(s); }, data_ptr, s);
181+
+[](std::basic_string_view<CharT, Traits>* ptr, const CharT* s) -> int { return ptr->compare(s); },
182+
data_ptr, s);
162183
}
163184

164185
val<int> compare(val<size_type> pos1, val<size_type> count1, val<const CharT*> s) {
165186
return invoke(
166-
+[](std::basic_string_view<CharT, Traits>* ptr, size_type pos1, size_t count1, const CharT* s) -> int { return ptr->compare(pos1, count1, s); }, data_ptr, pos1, count1, s);
187+
+[](std::basic_string_view<CharT, Traits>* ptr, size_type pos1, size_t count1, const CharT* s) -> int {
188+
return ptr->compare(pos1, count1, s);
189+
},
190+
data_ptr, pos1, count1, s);
167191
}
168192

169-
val<int> compare(val<size_type> pos1, val<size_type> count1, val<const CharT*> s, val<size_type> pos2, val<size_type> count2) {
193+
val<int> compare(val<size_type> pos1, val<size_type> count1, val<const CharT*> s, val<size_type> pos2,
194+
val<size_type> count2) {
170195
return invoke(
171-
+[](std::basic_string_view<CharT, Traits>* ptr, size_type pos1, size_t count1, const CharT* s, size_type pos2, size_t count2) -> int { return ptr->compare(pos1, count1, s, pos2, count2); }, data_ptr, pos1, count1, s, pos2,
172-
count2);
196+
+[](std::basic_string_view<CharT, Traits>* ptr, size_type pos1, size_t count1, const CharT* s,
197+
size_type pos2, size_t count2) -> int { return ptr->compare(pos1, count1, s, pos2, count2); },
198+
data_ptr, pos1, count1, s, pos2, count2);
173199
}
174200
#ifdef __cpp_lib_starts_ends_with
175201
val<bool> start_with(val<std::basic_string_view<CharT, Traits>>& v) {
176202
return invoke(
177-
+[](std::basic_string_view<CharT, Traits>* ptr, std::basic_string_view<CharT, Traits>* v) -> bool { return ptr->starts_with(*v); }, data_ptr, v.data_ptr);
203+
+[](std::basic_string_view<CharT, Traits>* ptr, std::basic_string_view<CharT, Traits>* v) -> bool {
204+
return ptr->starts_with(*v);
205+
},
206+
data_ptr, v.data_ptr);
178207
}
179208

180209
val<bool> start_with(val<const CharT*> s) {
181210
return invoke(
182-
+[](std::basic_string_view<CharT, Traits>* ptr, const CharT* s) -> bool { return ptr->starts_with(s); }, data_ptr, s);
211+
+[](std::basic_string_view<CharT, Traits>* ptr, const CharT* s) -> bool { return ptr->starts_with(s); },
212+
data_ptr, s);
183213
}
184214

185215
val<bool> start_with(val<CharT> s) {
186216
return invoke(
187-
+[](std::basic_string_view<CharT, Traits>* ptr, CharT s) -> bool { return ptr->starts_with(s); }, data_ptr, s);
217+
+[](std::basic_string_view<CharT, Traits>* ptr, CharT s) -> bool { return ptr->starts_with(s); }, data_ptr,
218+
s);
188219
}
189220

190221
val<bool> end_with(val<std::basic_string_view<CharT, Traits>>& v) {
191222
return invoke(
192-
+[](std::basic_string_view<CharT, Traits>* ptr, std::basic_string_view<CharT, Traits>* v) -> bool { return ptr->ends_with(*v); }, data_ptr, v.data_ptr);
223+
+[](std::basic_string_view<CharT, Traits>* ptr, std::basic_string_view<CharT, Traits>* v) -> bool {
224+
return ptr->ends_with(*v);
225+
},
226+
data_ptr, v.data_ptr);
193227
}
194228

195229
val<bool> end_with(val<const CharT*> s) {
196230
return invoke(
197-
+[](std::basic_string_view<CharT, Traits>* ptr, const CharT* s) -> bool { return ptr->ends_with(s); }, data_ptr, s);
231+
+[](std::basic_string_view<CharT, Traits>* ptr, const CharT* s) -> bool { return ptr->ends_with(s); },
232+
data_ptr, s);
198233
}
199234

200235
val<bool> end_with(val<CharT> s) {
201236
return invoke(
202-
+[](std::basic_string_view<CharT, Traits>* ptr, CharT s) -> bool { return ptr->ends_with(s); }, data_ptr, s);
237+
+[](std::basic_string_view<CharT, Traits>* ptr, CharT s) -> bool { return ptr->ends_with(s); }, data_ptr,
238+
s);
203239
}
204240
#endif
205241

206242
#ifdef __cpp_lib_string_contains
207243
val<bool> contains(val<std::basic_string_view<CharT, Traits>>& v) {
208244
return invoke(
209-
+[](std::basic_string_view<CharT, Traits>* ptr, std::basic_string_view<CharT, Traits>* v) -> bool { return ptr->contains(*v); }, data_ptr, v.data_ptr);
245+
+[](std::basic_string_view<CharT, Traits>* ptr, std::basic_string_view<CharT, Traits>* v) -> bool {
246+
return ptr->contains(*v);
247+
},
248+
data_ptr, v.data_ptr);
210249
}
211250

212251
val<bool> contains(val<const CharT*> s) {
213252
return invoke(
214-
+[](std::basic_string_view<CharT, Traits>* ptr, const CharT* s) -> bool { return ptr->contains(s); }, data_ptr, s);
253+
+[](std::basic_string_view<CharT, Traits>* ptr, const CharT* s) -> bool { return ptr->contains(s); },
254+
data_ptr, s);
215255
}
216256

217257
val<bool> contains(val<CharT> s) {

nautilus/include/nautilus/tracing/TracingUtil.hpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,28 @@ namespace nautilus::tracing {
1515

1616
bool inTracer();
1717

18-
value_ref traceBinaryOp(Op operation, Type resultType, const TypedValueRef& leftState, const TypedValueRef& rightState);
19-
value_ref traceUnaryOp(Op operation, Type resultType, const TypedValueRef& inputState);
18+
TypedValueRef& traceBinaryOp(Op operation, Type resultType, const TypedValueRef& leftState, const TypedValueRef& rightState);
19+
TypedValueRef& traceUnaryOp(Op operation, Type resultType, const TypedValueRef& inputState);
2020

2121
bool traceBool(const TypedValueRef& state);
22-
value_ref traceConstant(Type type, const ConstantLiteral& value);
22+
TypedValueRef& traceConstant(Type type, const ConstantLiteral& value);
2323
template <typename T>
24-
value_ref traceConstant(T&& value) {
24+
TypedValueRef traceConstant(T&& value) {
2525
if (inTracer()) {
2626
return traceConstant(to_type<T>(), createConstLiteral(value));
2727
}
2828
return {0, to_type<T>()};
2929
}
3030

31-
value_ref traceLoad(const TypedValueRef& src, Type resultType);
32-
void traceStore(const TypedValueRef& target, const TypedValueRef& src, Type valueType);
33-
34-
value_ref traceCast(const value_ref& state, Type resultType);
3531
void traceAssignment(const TypedValueRef& target, const TypedValueRef& source, Type resultType);
36-
value_ref traceCopy(const TypedValueRef& state);
32+
TypedValueRef traceCopy(const TypedValueRef& state);
3733

38-
value_ref traceCall(void* fptn, Type resultType, const std::vector<tracing::value_ref>& arguments);
34+
TypedValueRef& traceCall(void* fptn, Type resultType, const std::vector<tracing::TypedValueRef>& arguments);
3935

40-
value_ref registerFunctionArgument(Type type, size_t index);
36+
TypedValueRef& registerFunctionArgument(Type type, size_t index);
4137

42-
void traceReturnOperation(Type type, const value_ref& ref);
43-
void traceValueDestruction(value_ref ref);
38+
void traceReturnOperation(Type type, const TypedValueRef& ref);
39+
void traceValueDestruction(TypedValueRef ref);
4440

4541
void pushStaticVal(void* ptr);
4642
void popStaticVal();

nautilus/include/nautilus/tracing/TypedValueRef.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,4 @@ class TypedValueRefHolder {
4949
TypedValueRef valueRef;
5050
};
5151

52-
using value_ref = TypedValueRef;
5352
} // namespace nautilus::tracing

0 commit comments

Comments
 (0)