summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Notes/BigChanges/Variant.md70
-rw-r--r--Notes/BorrowChecker.md7
-rw-r--r--Notes/MIR-Validation.txt9
3 files changed, 86 insertions, 0 deletions
diff --git a/Notes/BigChanges/Variant.md b/Notes/BigChanges/Variant.md
new file mode 100644
index 00000000..55bb3bb0
--- /dev/null
+++ b/Notes/BigChanges/Variant.md
@@ -0,0 +1,70 @@
+
+(the below is from @ubsan)
+
+```
+// one can define their own variant, but I'm lazy
+#include <variant>
+#include <type_traits>
+#include <iostream>
+
+template <typename F, typename T, typename Void = void>
+struct return_type {};
+
+template <typename F, typename T>
+struct return_type<T, F, std::void_t<
+ decltype(std::declval<F>()(std::declval<T>()))
+>> {
+ using type = decltype(std::declval<F>()(std::declval<T>()));
+};
+
+template <typename F, typename T>
+using return_type_t = typename return_type<T, F>::type;
+
+// not sure what to call this
+template <typename F, typename... Ts>
+struct common_return_type {
+ using type = std::common_type_t<return_type_t<F, Ts>...>;
+};
+
+template <typename F, typename... Ts>
+using common_return_type_t = typename common_return_type<F, Ts...>::type;
+
+template <typename F, typename... Ts>
+auto match(
+ std::variant<Ts...>& variant, F&& functor
+) -> common_return_type_t<F, Ts...> {
+ // you could also use static_assert to make it SFINAE-unfriendly
+ return std::visit(functor, variant);
+}
+
+template <typename... Fs>
+struct overloaded : Fs... {
+ using Fs::operator()...;
+ overloaded(Fs&&... fs) : Fs(std::forward<Fs>(fs))... { }
+};
+
+int main() {
+ auto var = std::variant<int, std::string>(0);
+ std::cout << match(var, overloaded(
+ [](int i) { return i; },
+ [](std::string s) { return 0; }
+ ));
+}
+```
+
+
+
+ALTERNATIVE
+===========
+
+Could just update TU to have:
+``
+stmt.if_let(
+stmt.match_def(
+stmt.match(
+ [](::MIR::LValue::Data_Assign& se) {
+ },
+ [](::MIR::LValue::Data_Drop& se) {
+ }
+ );
+```
diff --git a/Notes/BorrowChecker.md b/Notes/BorrowChecker.md
new file mode 100644
index 00000000..78b46ff5
--- /dev/null
+++ b/Notes/BorrowChecker.md
@@ -0,0 +1,7 @@
+- On borrow, calculate lifetime of asignment (using existing lifetime code)
+ - Ignore reborrows?
+- Visit all statements in that lifetime and locate places where the borrow is propagated/stored
+ - Requires lifetime parameters on functions/&-ptrs to be present
+- Assignment of the source value during the lifetime of the borrow is an error
+- Dropping of the source value is an error
+- Returning the borrow is an error
diff --git a/Notes/MIR-Validation.txt b/Notes/MIR-Validation.txt
new file mode 100644
index 00000000..337c65cd
--- /dev/null
+++ b/Notes/MIR-Validation.txt
@@ -0,0 +1,9 @@
+
+Requirements:
+- Know full state (and linked states) for each path through the function.
+
+
+Idea:
+- Lifetime calculations (existing code)
+ - Mask out known invalid values at loopback.
+